mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 21:25:13 +02:00
Move plaato coordinator to separate module (#118019)
This commit is contained in:
@@ -18,8 +18,6 @@ from pyplaato.plaato import (
|
||||
ATTR_TEMP,
|
||||
ATTR_TEMP_UNIT,
|
||||
ATTR_VOLUME_UNIT,
|
||||
Plaato,
|
||||
PlaatoDeviceType,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
@@ -30,15 +28,12 @@ from homeassistant.const import (
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_TOKEN,
|
||||
CONF_WEBHOOK_ID,
|
||||
Platform,
|
||||
UnitOfTemperature,
|
||||
UnitOfVolume,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import (
|
||||
CONF_DEVICE_NAME,
|
||||
@@ -55,6 +50,7 @@ from .const import (
|
||||
SENSOR_DATA,
|
||||
UNDO_UPDATE_LISTENER,
|
||||
)
|
||||
from .coordinator import PlaatoCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -207,34 +203,3 @@ async def handle_webhook(hass, webhook_id, request):
|
||||
def _device_id(data):
|
||||
"""Return name of device sensor."""
|
||||
return f"{data.get(ATTR_DEVICE_NAME)}_{data.get(ATTR_DEVICE_ID)}"
|
||||
|
||||
|
||||
class PlaatoCoordinator(DataUpdateCoordinator): # pylint: disable=hass-enforce-coordinator-module
|
||||
"""Class to manage fetching data from the API."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
auth_token: str,
|
||||
device_type: PlaatoDeviceType,
|
||||
update_interval: timedelta,
|
||||
) -> None:
|
||||
"""Initialize."""
|
||||
self.api = Plaato(auth_token=auth_token)
|
||||
self.hass = hass
|
||||
self.device_type = device_type
|
||||
self.platforms: list[Platform] = []
|
||||
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=DOMAIN,
|
||||
update_interval=update_interval,
|
||||
)
|
||||
|
||||
async def _async_update_data(self):
|
||||
"""Update data via library."""
|
||||
return await self.api.get_data(
|
||||
session=aiohttp_client.async_get_clientsession(self.hass),
|
||||
device_type=self.device_type,
|
||||
)
|
||||
|
46
homeassistant/components/plaato/coordinator.py
Normal file
46
homeassistant/components/plaato/coordinator.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""Coordinator for Plaato devices."""
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from pyplaato.plaato import Plaato, PlaatoDeviceType
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PlaatoCoordinator(DataUpdateCoordinator):
|
||||
"""Class to manage fetching data from the API."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
auth_token: str,
|
||||
device_type: PlaatoDeviceType,
|
||||
update_interval: timedelta,
|
||||
) -> None:
|
||||
"""Initialize."""
|
||||
self.api = Plaato(auth_token=auth_token)
|
||||
self.hass = hass
|
||||
self.device_type = device_type
|
||||
self.platforms: list[Platform] = []
|
||||
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=DOMAIN,
|
||||
update_interval=update_interval,
|
||||
)
|
||||
|
||||
async def _async_update_data(self):
|
||||
"""Update data via library."""
|
||||
return await self.api.get_data(
|
||||
session=aiohttp_client.async_get_clientsession(self.hass),
|
||||
device_type=self.device_type,
|
||||
)
|
@@ -29,11 +29,11 @@ async def init_integration(
|
||||
"""Mock integration setup."""
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.plaato.Plaato.get_airlock_data",
|
||||
"homeassistant.components.plaato.coordinator.Plaato.get_airlock_data",
|
||||
return_value=PlaatoAirlock(AIRLOCK_DATA),
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.plaato.Plaato.get_keg_data",
|
||||
"homeassistant.components.plaato.coordinator.Plaato.get_keg_data",
|
||||
return_value=PlaatoKeg(KEG_DATA),
|
||||
),
|
||||
):
|
||||
|
Reference in New Issue
Block a user