@@ -36,8 +36,7 @@ class HouseholdMeasurements(Enum):
3636@dataclass (frozen = True , kw_only = True )
3737class PowersensorVirtualHouseholdSensorEntityDescription (SensorEntityDescription ):
3838 formatter : Callable
39- precision : int
40- event : str
39+ event : str
4140
4241FMT_INT = lambda f : int (f )
4342FMT_WS_TO_KWH = lambda f : float (f )/ 3600000
@@ -53,67 +52,67 @@ class PowersensorHouseholdEntity(SensorEntity):
5352 HouseholdMeasurements .POWER_HOME_USE : PowersensorVirtualHouseholdSensorEntityDescription (
5453 key = "Power - Home use" ,
5554 device_class = SensorDeviceClass .POWER ,
56- state_class = SensorStateClass .MEASUREMENT ,
5755 native_unit_of_measurement = UnitOfPower .WATT ,
56+ state_class = SensorStateClass .MEASUREMENT ,
57+ suggested_display_precision = 0 ,
5858 formatter = FMT_INT ,
59- precision = 0 ,
6059 event = "home_usage" ),
6160 HouseholdMeasurements .POWER_FROM_GRID : PowersensorVirtualHouseholdSensorEntityDescription (
6261 key = "Power - From grid" ,
6362 device_class = SensorDeviceClass .POWER ,
64- state_class = SensorStateClass .MEASUREMENT ,
6563 native_unit_of_measurement = UnitOfPower .WATT ,
64+ state_class = SensorStateClass .MEASUREMENT ,
65+ suggested_display_precision = 0 ,
6666 formatter = FMT_INT ,
67- precision = 0 ,
6867 event = "from_grid" ),
6968 HouseholdMeasurements .POWER_TO_GRID : PowersensorVirtualHouseholdSensorEntityDescription (
7069 key = "Power - To grid" ,
7170 device_class = SensorDeviceClass .POWER ,
72- state_class = SensorStateClass .MEASUREMENT ,
7371 native_unit_of_measurement = UnitOfPower .WATT ,
72+ state_class = SensorStateClass .MEASUREMENT ,
73+ suggested_display_precision = 0 ,
7474 formatter = FMT_INT ,
75- precision = 0 ,
7675 event = "to_grid" ),
7776 HouseholdMeasurements .POWER_SOLAR_GENERATION : PowersensorVirtualHouseholdSensorEntityDescription (
7877 key = "Power - Solar generation" ,
7978 device_class = SensorDeviceClass .POWER ,
80- state_class = SensorStateClass .MEASUREMENT ,
8179 native_unit_of_measurement = UnitOfPower .WATT ,
80+ state_class = SensorStateClass .MEASUREMENT ,
81+ suggested_display_precision = 0 ,
8282 formatter = FMT_INT ,
83- precision = 0 ,
8483 event = "solar_generation" ),
8584
8685 HouseholdMeasurements .ENERGY_HOME_USE : PowersensorVirtualHouseholdSensorEntityDescription (
8786 key = "Energy - Home usage" ,
8887 device_class = SensorDeviceClass .ENERGY ,
89- state_class = SensorStateClass .TOTAL_INCREASING ,
9088 native_unit_of_measurement = UnitOfEnergy .KILO_WATT_HOUR ,
89+ state_class = SensorStateClass .TOTAL_INCREASING ,
90+ suggested_display_precision = 3 ,
9191 formatter = FMT_WS_TO_KWH ,
92- precision = 3 ,
9392 event = "home_usage_summation" ),
9493 HouseholdMeasurements .ENERGY_FROM_GRID : PowersensorVirtualHouseholdSensorEntityDescription (
9594 key = "Energy - From grid" ,
9695 device_class = SensorDeviceClass .ENERGY ,
9796 state_class = SensorStateClass .TOTAL_INCREASING ,
9897 native_unit_of_measurement = UnitOfEnergy .KILO_WATT_HOUR ,
9998 formatter = FMT_WS_TO_KWH ,
100- precision = 3 ,
99+ suggested_display_precision = 3 ,
101100 event = "from_grid_summation" ),
102101 HouseholdMeasurements .ENERGY_TO_GRID : PowersensorVirtualHouseholdSensorEntityDescription (
103102 key = "Energy - To grid" ,
104103 device_class = SensorDeviceClass .ENERGY ,
105104 state_class = SensorStateClass .TOTAL_INCREASING ,
106105 native_unit_of_measurement = UnitOfEnergy .KILO_WATT_HOUR ,
107106 formatter = FMT_WS_TO_KWH ,
108- precision = 3 ,
107+ suggested_display_precision = 3 ,
109108 event = "to_grid_summation" ),
110109 HouseholdMeasurements .ENERGY_SOLAR_GENERATION : PowersensorVirtualHouseholdSensorEntityDescription (
111110 key = "Energy - Solar generation" ,
112111 device_class = SensorDeviceClass .ENERGY ,
113112 state_class = SensorStateClass .TOTAL_INCREASING ,
114113 native_unit_of_measurement = UnitOfEnergy .KILO_WATT_HOUR ,
115114 formatter = FMT_WS_TO_KWH ,
116- precision = 3 ,
115+ suggested_display_precision = 3 ,
117116 event = "solar_generation_summation" ),
118117 }
119118
@@ -124,10 +123,8 @@ def __init__(self, vhh: VirtualHousehold, measurement_type: HouseholdMeasurement
124123
125124 self ._attr_name = self ._config .key
126125 self ._attr_unique_id = f"{ DOMAIN } _vhh_{ self ._config .event } "
127- self ._attr_device_class = self ._config .device_class
128- self ._attr_state_class = self ._config .state_class
129- self ._attr_native_unit_of_measurement = self ._config .native_unit_of_measurement
130- self ._attr_suggested_display_precision = self ._config .precision
126+
127+ self .entity_description = self ._config
131128
132129 @property
133130 def device_info (self ) -> DeviceInfo :
0 commit comments