Adds [tool.ruff] and [tool.ty] config to pyproject.toml with a curated ruff rule set (E, F, W, I, UP, B, C4, SIM, RUF, ASYNC, LOG, G, PIE, RET, PERF, N), pins ruff/ty in requirements-dev.txt, reformats the whole tree with `ruff format`, and fixes the pre-existing lint and type-check debt those tools surfaced so both run clean. Production-code type fixes include: HA's ConfigFlowResult vs. the generic FlowResult in config_flow.py, narrowing BoundEntity.desc to its platform-specific subclass (SelectDesc/NumberDesc/SensorDesc/etc.) via cast() instead of an unchecked annotation, converting HA device_class strings to their proper enum types, a resolve_registry callback typed as `object` instead of `DeviceRegistry | None`, and a couple of other narrow correctness fixes (CA key type validation, an index-out-of-bounds false positive from an empty-tuple fallback, a bool/dict argument swap). Test-file fixes are mechanical: narrowing SamsungEntityDescription to the correct subclass via isinstance()/cast() before accessing subclass-only fields, and asserting Optional write_fn/unit_fn fields are set before calling them.
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
"""Time platform for Local Things."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import datetime
|
|
|
|
from homeassistant.components.time import TimeEntity
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from .const import DOMAIN
|
|
from .coordinator import LocalThingsCoordinator
|
|
from .entity import LocalThingsEntity, _is_included
|
|
from .registry.entities import TimeDesc
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
coordinator: LocalThingsCoordinator = hass.data[DOMAIN][entry.entry_id]
|
|
async_add_entities(
|
|
LocalThingsTime(coordinator, b)
|
|
for b in coordinator.bound
|
|
if isinstance(b.desc, TimeDesc) and _is_included(b, coordinator)
|
|
)
|
|
|
|
|
|
class LocalThingsTime(LocalThingsEntity, TimeEntity):
|
|
@property
|
|
def native_value(self) -> datetime.time | None:
|
|
return (self.coordinator.data or {}).get(self._state_key)
|
|
|
|
async def async_set_value(self, value: datetime.time) -> None:
|
|
await self.coordinator.async_send_command(self._bound, value)
|