1414 SensorStateClass ,
1515)
1616from homeassistant .config_entries import ConfigEntry
17-
1817from homeassistant .const import (
1918 ATTR_UNIT_OF_MEASUREMENT ,
2019 UnitOfElectricCurrent ,
3231from homeassistant .helpers .entity_platform import AddEntitiesCallback
3332from homeassistant .util import dt as dt_util
3433
35-
3634from .const import (
3735 ATTR_SUMMATION_FACTOR ,
3836 ATTR_SUMMATION_PERIOD ,
@@ -323,7 +321,7 @@ def handle_ecu_registration(data: dict[str, Any]):
323321 data = data .get (sensor .parameter ), attributes = initial_attribute_values
324322 ),
325323 )
326- sensors .append (APSystemsSensor (sensor , config ))
324+ sensors .append (APSystemsSensor (sensor , config , config_entry ))
327325 add_entities (sensors )
328326
329327 @callback
@@ -367,7 +365,7 @@ def handle_inverter_registration(data: dict[str, Any]):
367365 data = data .get (sensor .parameter ), attributes = initial_attribute_values
368366 ),
369367 )
370- sensors .append (APSystemsSensor (sensor , config ))
368+ sensors .append (APSystemsSensor (sensor , config , config_entry ))
371369
372370 # Add Inverter channel sensors
373371 for channel in range (data .get ("channel_qty" , 0 )):
@@ -388,7 +386,7 @@ def handle_inverter_registration(data: dict[str, Any]):
388386 ),
389387 name = f"{ sensor .name } Ch { channel + 1 } " ,
390388 )
391- sensors .append (APSystemsSensor (sensor , config ))
389+ sensors .append (APSystemsSensor (sensor , config , config_entry ))
392390
393391 add_entities (sensors )
394392
@@ -419,10 +417,10 @@ class APSystemsSensor(RestoreSensor, SensorEntity):
419417 _attr_extra_state_attributes = {}
420418
421419 def __init__ (
422- self ,
423- definition : APSystemSensorDefinition ,
420+ self ,
421+ definition : APSystemSensorDefinition ,
424422 config : APSystemSensorConfig ,
425- config_entry : ConfigEntry # Accept ConfigEntry to get dynamic config values
423+ config_entry : ConfigEntry , # Accept ConfigEntry to get dynamic config values
426424 ) -> None :
427425 """Initialise sensor."""
428426 self ._definition = definition
@@ -437,6 +435,8 @@ def __init__(
437435 self ._attr_state_class = definition .state_class
438436 self ._attr_unique_id = self ._config .unique_id
439437
438+ self .max_stub_interval = int (self .config_entry .data .get ("max_stub_interval" ))
439+
440440 @property
441441 def is_summation_sensor (self ) -> bool :
442442 """Is this a summation sensor."""
@@ -646,8 +646,8 @@ def summation_calculation(
646646 current_value : float ,
647647 value : float ,
648648 ) -> int | float :
649-
650649 """Return summation value of value over time.
650+
651651 If change in period, calculates a value over time from start of new period with
652652 max of MAX_STUB_INTERVAL.
653653 If no change in period, assumes value persisted since last timestamp.
@@ -669,12 +669,9 @@ def summation_calculation(
669669
670670 sum_value = None
671671 has_changed = False
672-
672+
673673 # Get configuration. If initial data else options.
674- self .max_stub_interval = int (
675- self .config_entry .options .get ('max_stub_interval' ,
676- self .config_entry .data .get ('max_stub_interval' ))
677- )
674+
678675 _LOGGER .debug ("Max stub interval = %s" , self .max_stub_interval )
679676
680677 # Has it crossed calculation period boundry?
0 commit comments