diff --git a/custom_components/spook/ectoplasms/cloud/entity.py b/custom_components/spook/ectoplasms/cloud/entity.py index 480c5e27..5e9775c9 100644 --- a/custom_components/spook/ectoplasms/cloud/entity.py +++ b/custom_components/spook/ectoplasms/cloud/entity.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING from homeassistant.components.cloud.const import DOMAIN as CLOUD_DOMAIN -from homeassistant.helpers.entity import DeviceInfo +from homeassistant.helpers.device_registry import DeviceInfo from ...const import DOMAIN from ...entity import SpookEntity, SpookEntityDescription @@ -13,13 +13,15 @@ if TYPE_CHECKING: from hass_nabucasa import Cloud + from homeassistant.components.cloud.client import CloudClient + class HomeAssistantCloudSpookEntity(SpookEntity): """Defines an base Spook entity for Home Assistant Cloud related entities.""" - _cloud: Cloud - - def __init__(self, cloud: Cloud, description: SpookEntityDescription) -> None: + def __init__( + self, cloud: Cloud[CloudClient], description: SpookEntityDescription + ) -> None: """Initialize the entity.""" super().__init__(description=description) self._cloud = cloud diff --git a/custom_components/spook/ectoplasms/cloud/switch.py b/custom_components/spook/ectoplasms/cloud/switch.py index 29dfb0e0..877b87f4 100644 --- a/custom_components/spook/ectoplasms/cloud/switch.py +++ b/custom_components/spook/ectoplasms/cloud/switch.py @@ -17,26 +17,21 @@ from hass_nabucasa import Cloud + from homeassistant.components.cloud.client import CloudClient from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -@dataclass(kw_only=True) +@dataclass(frozen=True, kw_only=True) class HomeAssistantCloudSpookSwitchEntityDescription( SpookEntityDescription, SwitchEntityDescription, ): """Class describing Spook Home Assistant sensor entities.""" - icon_off: str | None = None - is_on_fn: Callable[[Cloud], bool | None] - set_fn: Callable[[Cloud, bool], Awaitable[Any]] - - def __post_init__(self) -> None: - """Sync icon_off with icon.""" - if self.icon_off is None: - self.icon_off = self.icon + is_on_fn: Callable[[Cloud[CloudClient]], bool | None] + set_fn: Callable[[Cloud[CloudClient], bool], Awaitable[Any]] SWITCHES: tuple[HomeAssistantCloudSpookSwitchEntityDescription, ...] = ( @@ -105,7 +100,7 @@ async def async_setup_entry( ) -> None: """Set up Spook Home Assistant Cloud switches.""" if CLOUD_DOMAIN in hass.config.components: - cloud: Cloud = hass.data[CLOUD_DOMAIN] + cloud: Cloud[CloudClient] = hass.data[CLOUD_DOMAIN] async_add_entities( HomeAssistantCloudSpookSwitchEntity(cloud, description) for description in SWITCHES @@ -131,8 +126,8 @@ async def _update_state(_: Any) -> None: @property def icon(self) -> str | None: """Return the icon.""" - if self.entity_description.icon_off and self.is_on is False: - return self.entity_description.icon_off + if self.entity_description.icon and self.is_on is False: + return self.entity_description.icon return super().icon @property @@ -142,8 +137,8 @@ def is_on(self) -> bool | None: async def async_turn_on(self, **_kwargs: Any) -> None: """Turn the entity on.""" - await self.entity_description.set_fn(self._cloud, enabled=True) + await self.entity_description.set_fn(self._cloud, True) # noqa: FBT003 async def async_turn_off(self, **_kwargs: Any) -> None: """Turn the entity off.""" - await self.entity_description.set_fn(self._cloud, enabled=False) + await self.entity_description.set_fn(self._cloud, False) # noqa: FBT003 diff --git a/custom_components/spook/ectoplasms/homeassistant/button.py b/custom_components/spook/ectoplasms/homeassistant/button.py index d4408adc..7aa6a239 100644 --- a/custom_components/spook/ectoplasms/homeassistant/button.py +++ b/custom_components/spook/ectoplasms/homeassistant/button.py @@ -28,7 +28,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback -@dataclass(kw_only=True) +@dataclass(frozen=True, kw_only=True) class HomeAssistantSpookButtonEntityDescription( SpookEntityDescription, ButtonEntityDescription, diff --git a/custom_components/spook/ectoplasms/homeassistant/sensor.py b/custom_components/spook/ectoplasms/homeassistant/sensor.py index c058fb8a..335e20a4 100644 --- a/custom_components/spook/ectoplasms/homeassistant/sensor.py +++ b/custom_components/spook/ectoplasms/homeassistant/sensor.py @@ -47,7 +47,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback -@dataclass(kw_only=True) +@dataclass(frozen=True, kw_only=True) class HomeAssistantSpookSensorEntityDescription( SpookEntityDescription, SensorEntityDescription, diff --git a/custom_components/spook/ectoplasms/repairs/button.py b/custom_components/spook/ectoplasms/repairs/button.py index 0e4a2660..a8b90c7a 100644 --- a/custom_components/spook/ectoplasms/repairs/button.py +++ b/custom_components/spook/ectoplasms/repairs/button.py @@ -18,7 +18,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback -@dataclass(kw_only=True) +@dataclass(frozen=True, kw_only=True) class RepairsSpookButtonEntityDescription( SpookEntityDescription, ButtonEntityDescription, diff --git a/custom_components/spook/ectoplasms/repairs/event.py b/custom_components/spook/ectoplasms/repairs/event.py index 3b4c02cd..e35b443f 100644 --- a/custom_components/spook/ectoplasms/repairs/event.py +++ b/custom_components/spook/ectoplasms/repairs/event.py @@ -17,7 +17,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback -@dataclass +@dataclass(frozen=True, kw_only=True) class RepairsSpookEventEntityDescription( SpookEntityDescription, EventEntityDescription, diff --git a/custom_components/spook/ectoplasms/repairs/sensor.py b/custom_components/spook/ectoplasms/repairs/sensor.py index 1783f9c8..2e2e01b2 100644 --- a/custom_components/spook/ectoplasms/repairs/sensor.py +++ b/custom_components/spook/ectoplasms/repairs/sensor.py @@ -24,7 +24,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback -@dataclass(kw_only=True) +@dataclass(frozen=True, kw_only=True) class RepairsSpookSensorEntityDescription( SpookEntityDescription, SensorEntityDescription,