Skip to content

Commit

Permalink
Store zaehlpunkt granularity in extra attributes to use it in histori…
Browse files Browse the repository at this point in the history
…cal import call

Fixes #193
  • Loading branch information
DarwinsBuddy committed Oct 29, 2023
1 parent 39d35dc commit ef9008a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
11 changes: 11 additions & 0 deletions custom_components/wnsm/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
9 changes: 7 additions & 2 deletions custom_components/wnsm/base_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}")
Expand Down
1 change: 1 addition & 0 deletions custom_components/wnsm/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
("isDefault", "default"),
("isActive", "active"),
("isSmartMeterMarketReady", "smartMeterReady"),
("idexStatus.granularity.status", "granularity")
]

ATTRS_CONSUMPTIONS_CALL = [
Expand Down

0 comments on commit ef9008a

Please sign in to comment.