Skip to content

Commit 7d152ae

Browse files
authored
Merge pull request #877 from canton7/bugfix/ha-2025.8
Support 2025.8's IntegrationSensor adding a 'hass' parameter
2 parents ce84f8e + 1a7ca8f commit 7d152ae

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

custom_components/foxess_modbus/entities/modbus_integration_sensor.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Sensor"""
22

3+
import inspect
34
import logging
45
from dataclasses import dataclass
56
from datetime import timedelta
@@ -12,6 +13,7 @@
1213
from homeassistant.components.sensor import SensorEntityDescription
1314
from homeassistant.const import Platform
1415
from homeassistant.const import UnitOfTime
16+
from homeassistant.core import HomeAssistant
1517
from homeassistant.helpers.entity import Entity
1618

1719
from ..common.entity_controller import EntityController
@@ -55,6 +57,7 @@ def create_entity_if_supported(
5557

5658
# this piggybacks on the existing factory to create IntegrationSensors
5759
return ModbusIntegrationSensor(
60+
hass=controller.hass,
5861
controller=controller,
5962
entity_description=self,
6063
integration_method=self.integration_method,
@@ -83,6 +86,7 @@ class ModbusIntegrationSensor(ModbusEntityMixin, IntegrationSensor):
8386

8487
def __init__(
8588
self,
89+
hass: HomeAssistant,
8690
controller: EntityController,
8791
entity_description: ModbusIntegrationSensorDescription,
8892
integration_method: str,
@@ -99,17 +103,23 @@ def __init__(
99103
self.entity_description = entity_description
100104
self.entity_id = self._get_entity_id(Platform.SENSOR)
101105

102-
IntegrationSensor.__init__(
103-
self=self,
104-
integration_method=integration_method,
105-
name=cast(str, entity_description.name),
106-
round_digits=round_digits,
107-
source_entity=source_entity,
108-
unique_id=None,
109-
unit_prefix=None,
110-
unit_time=unit_time,
111-
max_sub_interval=MAX_SUB_INTERVAL,
112-
)
106+
# HA 2025.8 added 'hass' as a parameter
107+
signature = inspect.signature(IntegrationSensor.__init__)
108+
positional: list[Any] = [self]
109+
if "hass" in signature.parameters:
110+
positional.append(hass)
111+
kwargs = {
112+
"integration_method": integration_method,
113+
"name": cast(str, entity_description.name),
114+
"round_digits": round_digits,
115+
"source_entity": source_entity,
116+
"unique_id": None,
117+
"unit_prefix": None,
118+
"unit_time": unit_time,
119+
"max_sub_interval": MAX_SUB_INTERVAL,
120+
}
121+
122+
IntegrationSensor.__init__(*positional, **kwargs) # type: ignore[arg-type]
113123

114124
# Use the icon from entity_description
115125
delattr(self, "_attr_icon")

0 commit comments

Comments
 (0)