Move venstar base entity to separate module (#126542)
This commit is contained in:
parent
f5697ad5d2
commit
8c4ea323ba
5 changed files with 48 additions and 39 deletions
|
@ -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}",
|
||||
)
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
{
|
||||
|
|
44
homeassistant/components/venstar/entity.py
Normal file
44
homeassistant/components/venstar/entity.py
Normal 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}",
|
||||
)
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue