Move vallox coordinator to separate module (#117503)
* Move vallox coordinator to separate module * Move logic into coordinator class * Adjust
This commit is contained in:
parent
2c6071820e
commit
aa2485c7b9
9 changed files with 61 additions and 34 deletions
|
@ -1552,6 +1552,8 @@ omit =
|
|||
homeassistant/components/v2c/number.py
|
||||
homeassistant/components/v2c/sensor.py
|
||||
homeassistant/components/v2c/switch.py
|
||||
homeassistant/components/vallox/__init__.py
|
||||
homeassistant/components/vallox/coordinator.py
|
||||
homeassistant/components/vasttrafik/sensor.py
|
||||
homeassistant/components/velbus/__init__.py
|
||||
homeassistant/components/velbus/binary_sensor.py
|
||||
|
|
|
@ -6,7 +6,7 @@ import ipaddress
|
|||
import logging
|
||||
from typing import NamedTuple
|
||||
|
||||
from vallox_websocket_api import MetricData, Profile, Vallox, ValloxApiException
|
||||
from vallox_websocket_api import Profile, Vallox, ValloxApiException
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
@ -14,11 +14,7 @@ from homeassistant.const import CONF_HOST, CONF_NAME, Platform
|
|||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
UpdateFailed,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
DEFAULT_FAN_SPEED_AWAY,
|
||||
|
@ -26,8 +22,8 @@ from .const import (
|
|||
DEFAULT_FAN_SPEED_HOME,
|
||||
DEFAULT_NAME,
|
||||
DOMAIN,
|
||||
STATE_SCAN_INTERVAL,
|
||||
)
|
||||
from .coordinator import ValloxDataUpdateCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -93,10 +89,6 @@ SERVICE_TO_METHOD = {
|
|||
}
|
||||
|
||||
|
||||
class ValloxDataUpdateCoordinator(DataUpdateCoordinator[MetricData]): # pylint: disable=hass-enforce-coordinator-module
|
||||
"""The DataUpdateCoordinator for Vallox."""
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up the client and boot the platforms."""
|
||||
host = entry.data[CONF_HOST]
|
||||
|
@ -104,22 +96,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
client = Vallox(host)
|
||||
|
||||
async def async_update_data() -> MetricData:
|
||||
"""Fetch state update."""
|
||||
_LOGGER.debug("Updating Vallox state cache")
|
||||
|
||||
try:
|
||||
return await client.fetch_metric_data()
|
||||
except ValloxApiException as err:
|
||||
raise UpdateFailed("Error during state cache update") from err
|
||||
|
||||
coordinator = ValloxDataUpdateCoordinator(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=f"{name} DataUpdateCoordinator",
|
||||
update_interval=STATE_SCAN_INTERVAL,
|
||||
update_method=async_update_data,
|
||||
)
|
||||
coordinator = ValloxDataUpdateCoordinator(hass, name, client)
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
|
@ -161,7 +138,7 @@ class ValloxServiceHandler:
|
|||
"""Services implementation."""
|
||||
|
||||
def __init__(
|
||||
self, client: Vallox, coordinator: DataUpdateCoordinator[MetricData]
|
||||
self, client: Vallox, coordinator: ValloxDataUpdateCoordinator
|
||||
) -> None:
|
||||
"""Initialize the proxy."""
|
||||
self._client = client
|
||||
|
|
|
@ -13,8 +13,9 @@ from homeassistant.const import EntityCategory
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ValloxDataUpdateCoordinator, ValloxEntity
|
||||
from . import ValloxEntity
|
||||
from .const import DOMAIN
|
||||
from .coordinator import ValloxDataUpdateCoordinator
|
||||
|
||||
|
||||
class ValloxBinarySensorEntity(ValloxEntity, BinarySensorEntity):
|
||||
|
|
42
homeassistant/components/vallox/coordinator.py
Normal file
42
homeassistant/components/vallox/coordinator.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
"""Coordinator for Vallox ventilation units."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from vallox_websocket_api import MetricData, Vallox, ValloxApiException
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import STATE_SCAN_INTERVAL
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ValloxDataUpdateCoordinator(DataUpdateCoordinator[MetricData]):
|
||||
"""The DataUpdateCoordinator for Vallox."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
name: str,
|
||||
client: Vallox,
|
||||
) -> None:
|
||||
"""Initialize Vallox data coordinator."""
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=f"{name} DataUpdateCoordinator",
|
||||
update_interval=STATE_SCAN_INTERVAL,
|
||||
)
|
||||
self.client = client
|
||||
|
||||
async def _async_update_data(self) -> MetricData:
|
||||
"""Fetch state update."""
|
||||
_LOGGER.debug("Updating Vallox state cache")
|
||||
|
||||
try:
|
||||
return await self.client.fetch_metric_data()
|
||||
except ValloxApiException as err:
|
||||
raise UpdateFailed("Error during state cache update") from err
|
|
@ -12,8 +12,9 @@ from homeassistant.const import EntityCategory
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ValloxDataUpdateCoordinator, ValloxEntity
|
||||
from . import ValloxEntity
|
||||
from .const import DOMAIN
|
||||
from .coordinator import ValloxDataUpdateCoordinator
|
||||
|
||||
|
||||
class ValloxFilterChangeDateEntity(ValloxEntity, DateEntity):
|
||||
|
|
|
@ -14,7 +14,7 @@ from homeassistant.exceptions import HomeAssistantError
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import ValloxDataUpdateCoordinator, ValloxEntity
|
||||
from . import ValloxEntity
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
METRIC_KEY_MODE,
|
||||
|
@ -26,6 +26,7 @@ from .const import (
|
|||
PRESET_MODE_TO_VALLOX_PROFILE_SETTABLE,
|
||||
VALLOX_PROFILE_TO_PRESET_MODE_REPORTABLE,
|
||||
)
|
||||
from .coordinator import ValloxDataUpdateCoordinator
|
||||
|
||||
|
||||
class ExtraStateAttributeDetails(NamedTuple):
|
||||
|
|
|
@ -16,8 +16,9 @@ from homeassistant.const import EntityCategory, UnitOfTemperature
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ValloxDataUpdateCoordinator, ValloxEntity
|
||||
from . import ValloxEntity
|
||||
from .const import DOMAIN
|
||||
from .coordinator import ValloxDataUpdateCoordinator
|
||||
|
||||
|
||||
class ValloxNumberEntity(ValloxEntity, NumberEntity):
|
||||
|
|
|
@ -24,7 +24,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import ValloxDataUpdateCoordinator, ValloxEntity
|
||||
from . import ValloxEntity
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
METRIC_KEY_MODE,
|
||||
|
@ -32,6 +32,7 @@ from .const import (
|
|||
VALLOX_CELL_STATE_TO_STR,
|
||||
VALLOX_PROFILE_TO_PRESET_MODE_REPORTABLE,
|
||||
)
|
||||
from .coordinator import ValloxDataUpdateCoordinator
|
||||
|
||||
|
||||
class ValloxSensorEntity(ValloxEntity, SensorEntity):
|
||||
|
|
|
@ -13,8 +13,9 @@ from homeassistant.const import EntityCategory
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ValloxDataUpdateCoordinator, ValloxEntity
|
||||
from . import ValloxEntity
|
||||
from .const import DOMAIN
|
||||
from .coordinator import ValloxDataUpdateCoordinator
|
||||
|
||||
|
||||
class ValloxSwitchEntity(ValloxEntity, SwitchEntity):
|
||||
|
|
Loading…
Add table
Reference in a new issue