Skip to content

Commit

Permalink
Update for homeassistant historical sensor and hass >=2023.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lopezl committed Jun 16, 2023
1 parent bf136e0 commit 999796c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 0 additions & 3 deletions custom_components/ideenergy/datacoordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}")
Expand Down
4 changes: 2 additions & 2 deletions custom_components/ideenergy/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
20 changes: 13 additions & 7 deletions custom_components/ideenergy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "i-DE Energy Monitor",
"render_readme": true,
"content_in_root": false,
"homeassistant": "2023.2.0"
"homeassistant": "2023.6.0"
}

0 comments on commit 999796c

Please sign in to comment.