From ef9008ad50401a43da94ef810f7e84d739bf7050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Sp=C3=B6rk?= Date: Sun, 29 Oct 2023 10:31:21 +0100 Subject: [PATCH] Store zaehlpunkt granularity in extra attributes to use it in historical import call Fixes #193 --- custom_components/wnsm/api/constants.py | 11 +++++++++++ custom_components/wnsm/base_sensor.py | 9 +++++++-- custom_components/wnsm/const.py | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/custom_components/wnsm/api/constants.py b/custom_components/wnsm/api/constants.py index 16f3c22..22730a1 100644 --- a/custom_components/wnsm/api/constants.py +++ b/custom_components/wnsm/api/constants.py @@ -40,6 +40,17 @@ class ValueType(enum.Enum): DAY = "DAY" #: Consumption for the day QUARTER_HOUR = "QUARTER_HOUR" #: Consumption for 15min slots + @staticmethod + def from_str(label): + if label in ('METER_READ', 'meter_read'): + return ValueType.METER_READ + elif label in ('DAY', 'day'): + return ValueType.DAY + elif label in ('QUARTER_HOUR', 'quarter_hour'): + return ValueType.QUARTER_HOUR + else: + raise NotImplementedError + def build_access_token_args(**kwargs): """ diff --git a/custom_components/wnsm/base_sensor.py b/custom_components/wnsm/base_sensor.py index a2e42ca..73717d2 100644 --- a/custom_components/wnsm/base_sensor.py +++ b/custom_components/wnsm/base_sensor.py @@ -14,6 +14,7 @@ from homeassistant.util import slugify from .api import Smartmeter +from .api.constants import ValueType from .const import ( ATTRS_BASEINFORMATION_CALL, ATTRS_CONSUMPTIONS_CALL, @@ -89,7 +90,7 @@ def state(self) -> Optional[str]: # pylint: disable=overridden-final-method async def get_zaehlpunkt(self, smartmeter: Smartmeter) -> dict[str, str]: """ asynchronously get and parse /zaehlpunkt response - Returns response already sanitzied of the specified zahlpunkt in ctor + Returns response already sanitized of the specified zaehlpunkt in ctor """ zps = await self.hass.async_add_executor_job(smartmeter.zaehlpunkte) if zps is None or len(zps) == 0: @@ -123,7 +124,11 @@ async def get_consumption(self, smartmeter: Smartmeter, start_date: datetime): async def get_historic_data(self, smartmeter: Smartmeter): """Return three years of historic quarter-hourly data""" response = await self.hass.async_add_executor_job( - smartmeter.historical_data, self.zaehlpunkt, + smartmeter.historical_data, + self.zaehlpunkt, + None, + None, + ValueType.from_str(self._attr_extra_state_attributes.get('granularity', 'QUARTER_HOUR')) ) if "Exception" in response: raise RuntimeError(f"Cannot access historic data: {response}") diff --git a/custom_components/wnsm/const.py b/custom_components/wnsm/const.py index 46b8bf7..7b3a26e 100644 --- a/custom_components/wnsm/const.py +++ b/custom_components/wnsm/const.py @@ -36,6 +36,7 @@ ("isDefault", "default"), ("isActive", "active"), ("isSmartMeterMarketReady", "smartMeterReady"), + ("idexStatus.granularity.status", "granularity") ] ATTRS_CONSUMPTIONS_CALL = [