From 60193a3c2dee15f12c18dde005fd5e1a88a8ab50 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 15 May 2024 13:52:32 +0200 Subject: [PATCH] Move mill coordinator to separate module (#117493) --- homeassistant/components/mill/__init__.py | 27 +------------- homeassistant/components/mill/climate.py | 2 +- homeassistant/components/mill/coordinator.py | 38 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 homeassistant/components/mill/coordinator.py diff --git a/homeassistant/components/mill/__init__.py b/homeassistant/components/mill/__init__.py index b2f06597563..11199e126cf 100644 --- a/homeassistant/components/mill/__init__.py +++ b/homeassistant/components/mill/__init__.py @@ -3,7 +3,6 @@ from __future__ import annotations from datetime import timedelta -import logging from mill import Mill 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.exceptions import ConfigEntryNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from .const import CLOUD, CONNECTION_TYPE, DOMAIN, LOCAL - -_LOGGER = logging.getLogger(__name__) +from .coordinator import MillDataUpdateCoordinator 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: """Set up the Mill heater.""" hass.data.setdefault(DOMAIN, {LOCAL: {}, CLOUD: {}}) diff --git a/homeassistant/components/mill/climate.py b/homeassistant/components/mill/climate.py index a2e70b8f9c8..5c5c7882634 100644 --- a/homeassistant/components/mill/climate.py +++ b/homeassistant/components/mill/climate.py @@ -26,7 +26,6 @@ from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, Device from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity -from . import MillDataUpdateCoordinator from .const import ( ATTR_AWAY_TEMP, ATTR_COMFORT_TEMP, @@ -41,6 +40,7 @@ from .const import ( MIN_TEMP, SERVICE_SET_ROOM_TEMP, ) +from .coordinator import MillDataUpdateCoordinator SET_ROOM_TEMP_SCHEMA = vol.Schema( { diff --git a/homeassistant/components/mill/coordinator.py b/homeassistant/components/mill/coordinator.py new file mode 100644 index 00000000000..9821519ca84 --- /dev/null +++ b/homeassistant/components/mill/coordinator.py @@ -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, + )