Move mill coordinator to separate module (#117493)
This commit is contained in:
parent
4803db7cf0
commit
60193a3c2d
3 changed files with 40 additions and 27 deletions
|
@ -3,7 +3,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
|
||||||
|
|
||||||
from mill import Mill
|
from mill import Mill
|
||||||
from mill_local import Mill as MillLocal
|
from mill_local import Mill as MillLocal
|
||||||
|
@ -13,37 +12,13 @@ from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_USERNAME, P
|
||||||
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 CLOUD, CONNECTION_TYPE, DOMAIN, LOCAL
|
from .const import CLOUD, CONNECTION_TYPE, DOMAIN, LOCAL
|
||||||
|
from .coordinator import MillDataUpdateCoordinator
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
|
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
|
||||||
|
|
||||||
|
|
||||||
class MillDataUpdateCoordinator(DataUpdateCoordinator): # pylint: disable=hass-enforce-coordinator-module
|
|
||||||
"""Class to manage fetching Mill data."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
hass: HomeAssistant,
|
|
||||||
update_interval: timedelta | None = None,
|
|
||||||
*,
|
|
||||||
mill_data_connection: Mill | MillLocal,
|
|
||||||
) -> None:
|
|
||||||
"""Initialize global Mill data updater."""
|
|
||||||
self.mill_data_connection = mill_data_connection
|
|
||||||
|
|
||||||
super().__init__(
|
|
||||||
hass,
|
|
||||||
_LOGGER,
|
|
||||||
name=DOMAIN,
|
|
||||||
update_method=mill_data_connection.fetch_heater_and_sensor_data,
|
|
||||||
update_interval=update_interval,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up the Mill heater."""
|
"""Set up the Mill heater."""
|
||||||
hass.data.setdefault(DOMAIN, {LOCAL: {}, CLOUD: {}})
|
hass.data.setdefault(DOMAIN, {LOCAL: {}, CLOUD: {}})
|
||||||
|
|
|
@ -26,7 +26,6 @@ from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, Device
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from . import MillDataUpdateCoordinator
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_AWAY_TEMP,
|
ATTR_AWAY_TEMP,
|
||||||
ATTR_COMFORT_TEMP,
|
ATTR_COMFORT_TEMP,
|
||||||
|
@ -41,6 +40,7 @@ from .const import (
|
||||||
MIN_TEMP,
|
MIN_TEMP,
|
||||||
SERVICE_SET_ROOM_TEMP,
|
SERVICE_SET_ROOM_TEMP,
|
||||||
)
|
)
|
||||||
|
from .coordinator import MillDataUpdateCoordinator
|
||||||
|
|
||||||
SET_ROOM_TEMP_SCHEMA = vol.Schema(
|
SET_ROOM_TEMP_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
|
|
38
homeassistant/components/mill/coordinator.py
Normal file
38
homeassistant/components/mill/coordinator.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
"""Coordinator for the mill component."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from mill import Mill
|
||||||
|
from mill_local import Mill as MillLocal
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class MillDataUpdateCoordinator(DataUpdateCoordinator):
|
||||||
|
"""Class to manage fetching Mill data."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
update_interval: timedelta | None = None,
|
||||||
|
*,
|
||||||
|
mill_data_connection: Mill | MillLocal,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize global Mill data updater."""
|
||||||
|
self.mill_data_connection = mill_data_connection
|
||||||
|
|
||||||
|
super().__init__(
|
||||||
|
hass,
|
||||||
|
_LOGGER,
|
||||||
|
name=DOMAIN,
|
||||||
|
update_method=mill_data_connection.fetch_heater_and_sensor_data,
|
||||||
|
update_interval=update_interval,
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue