mirror of
https://github.com/home-assistant/core.git
synced 2025-05-18 12:59:14 +00:00

* First checkin for myUplink * Refactored coordinator and sensor state classe * Updated .coveragerc * Update test_config_flow * Fix test_config_flow for myuplink * Only set state class for temperature sensor * PR comment updates * Type strong dict * use asyncio.timeouts * PR updates (part 1) * Updated to myuplink 0.0.9 * Add strict typing * Fix typing * Inherit CoordinatorEntity * Clean up coordinator and sensors * Use common base entity * Improve device point sensor * Exclude entity from coverage * Set device point entity name if there's no entity description * Update homeassistant/components/myuplink/sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/myuplink/entity.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/myuplink/entity.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Remvoed firmware + connstate sensors * Always add device point parameter name * Removed MyUplinkDeviceSensor * Removed unused class * key="celsius", --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
"""Coordinator for myUplink."""
|
|
import asyncio.timeouts
|
|
from dataclasses import dataclass
|
|
from datetime import datetime, timedelta
|
|
import logging
|
|
|
|
from myuplink.api import MyUplinkAPI
|
|
from myuplink.models import Device, DevicePoint, System
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
@dataclass
|
|
class CoordinatorData:
|
|
"""Represent coordinator data."""
|
|
|
|
systems: list[System]
|
|
devices: dict[str, Device]
|
|
points: dict[str, dict[str, DevicePoint]]
|
|
time: datetime
|
|
|
|
|
|
class MyUplinkDataCoordinator(DataUpdateCoordinator[CoordinatorData]):
|
|
"""Coordinator for myUplink data."""
|
|
|
|
def __init__(self, hass: HomeAssistant, api: MyUplinkAPI) -> None:
|
|
"""Initialize myUplink coordinator."""
|
|
super().__init__(
|
|
hass,
|
|
_LOGGER,
|
|
name="myuplink",
|
|
update_interval=timedelta(seconds=60),
|
|
)
|
|
self.api = api
|
|
|
|
async def _async_update_data(self) -> CoordinatorData:
|
|
"""Fetch data from the myUplink API."""
|
|
async with asyncio.timeout(10):
|
|
# Get systems
|
|
systems = await self.api.async_get_systems()
|
|
|
|
devices: dict[str, Device] = {}
|
|
points: dict[str, dict[str, DevicePoint]] = {}
|
|
device_ids = [
|
|
device.deviceId for system in systems for device in system.devices
|
|
]
|
|
for device_id in device_ids:
|
|
# Get device info
|
|
api_device_info = await self.api.async_get_device(device_id)
|
|
devices[device_id] = api_device_info
|
|
|
|
# Get device points (data)
|
|
api_device_points = await self.api.async_get_device_points(device_id)
|
|
point_info: dict[str, DevicePoint] = {}
|
|
for point in api_device_points:
|
|
point_info[point.parameter_id] = point
|
|
|
|
points[device_id] = point_info
|
|
|
|
return CoordinatorData(
|
|
systems=systems, devices=devices, points=points, time=datetime.now()
|
|
)
|