Move Aseko coordinator to separate file (#95120)
This commit is contained in:
parent
e2fdc6a98b
commit
fe0d33d97c
6 changed files with 45 additions and 33 deletions
|
@ -82,6 +82,7 @@ omit =
|
||||||
homeassistant/components/arwn/sensor.py
|
homeassistant/components/arwn/sensor.py
|
||||||
homeassistant/components/aseko_pool_live/__init__.py
|
homeassistant/components/aseko_pool_live/__init__.py
|
||||||
homeassistant/components/aseko_pool_live/binary_sensor.py
|
homeassistant/components/aseko_pool_live/binary_sensor.py
|
||||||
|
homeassistant/components/aseko_pool_live/coordinator.py
|
||||||
homeassistant/components/aseko_pool_live/entity.py
|
homeassistant/components/aseko_pool_live/entity.py
|
||||||
homeassistant/components/aseko_pool_live/sensor.py
|
homeassistant/components/aseko_pool_live/sensor.py
|
||||||
homeassistant/components/asterisk_cdr/mailbox.py
|
homeassistant/components/asterisk_cdr/mailbox.py
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
"""The Aseko Pool Live integration."""
|
"""The Aseko Pool Live integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aioaseko import APIUnavailable, MobileAccount, Unit, Variable
|
from aioaseko import APIUnavailable, MobileAccount
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN, Platform
|
from homeassistant.const import CONF_ACCESS_TOKEN, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .coordinator import AsekoDataUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -49,28 +48,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
class AsekoDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Variable]]):
|
|
||||||
"""Class to manage fetching Aseko unit data from single endpoint."""
|
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, unit: Unit) -> None:
|
|
||||||
"""Initialize global Aseko unit data updater."""
|
|
||||||
self._unit = unit
|
|
||||||
|
|
||||||
if self._unit.name:
|
|
||||||
name = self._unit.name
|
|
||||||
else:
|
|
||||||
name = f"{self._unit.type}-{self._unit.serial_number}"
|
|
||||||
|
|
||||||
super().__init__(
|
|
||||||
hass,
|
|
||||||
_LOGGER,
|
|
||||||
name=name,
|
|
||||||
update_interval=timedelta(minutes=2),
|
|
||||||
)
|
|
||||||
|
|
||||||
async def _async_update_data(self) -> dict[str, Variable]:
|
|
||||||
"""Fetch unit data."""
|
|
||||||
await self._unit.get_state()
|
|
||||||
return {variable.type: variable for variable in self._unit.variables}
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AsekoDataUpdateCoordinator
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .coordinator import AsekoDataUpdateCoordinator
|
||||||
from .entity import AsekoEntity
|
from .entity import AsekoEntity
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class AsekoBinarySensorDescriptionMixin:
|
||||||
class AsekoBinarySensorEntityDescription(
|
class AsekoBinarySensorEntityDescription(
|
||||||
BinarySensorEntityDescription, AsekoBinarySensorDescriptionMixin
|
BinarySensorEntityDescription, AsekoBinarySensorDescriptionMixin
|
||||||
):
|
):
|
||||||
"""Describes a Aseko binary sensor entity."""
|
"""Describes an Aseko binary sensor entity."""
|
||||||
|
|
||||||
|
|
||||||
UNIT_BINARY_SENSORS: tuple[AsekoBinarySensorEntityDescription, ...] = (
|
UNIT_BINARY_SENSORS: tuple[AsekoBinarySensorEntityDescription, ...] = (
|
||||||
|
|
37
homeassistant/components/aseko_pool_live/coordinator.py
Normal file
37
homeassistant/components/aseko_pool_live/coordinator.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
"""The Aseko Pool Live integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from aioaseko import Unit, Variable
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class AsekoDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Variable]]):
|
||||||
|
"""Class to manage fetching Aseko unit data from single endpoint."""
|
||||||
|
|
||||||
|
def __init__(self, hass: HomeAssistant, unit: Unit) -> None:
|
||||||
|
"""Initialize global Aseko unit data updater."""
|
||||||
|
self._unit = unit
|
||||||
|
|
||||||
|
if self._unit.name:
|
||||||
|
name = self._unit.name
|
||||||
|
else:
|
||||||
|
name = f"{self._unit.type}-{self._unit.serial_number}"
|
||||||
|
|
||||||
|
super().__init__(
|
||||||
|
hass,
|
||||||
|
_LOGGER,
|
||||||
|
name=name,
|
||||||
|
update_interval=timedelta(minutes=2),
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _async_update_data(self) -> dict[str, Variable]:
|
||||||
|
"""Fetch unit data."""
|
||||||
|
await self._unit.get_state()
|
||||||
|
return {variable.type: variable for variable in self._unit.variables}
|
|
@ -4,8 +4,8 @@ from aioaseko import Unit
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from . import AsekoDataUpdateCoordinator
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .coordinator import AsekoDataUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
class AsekoEntity(CoordinatorEntity[AsekoDataUpdateCoordinator]):
|
class AsekoEntity(CoordinatorEntity[AsekoDataUpdateCoordinator]):
|
||||||
|
|
|
@ -12,8 +12,8 @@ from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AsekoDataUpdateCoordinator
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .coordinator import AsekoDataUpdateCoordinator
|
||||||
from .entity import AsekoEntity
|
from .entity import AsekoEntity
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ async def async_setup_entry(
|
||||||
class VariableSensorEntity(AsekoEntity, SensorEntity):
|
class VariableSensorEntity(AsekoEntity, SensorEntity):
|
||||||
"""Representation of a unit variable sensor entity."""
|
"""Representation of a unit variable sensor entity."""
|
||||||
|
|
||||||
attr_state_class = SensorStateClass.MEASUREMENT
|
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, unit: Unit, variable: Variable, coordinator: AsekoDataUpdateCoordinator
|
self, unit: Unit, variable: Variable, coordinator: AsekoDataUpdateCoordinator
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue