mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Move melnor coordinator to separate module (#117486)
This commit is contained in:
parent
37c55d81e3
commit
6bd3648c77
@ -12,7 +12,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .models import MelnorDataUpdateCoordinator
|
from .coordinator import MelnorDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [
|
PLATFORMS: list[Platform] = [
|
||||||
Platform.NUMBER,
|
Platform.NUMBER,
|
||||||
|
33
homeassistant/components/melnor/coordinator.py
Normal file
33
homeassistant/components/melnor/coordinator.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
"""Coordinator for the Melnor integration."""
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from melnor_bluetooth.device import Device
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class MelnorDataUpdateCoordinator(DataUpdateCoordinator[Device]):
|
||||||
|
"""Melnor data update coordinator."""
|
||||||
|
|
||||||
|
_device: Device
|
||||||
|
|
||||||
|
def __init__(self, hass: HomeAssistant, device: Device) -> None:
|
||||||
|
"""Initialize my coordinator."""
|
||||||
|
super().__init__(
|
||||||
|
hass,
|
||||||
|
_LOGGER,
|
||||||
|
name="Melnor Bluetooth",
|
||||||
|
update_interval=timedelta(seconds=5),
|
||||||
|
)
|
||||||
|
self._device = device
|
||||||
|
|
||||||
|
async def _async_update_data(self):
|
||||||
|
"""Update the device state."""
|
||||||
|
|
||||||
|
await self._device.fetch_state()
|
||||||
|
return self._device
|
@ -1,45 +1,17 @@
|
|||||||
"""Melnor integration models."""
|
"""Melnor integration models."""
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from datetime import timedelta
|
|
||||||
import logging
|
|
||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
|
|
||||||
from melnor_bluetooth.device import Device, Valve
|
from melnor_bluetooth.device import Device, Valve
|
||||||
|
|
||||||
from homeassistant.components.number import EntityDescription
|
from homeassistant.components.number import EntityDescription
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
CoordinatorEntity,
|
|
||||||
DataUpdateCoordinator,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .coordinator import MelnorDataUpdateCoordinator
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class MelnorDataUpdateCoordinator(DataUpdateCoordinator[Device]): # pylint: disable=hass-enforce-coordinator-module
|
|
||||||
"""Melnor data update coordinator."""
|
|
||||||
|
|
||||||
_device: Device
|
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, device: Device) -> None:
|
|
||||||
"""Initialize my coordinator."""
|
|
||||||
super().__init__(
|
|
||||||
hass,
|
|
||||||
_LOGGER,
|
|
||||||
name="Melnor Bluetooth",
|
|
||||||
update_interval=timedelta(seconds=5),
|
|
||||||
)
|
|
||||||
self._device = device
|
|
||||||
|
|
||||||
async def _async_update_data(self):
|
|
||||||
"""Update the device state."""
|
|
||||||
|
|
||||||
await self._device.fetch_state()
|
|
||||||
return self._device
|
|
||||||
|
|
||||||
|
|
||||||
class MelnorBluetoothEntity(CoordinatorEntity[MelnorDataUpdateCoordinator]):
|
class MelnorBluetoothEntity(CoordinatorEntity[MelnorDataUpdateCoordinator]):
|
||||||
|
@ -19,11 +19,8 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .models import (
|
from .coordinator import MelnorDataUpdateCoordinator
|
||||||
MelnorDataUpdateCoordinator,
|
from .models import MelnorZoneEntity, get_entities_for_valves
|
||||||
MelnorZoneEntity,
|
|
||||||
get_entities_for_valves,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
|
@ -27,12 +27,8 @@ from homeassistant.helpers.typing import StateType
|
|||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .models import (
|
from .coordinator import MelnorDataUpdateCoordinator
|
||||||
MelnorBluetoothEntity,
|
from .models import MelnorBluetoothEntity, MelnorZoneEntity, get_entities_for_valves
|
||||||
MelnorDataUpdateCoordinator,
|
|
||||||
MelnorZoneEntity,
|
|
||||||
get_entities_for_valves,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def watering_seconds_left(valve: Valve) -> datetime | None:
|
def watering_seconds_left(valve: Valve) -> datetime | None:
|
||||||
|
@ -18,11 +18,8 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .models import (
|
from .coordinator import MelnorDataUpdateCoordinator
|
||||||
MelnorDataUpdateCoordinator,
|
from .models import MelnorZoneEntity, get_entities_for_valves
|
||||||
MelnorZoneEntity,
|
|
||||||
get_entities_for_valves,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
|
@ -16,11 +16,8 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .models import (
|
from .coordinator import MelnorDataUpdateCoordinator
|
||||||
MelnorDataUpdateCoordinator,
|
from .models import MelnorZoneEntity, get_entities_for_valves
|
||||||
MelnorZoneEntity,
|
|
||||||
get_entities_for_valves,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user