Skip to content

Commit

Permalink
Remove HA version-specific workaround for IntegrationSensor
Browse files Browse the repository at this point in the history
  • Loading branch information
canton7 committed Jan 4, 2025
1 parent 5c3aca4 commit a6c8de5
Showing 1 changed file with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Sensor"""

import inspect
import logging
from dataclasses import dataclass
from datetime import timedelta
Expand All @@ -26,18 +25,7 @@

_LOGGER = logging.getLogger(__name__)


def _make_integration_sensor_kwargs() -> dict[str, Any]:
# HA 2024.7 introduced a new non-optional max_sub_interval parameter
kwargs: dict[str, Any] = {}
args = inspect.signature(IntegrationSensor.__init__)
if "max_sub_interval" in args.parameters:
kwargs["max_sub_interval"] = timedelta(minutes=1) # Default used by integration sensor config

return kwargs


_INTEGRATION_SENSOR_KWARGS = _make_integration_sensor_kwargs()
MAX_SUB_INTERVAL = timedelta(minutes=1) # Default used by integration sensor config


@dataclass(kw_only=True, **ENTITY_DESCRIPTION_KWARGS)
Expand Down Expand Up @@ -121,7 +109,7 @@ def __init__(
unique_id=None,
unit_prefix=None,
unit_time=unit_time,
**_INTEGRATION_SENSOR_KWARGS,
max_sub_interval=MAX_SUB_INTERVAL,
)

# Use the icon from entity_description
Expand Down

0 comments on commit a6c8de5

Please sign in to comment.