11import logging
22from datetime import timedelta
33from homeassistant .const import UnitOfPower , UnitOfTemperature , PERCENTAGE , STATE_OFF
4+ from homeassistant .core import HomeAssistant
45from homeassistant .components .sensor import SensorDeviceClass , SensorEntity
56from homeassistant .components .integration .sensor import IntegrationSensor
67from homeassistant .components .binary_sensor import BinarySensorDeviceClass , BinarySensorEntity
@@ -29,11 +30,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
2930 new_entities .append (LowChargeSensor (coordinator , tank ))
3031 new_entities .append (NoChargeSensor (coordinator , tank ))
3132 new_entities .append (PowerSensor (coordinator , tank ))
32- new_entities .append (EnergySensor (tank ))
33+ new_entities .append (EnergySensor (hass , tank ))
3334 new_entities .append (TargetTemperatureSensor (coordinator , tank ))
3435 new_entities .append (HolidayModeSensor (coordinator , tank ))
3536 new_entities .append (PVPowerSensor (coordinator , tank ))
36- new_entities .append (PVEnergySensor (tank ))
37+ new_entities .append (PVEnergySensor (hass , tank ))
3738 new_entities .append (ClampPowerSensor (coordinator , tank ))
3839 new_entities .append (IsChargingSensor (coordinator , tank ))
3940 new_entities .append (HolidayStartDateSensor (coordinator , tank ))
@@ -174,6 +175,8 @@ def name(self):
174175
175176class IndirectHeatSensor (BinarySensorBase ):
176177
178+ device_class = BinarySensorDeviceClass .HEAT
179+
177180 def __init__ (self , coordinator , tank :Tank ):
178181 super ().__init__ ( coordinator , tank )
179182
@@ -195,6 +198,8 @@ def name(self):
195198
196199class ElectricHeatSensor (BinarySensorBase ):
197200
201+ device_class = SensorDeviceClass .ENERGY
202+
198203 def __init__ (self , coordinator , tank :Tank ):
199204 super ().__init__ ( coordinator , tank )
200205 self ._state = STATE_OFF
@@ -213,6 +218,8 @@ def name(self):
213218
214219class HeatPumpHeatSensor (BinarySensorBase ):
215220
221+ device_class = SensorDeviceClass .ENERGY
222+
216223 def __init__ (self , coordinator , tank :Tank ):
217224 super ().__init__ ( coordinator , tank )
218225 self ._state = STATE_OFF
@@ -322,8 +329,9 @@ def name(self):
322329
323330class EnergySensor (IntegrationSensor ):
324331
325- def __init__ (self , tank :Tank ):
332+ def __init__ (self , hass : HomeAssistant , tank :Tank ):
326333 super ().__init__ (
334+ hass = hass ,
327335 name = "Mixergy Electric Heat Energy" ,
328336 source_entity = "sensor.mixergy_electric_heat_power" ,
329337 round_digits = 2 ,
@@ -362,15 +370,16 @@ def unit_of_measurement(self):
362370 @property
363371 def name (self ):
364372 return f"Mixergy Electric PV Power"
365-
373+
366374 @property
367375 def available (self ):
368376 return super ().available and self ._tank .has_pv_diverter
369377
370378class PVEnergySensor (IntegrationSensor ):
371379
372- def __init__ (self , tank :Tank ):
380+ def __init__ (self , hass : HomeAssistant , tank :Tank ):
373381 super ().__init__ (
382+ hass = hass ,
374383 name = "Mixergy Electric PV Energy" ,
375384 source_entity = "sensor.mixergy_electric_pv_power" ,
376385 round_digits = 2 ,
@@ -414,7 +423,7 @@ def unit_of_measurement(self):
414423 @property
415424 def name (self ):
416425 return f"Clamp Power"
417-
426+
418427 @property
419428 def available (self ):
420429 return super ().available and self ._tank .has_pv_diverter
@@ -480,7 +489,7 @@ def state(self):
480489 @property
481490 def name (self ):
482491 return f"Holiday Date End"
483-
492+
484493class DefaultHeatSourceSensor (SensorBase ):
485494
486495 device_class = SensorDeviceClass .ENUM
0 commit comments