@@ -48,18 +48,28 @@ async def async_setup_entry(
48
48
49
49
add_entities (
50
50
[
51
+ #power
51
52
BatteryStatus (coordinator ),
52
53
HouseConsumption (coordinator ),
53
54
BatteryPower (coordinator ),
54
55
SolarProduction (coordinator ),
55
56
GridPower (coordinator ),
57
+ #power direction
56
58
GridToHouse (coordinator ),
57
59
SolarToBattery (coordinator ),
58
60
SolarToGrid (coordinator ),
59
61
BatteryToHouse (coordinator ),
60
62
SolarToHouse (coordinator ),
61
63
GridToBattery (coordinator ),
62
64
BatteryToGrid (coordinator ),
65
+ #energy
66
+ SoldEnergy (coordinator ),
67
+ SolarEnergy (coordinator ),
68
+ SelfConsumedEnergy (coordinator ),
69
+ BoughtEnergy (coordinator ),
70
+ ConsumedEnergy (coordinator ),
71
+ #other
72
+ SelfSufficiency (coordinator ),
63
73
]
64
74
)
65
75
@@ -312,3 +322,114 @@ def __init__(self, coordinator: ApiCoordinator) -> None:
312
322
@property
313
323
def is_on (self ) -> bool :
314
324
return self .coordinator .api .status .battery_to_grid
325
+
326
+
327
+ class BaseEnergySensor (SensorEntity , CoordinatorEntity ):
328
+ """Representation of a Sensor."""
329
+
330
+ @property
331
+ def device_info (self ) -> DeviceInfo | None :
332
+ return {
333
+ "identifiers" : {(DOMAIN , "aton_storage_" + self .coordinator .api .username )}
334
+ }
335
+
336
+ def __init__ (self , coordinator : ApiCoordinator ) -> None :
337
+ super ().__init__ (coordinator )
338
+ self ._attr_native_unit_of_measurement = ENERGY_WATT_HOUR
339
+ self ._attr_device_class = SensorDeviceClass .ENERGY
340
+ self ._attr_state_class = SensorStateClass .MEASUREMENT
341
+
342
+ def update (self ) -> None :
343
+ """update"""
344
+
345
+ @callback
346
+ def _handle_coordinator_update (self ) -> None :
347
+ """Handle updated data from the coordinator."""
348
+ self .update ()
349
+ self .async_write_ha_state ()
350
+
351
+
352
+ class SoldEnergy (BaseEnergySensor ):
353
+ """Representation of a Sensor"""
354
+
355
+ def __init__ (self ,coordinator : ApiCoordinator ) -> None :
356
+ super ().__init__ (coordinator )
357
+ self ._attr_name = "Energia Venduta"
358
+ self ._attr_unique_id = "aton_sold_energy_" + coordinator .api .username
359
+
360
+ def update (self ) -> None :
361
+ self ._attr_native_value = self .coordinator .api .sold_energy
362
+
363
+
364
+ class SolarEnergy (BaseEnergySensor ):
365
+ """Representation of a Sensor"""
366
+
367
+ def __init__ (self ,coordinator : ApiCoordinator ) -> None :
368
+ super ().__init__ (coordinator )
369
+ self ._attr_name = "Energia Solare"
370
+ self ._attr_unique_id = "aton_solar_energy_" + coordinator .api .username
371
+
372
+ def update (self ) -> None :
373
+ self ._attr_native_value = self .coordinator .api .solar_energy
374
+
375
+
376
+ class SelfConsumedEnergy (BaseEnergySensor ):
377
+ """Representation of a Sensor"""
378
+
379
+ def __init__ (self ,coordinator : ApiCoordinator ) -> None :
380
+ super ().__init__ (coordinator )
381
+ self ._attr_name = "Energia Auto Consumata"
382
+ self ._attr_unique_id = "aton_self_energy_" + coordinator .api .username
383
+
384
+ def update (self ) -> None :
385
+ self ._attr_native_value = self .coordinator .api .self_consumed_energy
386
+
387
+
388
+ class BoughtEnergy (BaseEnergySensor ):
389
+ """Representation of a Sensor"""
390
+
391
+ def __init__ (self ,coordinator : ApiCoordinator ) -> None :
392
+ super ().__init__ (coordinator )
393
+ self ._attr_name = "Energia Comprata"
394
+ self ._attr_unique_id = "aton_bought_energy_" + coordinator .api .username
395
+
396
+ def update (self ) -> None :
397
+ self ._attr_native_value = self .coordinator .api .bought_energy
398
+
399
+
400
+ class ConsumedEnergy (BaseEnergySensor ):
401
+ """Representation of a Sensor"""
402
+
403
+ def __init__ (self ,coordinator : ApiCoordinator ) -> None :
404
+ super ().__init__ (coordinator )
405
+ self ._attr_name = "Energia Consumata"
406
+ self ._attr_unique_id = "aton_consumed_energy_" + coordinator .api .username
407
+
408
+ def update (self ) -> None :
409
+ self ._attr_native_value = self .coordinator .api .consumed_energy
410
+
411
+ class SelfSufficiency (SensorEntity , CoordinatorEntity ):
412
+ """Representation of a Sensor."""
413
+
414
+ @property
415
+ def device_info (self ) -> DeviceInfo | None :
416
+ return {
417
+ "identifiers" : {
418
+ (DOMAIN , "aton_storage_" + self .coordinator .api .username )
419
+ },
420
+ }
421
+
422
+ def __init__ (self , coordinator : ApiCoordinator ) -> None :
423
+ super ().__init__ (coordinator )
424
+ self ._attr_name = "Autosufficienza"
425
+ self ._attr_native_unit_of_measurement = PERCENTAGE
426
+ self ._attr_device_class = SensorDeviceClass .POWER_FACTOR
427
+ self ._attr_state_class = SensorStateClass .MEASUREMENT
428
+ self ._attr_unique_id = "aton_self_sufficiency_" + coordinator .api .username
429
+
430
+ @callback
431
+ def _handle_coordinator_update (self ) -> None :
432
+ """Handle updated data from the coordinator."""
433
+ self ._attr_native_value = self .coordinator .api .status .self_sufficiency
434
+ self .async_write_ha_state ()
435
+
0 commit comments