mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Move poolsense coordinator to its own file (#100964)
This commit is contained in:
parent
4c21aa18db
commit
eab428f0e2
@ -978,6 +978,7 @@ omit =
|
|||||||
homeassistant/components/point/sensor.py
|
homeassistant/components/point/sensor.py
|
||||||
homeassistant/components/poolsense/__init__.py
|
homeassistant/components/poolsense/__init__.py
|
||||||
homeassistant/components/poolsense/binary_sensor.py
|
homeassistant/components/poolsense/binary_sensor.py
|
||||||
|
homeassistant/components/poolsense/coordinator.py
|
||||||
homeassistant/components/poolsense/sensor.py
|
homeassistant/components/poolsense/sensor.py
|
||||||
homeassistant/components/powerwall/__init__.py
|
homeassistant/components/powerwall/__init__.py
|
||||||
homeassistant/components/progettihwsw/__init__.py
|
homeassistant/components/progettihwsw/__init__.py
|
||||||
|
@ -1,23 +1,17 @@
|
|||||||
"""The PoolSense integration."""
|
"""The PoolSense integration."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from poolsense import PoolSense
|
from poolsense import PoolSense
|
||||||
from poolsense.exceptions import PoolSenseError
|
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
from homeassistant.helpers.entity import EntityDescription
|
from homeassistant.helpers.entity import EntityDescription
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
CoordinatorEntity,
|
|
||||||
DataUpdateCoordinator,
|
|
||||||
UpdateFailed,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .const import ATTRIBUTION, DOMAIN
|
from .const import ATTRIBUTION, DOMAIN
|
||||||
|
from .coordinator import PoolSenseDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||||
|
|
||||||
@ -70,31 +64,3 @@ class PoolSenseEntity(CoordinatorEntity):
|
|||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_name = f"PoolSense {description.name}"
|
self._attr_name = f"PoolSense {description.name}"
|
||||||
self._attr_unique_id = f"{email}-{description.key}"
|
self._attr_unique_id = f"{email}-{description.key}"
|
||||||
|
|
||||||
|
|
||||||
class PoolSenseDataUpdateCoordinator(DataUpdateCoordinator):
|
|
||||||
"""Define an object to hold PoolSense data."""
|
|
||||||
|
|
||||||
def __init__(self, hass, entry):
|
|
||||||
"""Initialize."""
|
|
||||||
self.poolsense = PoolSense(
|
|
||||||
aiohttp_client.async_get_clientsession(hass),
|
|
||||||
entry.data[CONF_EMAIL],
|
|
||||||
entry.data[CONF_PASSWORD],
|
|
||||||
)
|
|
||||||
self.hass = hass
|
|
||||||
self.entry = entry
|
|
||||||
|
|
||||||
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=timedelta(hours=1))
|
|
||||||
|
|
||||||
async def _async_update_data(self):
|
|
||||||
"""Update data via library."""
|
|
||||||
data = {}
|
|
||||||
async with asyncio.timeout(10):
|
|
||||||
try:
|
|
||||||
data = await self.poolsense.get_poolsense_data()
|
|
||||||
except PoolSenseError as error:
|
|
||||||
_LOGGER.error("PoolSense query did not complete")
|
|
||||||
raise UpdateFailed(error) from error
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
43
homeassistant/components/poolsense/coordinator.py
Normal file
43
homeassistant/components/poolsense/coordinator.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
"""DataUpdateCoordinator for poolsense integration."""
|
||||||
|
import asyncio
|
||||||
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from poolsense import PoolSense
|
||||||
|
from poolsense.exceptions import PoolSenseError
|
||||||
|
|
||||||
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||||
|
from homeassistant.helpers import aiohttp_client
|
||||||
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class PoolSenseDataUpdateCoordinator(DataUpdateCoordinator):
|
||||||
|
"""Define an object to hold PoolSense data."""
|
||||||
|
|
||||||
|
def __init__(self, hass, entry):
|
||||||
|
"""Initialize."""
|
||||||
|
self.poolsense = PoolSense(
|
||||||
|
aiohttp_client.async_get_clientsession(hass),
|
||||||
|
entry.data[CONF_EMAIL],
|
||||||
|
entry.data[CONF_PASSWORD],
|
||||||
|
)
|
||||||
|
self.hass = hass
|
||||||
|
self.entry = entry
|
||||||
|
|
||||||
|
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=timedelta(hours=1))
|
||||||
|
|
||||||
|
async def _async_update_data(self):
|
||||||
|
"""Update data via library."""
|
||||||
|
data = {}
|
||||||
|
async with asyncio.timeout(10):
|
||||||
|
try:
|
||||||
|
data = await self.poolsense.get_poolsense_data()
|
||||||
|
except PoolSenseError as error:
|
||||||
|
_LOGGER.error("PoolSense query did not complete")
|
||||||
|
raise UpdateFailed(error) from error
|
||||||
|
|
||||||
|
return data
|
Loading…
x
Reference in New Issue
Block a user