Update plugwise 0.16.2 (#65933)
This commit is contained in:
parent
0ea82bdbfb
commit
d12a392767
59 changed files with 837 additions and 317 deletions
|
@ -1,17 +1,24 @@
|
|||
"""DataUpdateCoordinator for Plugwise."""
|
||||
from datetime import timedelta
|
||||
from typing import Any, NamedTuple
|
||||
|
||||
import async_timeout
|
||||
from plugwise import Smile
|
||||
from plugwise.exceptions import XMLDataMissingError
|
||||
from plugwise.exceptions import PlugwiseException, XMLDataMissingError
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import DEFAULT_SCAN_INTERVAL, DEFAULT_TIMEOUT, DOMAIN, LOGGER
|
||||
from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, LOGGER
|
||||
|
||||
|
||||
class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[bool]):
|
||||
class PlugwiseData(NamedTuple):
|
||||
"""Plugwise data stored in the DataUpdateCoordinator."""
|
||||
|
||||
gateway: dict[str, Any]
|
||||
devices: dict[str, dict[str, Any]]
|
||||
|
||||
|
||||
class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[PlugwiseData]):
|
||||
"""Class to manage fetching Plugwise data from single endpoint."""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, api: Smile) -> None:
|
||||
|
@ -26,11 +33,14 @@ class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[bool]):
|
|||
)
|
||||
self.api = api
|
||||
|
||||
async def _async_update_data(self) -> bool:
|
||||
async def _async_update_data(self) -> PlugwiseData:
|
||||
"""Fetch data from Plugwise."""
|
||||
try:
|
||||
async with async_timeout.timeout(DEFAULT_TIMEOUT):
|
||||
await self.api.full_update_device()
|
||||
data = await self.api.async_update()
|
||||
except XMLDataMissingError as err:
|
||||
raise UpdateFailed("Smile update failed") from err
|
||||
return True
|
||||
raise UpdateFailed(
|
||||
f"No XML data received for: {self.api.smile_name}"
|
||||
) from err
|
||||
except PlugwiseException as err:
|
||||
raise UpdateFailed(f"Updated failed for: {self.api.smile_name}") from err
|
||||
return PlugwiseData(*data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue