Move venstar base entity to separate module (#126542)

This commit is contained in:
epenet 2024-09-23 15:12:55 +02:00 committed by GitHub
parent f5697ad5d2
commit 8c4ea323ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 48 additions and 39 deletions

View file

@ -13,9 +13,7 @@ from homeassistant.const import (
CONF_USERNAME,
Platform,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.core import HomeAssistant
from .const import DOMAIN, VENSTAR_TIMEOUT
from .coordinator import VenstarDataUpdateCoordinator
@ -59,36 +57,3 @@ async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
if unload_ok:
hass.data[DOMAIN].pop(config.entry_id)
return unload_ok
class VenstarEntity(CoordinatorEntity[VenstarDataUpdateCoordinator]):
"""Representation of a Venstar entity."""
_attr_has_entity_name = True
def __init__(
self,
venstar_data_coordinator: VenstarDataUpdateCoordinator,
config: ConfigEntry,
) -> None:
"""Initialize the data object."""
super().__init__(venstar_data_coordinator)
self._config = config
self._client = venstar_data_coordinator.client
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self.async_write_ha_state()
@property
def device_info(self) -> DeviceInfo:
"""Return the device information for this entity."""
fw_ver_major, fw_ver_minor = self._client.get_firmware_ver()
return DeviceInfo(
identifiers={(DOMAIN, self._config.entry_id)},
name=self._client.name,
manufacturer="Venstar",
model=f"{self._client.model}-{self._client.get_type()}",
sw_version=f"{fw_ver_major}.{fw_ver_minor}",
)

View file

@ -8,8 +8,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import VenstarEntity
from .const import DOMAIN
from .entity import VenstarEntity
async def async_setup_entry(

View file

@ -36,7 +36,6 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import VenstarEntity
from .const import (
_LOGGER,
ATTR_FAN_STATE,
@ -47,6 +46,7 @@ from .const import (
HOLD_MODE_TEMPERATURE,
)
from .coordinator import VenstarDataUpdateCoordinator
from .entity import VenstarEntity
PLATFORM_SCHEMA = CLIMATE_PLATFORM_SCHEMA.extend(
{

View file

@ -0,0 +1,44 @@
"""The venstar component."""
from __future__ import annotations
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .coordinator import VenstarDataUpdateCoordinator
class VenstarEntity(CoordinatorEntity[VenstarDataUpdateCoordinator]):
"""Representation of a Venstar entity."""
_attr_has_entity_name = True
def __init__(
self,
venstar_data_coordinator: VenstarDataUpdateCoordinator,
config: ConfigEntry,
) -> None:
"""Initialize the data object."""
super().__init__(venstar_data_coordinator)
self._config = config
self._client = venstar_data_coordinator.client
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self.async_write_ha_state()
@property
def device_info(self) -> DeviceInfo:
"""Return the device information for this entity."""
fw_ver_major, fw_ver_minor = self._client.get_firmware_ver()
return DeviceInfo(
identifiers={(DOMAIN, self._config.entry_id)},
name=self._client.name,
manufacturer="Venstar",
model=f"{self._client.model}-{self._client.get_type()}",
sw_version=f"{fw_ver_major}.{fw_ver_minor}",
)

View file

@ -23,9 +23,9 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import VenstarEntity
from .const import DOMAIN
from .coordinator import VenstarDataUpdateCoordinator
from .entity import VenstarEntity
RUNTIME_HEAT1 = "heat1"
RUNTIME_HEAT2 = "heat2"