mirror of
https://github.com/Andre0512/hon.git
synced 2026-02-24 02:52:14 +00:00
Replace deprecated HomeAssistantType with HomeAssistant from homeassistant.core. HomeAssistantType was removed in newer Home Assistant versions, causing ImportError. This updates all imports from homeassistant.helpers.typing to homeassistant.core. Fixes compatibility with Home Assistant 2026.x and later versions. Files updated: - __init__.py - binary_sensor.py - button.py - climate.py - entity.py - fan.py - light.py - lock.py - number.py - select.py - sensor.py - switch.py
57 lines
2 KiB
Python
57 lines
2 KiB
Python
from typing import Optional, Any
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import callback
|
|
from homeassistant.helpers.entity import DeviceInfo
|
|
from homeassistant.core import HomeAssistant
|
|
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: HomeAssistant,
|
|
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", "").capitalize(),
|
|
name=self._device.nick_name,
|
|
model=self._device.model_name,
|
|
sw_version=self._device.get("fwVersion", ""),
|
|
hw_version=f"{self._device.appliance_type}{self._device.model_id}",
|
|
serial_number=self._device.get("serialNumber", ""),
|
|
)
|
|
|
|
@callback
|
|
def _handle_coordinator_update(self, update: bool = True) -> None:
|
|
if update:
|
|
self.async_write_ha_state()
|