11"""Sensor"""
22
3+ import inspect
34import logging
45from dataclasses import dataclass
56from datetime import timedelta
1213from homeassistant .components .sensor import SensorEntityDescription
1314from homeassistant .const import Platform
1415from homeassistant .const import UnitOfTime
16+ from homeassistant .core import HomeAssistant
1517from homeassistant .helpers .entity import Entity
1618
1719from ..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