diff --git a/Pipfile b/Pipfile index c21f40d..6228309 100644 --- a/Pipfile +++ b/Pipfile @@ -6,9 +6,10 @@ name = "pypi" [packages] [dev-packages] -homeassistant = ">= 2023.2.1" +homeassistant = ">= 2023.6.1" ipython = "*" ipdb = "*" +homeassistant-historical-sensor = {editable = true, path = "./../ha-historical-sensor"} [requires] python_version = "3" diff --git a/custom_components/ideenergy/datacoordinator.py b/custom_components/ideenergy/datacoordinator.py index 00ca348..00e640f 100644 --- a/custom_components/ideenergy/datacoordinator.py +++ b/custom_components/ideenergy/datacoordinator.py @@ -88,9 +88,6 @@ def __init__( self.platforms = [] # type: ignore[var-annotated] self.sensors = [] # type: ignore[var-annotated] - def utcnow(self): - return dt_util.utcnow() - def register_sensor(self, sensor: IDeEntity) -> None: self.sensors.append(sensor) _LOGGER.debug(f"Registered sensor {sensor.__class__}") diff --git a/custom_components/ideenergy/manifest.json b/custom_components/ideenergy/manifest.json index 143a426..f149dbe 100644 --- a/custom_components/ideenergy/manifest.json +++ b/custom_components/ideenergy/manifest.json @@ -10,7 +10,7 @@ "issue_tracker": "https://github.com/ldotlopez/ha-ideenergy/issues", "requirements": [ "ideenergy==1.0.0rc2", - "homeassistant-historical-sensor==0.0.4" + "homeassistant-historical-sensor==0.0.6" ], - "version": "1.99.0" + "version": "1.99.1" } diff --git a/custom_components/ideenergy/sensor.py b/custom_components/ideenergy/sensor.py index e57194f..6831cf9 100644 --- a/custom_components/ideenergy/sensor.py +++ b/custom_components/ideenergy/sensor.py @@ -29,7 +29,7 @@ import logging from datetime import timedelta -from typing import Dict, List, Optional +from typing import Dict, List, Optional, Union from homeassistant.components.recorder.models import StatisticData, StatisticMetaData from homeassistant.components.sensor import ( @@ -49,7 +49,10 @@ from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.typing import DiscoveryInfoType from homeassistant.util import dt as dtutil -from homeassistant_historical_sensor import HistoricalSensor, HistoricalState +from homeassistant_historical_sensor import ( + HistoricalSensor, + HistoricalState, +) from .const import DOMAIN from .datacoordinator import ( @@ -92,16 +95,19 @@ def async_update_historical(self) -> None: pass -class StatisticsMixin: - def get_statatistics_metadata(self) -> StatisticMetaData: - meta = super().get_statatistics_metadata() +class StatisticsMixin(HistoricalSensor): + @property + def statatistic_id(self): + return self.entity_id + + def get_statatistic_metadata(self) -> StatisticMetaData: + meta = super().get_statatistic_metadata() meta["has_sum"] = True return meta async def async_calculate_statistic_data( self, hist_states: List[HistoricalState], *, latest: Optional[dict] - ) -> List[StatisticData]: - + ) -> Union[List[StatisticData]]: if latest: cutoff = dtutil.utc_from_timestamp(latest["end"]) accumulated = latest["sum"] or 0 diff --git a/hacs.json b/hacs.json index 0ceb398..21c7370 100644 --- a/hacs.json +++ b/hacs.json @@ -2,5 +2,5 @@ "name": "i-DE Energy Monitor", "render_readme": true, "content_in_root": false, - "homeassistant": "2023.2.0" + "homeassistant": "2023.6.0" }