@@ -96,7 +96,9 @@ async def async_setup_platform(
9696
9797 await async_setup_reload_service (hass , DOMAIN , PLATFORMS )
9898
99- async_add_entities ([PeriodicMinMaxSensor (hass , entity_id , name , sensor_type , unique_id )])
99+ async_add_entities (
100+ [PeriodicMinMaxSensor (hass , entity_id , name , sensor_type , unique_id )]
101+ )
100102
101103
102104class PeriodicMinMaxSensor (SensorEntity , RestoreEntity ):
@@ -136,13 +138,14 @@ def __init__(
136138 self .max_value : float | None = None
137139 self ._state : Any = None
138140
139-
140141 async def async_added_to_hass (self ) -> None :
141142 """Handle added to Hass."""
142143
143144 self .async_on_remove (
144145 async_track_state_change_event (
145- self .hass , self ._source_entity_id , self ._async_min_max_sensor_state_listener
146+ self .hass ,
147+ self ._source_entity_id ,
148+ self ._async_min_max_sensor_state_listener ,
146149 )
147150 )
148151
@@ -158,18 +161,34 @@ async def async_added_to_hass(self) -> None:
158161
159162 if entry :
160163 self ._unit_of_measurement = entry .unit_of_measurement
161- self ._attr_device_class = SensorDeviceClass (entry .device_class ) if entry .device_class else None
162- self ._attr_icon = entry .icon if entry .icon else entry .original_icon if entry .original_icon else ICON
164+ self ._attr_device_class = (
165+ SensorDeviceClass (entry .device_class ) if entry .device_class else None
166+ )
167+ self ._attr_icon = (
168+ entry .icon
169+ if entry .icon
170+ else entry .original_icon
171+ if entry .original_icon
172+ else ICON
173+ )
163174
164175 state = await self .async_get_last_state ()
165- if state is not None and state .state not in [STATE_UNKNOWN , STATE_UNAVAILABLE ]:
176+ if state is not None and state .state not in [
177+ STATE_UNKNOWN ,
178+ STATE_UNAVAILABLE ,
179+ ]:
166180 self ._state = float (state .state )
167181 self ._calc_values ()
168182
169183 # Replay current state of source entitiy
170184 state = self .hass .states .get (self ._source_entity_id )
171185 state_event : Event [EventStateChangedData ] = Event (
172- "" , {"entity_id" : self ._source_entity_id , "new_state" : state , "old_state" : None }
186+ "" ,
187+ {
188+ "entity_id" : self ._source_entity_id ,
189+ "new_state" : state ,
190+ "old_state" : None ,
191+ },
173192 )
174193 self ._async_min_max_sensor_state_listener (state_event , update_state = False )
175194
@@ -259,4 +278,4 @@ async def handle_reset(self) -> None:
259278 self .min_value = self ._state
260279 self .max_value = self ._state
261280
262- self .async_write_ha_state ()
281+ self .async_write_ha_state ()
0 commit comments