-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
148 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from typing import Optional, Any | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import callback | ||
from homeassistant.helpers.entity import DeviceInfo | ||
from homeassistant.helpers.typing import HomeAssistantType | ||
from homeassistant.helpers.update_coordinator import ( | ||
CoordinatorEntity, | ||
) | ||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator | ||
from pyhon.appliance import HonAppliance | ||
|
||
from .const import DOMAIN | ||
from .typedefs import HonEntityDescription | ||
|
||
|
||
class HonEntity(CoordinatorEntity[DataUpdateCoordinator[dict[str, Any]]]): | ||
_attr_has_entity_name = True | ||
_attr_should_poll = False | ||
|
||
def __init__( | ||
self, | ||
hass: HomeAssistantType, | ||
entry: ConfigEntry, | ||
device: HonAppliance, | ||
description: Optional[HonEntityDescription] = None, | ||
) -> None: | ||
self.coordinator = hass.data[DOMAIN][entry.unique_id]["coordinator"] | ||
super().__init__(self.coordinator) | ||
self._hon = hass.data[DOMAIN][entry.unique_id]["hon"] | ||
self._hass = hass | ||
self._device: HonAppliance = device | ||
|
||
if description is not None: | ||
self.entity_description = description | ||
self._attr_unique_id = f"{self._device.unique_id}{description.key}" | ||
else: | ||
self._attr_unique_id = self._device.unique_id | ||
self._handle_coordinator_update(update=False) | ||
|
||
@property | ||
def device_info(self) -> DeviceInfo: | ||
return DeviceInfo( | ||
identifiers={(DOMAIN, self._device.unique_id)}, | ||
manufacturer=self._device.get("brand", ""), | ||
name=self._device.nick_name, | ||
model=self._device.model_name, | ||
sw_version=self._device.get("fwVersion", ""), | ||
) | ||
|
||
@callback | ||
def _handle_coordinator_update(self, update: bool = True) -> None: | ||
if update: | ||
self.async_write_ha_state() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.