Skip to content

Commit

Permalink
Merge pull request #10 from isaacyera/fix/ha-2024.7
Browse files Browse the repository at this point in the history
HA2024.7: Fix Energy sensors
  • Loading branch information
vortizhe authored Jul 16, 2024
2 parents 4ca11eb + ac9d223 commit 51c60d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 2 additions & 4 deletions custom_components/ingeteam_modbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Register the hub."""
hass.data[DOMAIN][name] = {"hub": hub}

for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

return True


Expand Down
18 changes: 15 additions & 3 deletions custom_components/ingeteam_modbus/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from datetime import datetime, UTC, timedelta
from typing import Optional, Dict, Any
from decimal import Decimal
from .const import (
Expand Down Expand Up @@ -27,12 +28,13 @@
ATTR_SOURCE_ID,
UNIT_PREFIXES,
UNIT_TIME,
_IntegrationMethod
_IntegrationMethod,
_IntegrationTrigger
)

from homeassistant.components.integration.const import METHOD_TRAPEZOIDAL

from homeassistant.core import callback
from homeassistant.core import callback, CALLBACK_TYPE

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -203,7 +205,8 @@ def __init__(
integration_method = METHOD_TRAPEZOIDAL,
name: str | None,
source_entity: str,
unique_id: str | None):
unique_id: str | None,
max_sub_interval: timedelta | None = None,):
"""Initialize the integration sensor."""
unit_prefix = "k"
unit_time = "h"
Expand All @@ -213,6 +216,15 @@ def __init__(
self._state: Decimal | None = None
self._last_valid_state = Decimal | None
self._method = _IntegrationMethod.from_name(integration_method)
self._max_sub_interval: timedelta | None = (
None # disable time based integration
if max_sub_interval is None or max_sub_interval.total_seconds() == 0
else max_sub_interval
)
self._max_sub_interval_exceeded_callback: CALLBACK_TYPE = lambda *args: None
self._last_integration_time: datetime = datetime.now(tz=UTC)
self._last_integration_trigger = _IntegrationTrigger.StateEvent


self._attr_name = name if name is not None else f"{source_entity} integral"
self._unit_template = f"{'' if unit_prefix is None else unit_prefix}{{}}"
Expand Down

0 comments on commit 51c60d0

Please sign in to comment.