Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new sensors of Kostal Plenticore integration #103802

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use new client.
  • Loading branch information
stegm committed Nov 14, 2023
commit 34f904865c622df25b3ed34efed1042d02fb99f1
24 changes: 16 additions & 8 deletions homeassistant/components/kostal_plenticore/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@

import asyncio
from collections import defaultdict
from collections.abc import Callable
from collections.abc import Callable, Mapping
from datetime import datetime, timedelta
import logging
from typing import Any, TypeVar, cast

from aiohttp.client_exceptions import ClientError
from pykoplenti import ApiClient, ApiException, AuthenticationException
from pykoplenti import (
ApiClient,
ApiException,
AuthenticationException,
ExtendedApiClient,
)

from homeassistant.const import CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
Expand Down Expand Up @@ -51,7 +56,9 @@ def client(self) -> ApiClient:

async def async_setup(self) -> bool:
"""Set up Plenticore API client."""
self._client = ApiClient(async_get_clientsession(self.hass), host=self.host)
self._client = ExtendedApiClient(
async_get_clientsession(self.hass), host=self.host
)
try:
await self._client.login(self.config_entry.data[CONF_PASSWORD])
except AuthenticationException as err:
Expand Down Expand Up @@ -124,7 +131,7 @@ class DataUpdateCoordinatorMixin:

async def async_read_data(
self, module_id: str, data_id: str
) -> dict[str, dict[str, str]] | None:
) -> Mapping[str, Mapping[str, str]] | None:
"""Read data from Plenticore."""
if (client := self._plenticore.client) is None:
return None
Expand Down Expand Up @@ -190,7 +197,7 @@ def stop_fetch_data(self, module_id: str, data_id: str) -> None:


class ProcessDataUpdateCoordinator(
PlenticoreUpdateCoordinator[dict[str, dict[str, str]]]
PlenticoreUpdateCoordinator[Mapping[str, Mapping[str, str]]]
):
"""Implementation of PlenticoreUpdateCoordinator for process data."""

Expand All @@ -206,18 +213,19 @@ async def _async_update_data(self) -> dict[str, dict[str, str]]:
return {
module_id: {
process_data.id: process_data.value
for process_data in fetched_data[module_id]
for process_data in fetched_data[module_id].values()
}
for module_id in fetched_data
}


class SettingDataUpdateCoordinator(
PlenticoreUpdateCoordinator[dict[str, dict[str, str]]], DataUpdateCoordinatorMixin
PlenticoreUpdateCoordinator[Mapping[str, Mapping[str, str]]],
DataUpdateCoordinatorMixin,
):
"""Implementation of PlenticoreUpdateCoordinator for settings data."""

async def _async_update_data(self) -> dict[str, dict[str, str]]:
async def _async_update_data(self) -> Mapping[str, Mapping[str, str]]:
client = self._plenticore.client

if not self._fetch or client is None:
Expand Down