8
8
UnitOfTemperature , UnitOfFrequency
9
9
10
10
11
+ def round_if_numeric (value : Any , decimals : int ):
12
+ if type (value ) in (int , float ):
13
+ return round (value , decimals )
14
+ else :
15
+ return value
16
+
17
+
11
18
@dataclass (frozen = True )
12
19
class FoxEssEntityDescription (SensorEntityDescription ):
13
20
variable : str | None = None
14
21
state : Callable [[defaultdict ], Any ] | None = None
22
+ process : Callable [[Any ], Any ] | None = lambda value : round_if_numeric (value , 3 )
15
23
realtime : bool = True
16
24
17
25
@@ -24,6 +32,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
24
32
device_class = SensorDeviceClass .TIMESTAMP ,
25
33
variable = "" ,
26
34
state = lambda data : data ["last_update" ],
35
+ process = None
27
36
),
28
37
FoxEssEntityDescription (
29
38
key = "pv_power" ,
@@ -535,6 +544,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
535
544
native_unit_of_measurement = UnitOfTemperature .CELSIUS ,
536
545
variable = "batTemperature" ,
537
546
state = lambda data : data ["realtime" ]["batTemperature" ],
547
+ process = lambda value : round_if_numeric (value , 1 ),
538
548
),
539
549
FoxEssEntityDescription (
540
550
key = "ambient_temperature" ,
@@ -545,6 +555,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
545
555
native_unit_of_measurement = UnitOfTemperature .CELSIUS ,
546
556
variable = "ambientTemperation" ,
547
557
state = lambda data : data ["realtime" ]["ambientTemperation" ],
558
+ process = lambda value : round_if_numeric (value , 1 ),
548
559
),
549
560
FoxEssEntityDescription (
550
561
key = "inv_temperature" ,
@@ -555,6 +566,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
555
566
native_unit_of_measurement = UnitOfTemperature .CELSIUS ,
556
567
variable = "invTemperation" ,
557
568
state = lambda data : data ["realtime" ]["invTemperation" ],
569
+ process = lambda value : round_if_numeric (value , 1 ),
558
570
),
559
571
FoxEssEntityDescription (
560
572
key = "boost_temperature" ,
@@ -565,6 +577,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
565
577
native_unit_of_measurement = UnitOfTemperature .CELSIUS ,
566
578
variable = "boostTemperation" ,
567
579
state = lambda data : data ["realtime" ]["boostTemperation" ],
580
+ process = lambda value : round_if_numeric (value , 1 ),
568
581
),
569
582
FoxEssEntityDescription (
570
583
key = "charge_temperature" ,
@@ -575,6 +588,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
575
588
native_unit_of_measurement = UnitOfTemperature .CELSIUS ,
576
589
variable = "chargeTemperature" ,
577
590
state = lambda data : data ["realtime" ]["chargeTemperature" ],
591
+ process = lambda value : round_if_numeric (value , 1 ),
578
592
),
579
593
FoxEssEntityDescription (
580
594
key = "dsp_temperature" ,
@@ -585,6 +599,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
585
599
native_unit_of_measurement = UnitOfTemperature .CELSIUS ,
586
600
variable = "dspTemperature" ,
587
601
state = lambda data : data ["realtime" ]["dspTemperature" ],
602
+ process = lambda value : round_if_numeric (value , 1 ),
588
603
),
589
604
# end of temperatures
590
605
@@ -598,6 +613,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
598
613
native_unit_of_measurement = UnitOfFrequency .HERTZ ,
599
614
variable = "RFreq" ,
600
615
state = lambda data : data ["realtime" ]["RFreq" ],
616
+ process = lambda value : round_if_numeric (value , 1 ),
601
617
),
602
618
FoxEssEntityDescription (
603
619
key = "s_frequency" ,
@@ -608,6 +624,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
608
624
native_unit_of_measurement = UnitOfFrequency .HERTZ ,
609
625
variable = "SFreq" ,
610
626
state = lambda data : data ["realtime" ]["SFreq" ],
627
+ process = lambda value : round_if_numeric (value , 1 ),
611
628
),
612
629
FoxEssEntityDescription (
613
630
key = "t_frequency" ,
@@ -618,6 +635,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
618
635
native_unit_of_measurement = UnitOfFrequency .HERTZ ,
619
636
variable = "TFreq" ,
620
637
state = lambda data : data ["realtime" ]["TFreq" ],
638
+ process = lambda value : round_if_numeric (value , 1 ),
621
639
),
622
640
# end of frequencies
623
641
@@ -683,6 +701,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
683
701
native_unit_of_measurement = PERCENTAGE ,
684
702
variable = "SoC" ,
685
703
state = lambda data : data ["realtime" ]["SoC" ],
704
+ process = lambda value : round_if_numeric (value , 0 ),
686
705
),
687
706
FoxEssEntityDescription (
688
707
key = "residual_energy" ,
@@ -732,7 +751,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
732
751
),
733
752
FoxEssEntityDescription (
734
753
key = "charged_energy_total" ,
735
- name = "Charged Energy Total" ,
754
+ name = "Daily Charged Energy Total" ,
736
755
icon = "mdi:battery-plus-outline" ,
737
756
device_class = SensorDeviceClass .ENERGY ,
738
757
state_class = SensorStateClass .TOTAL_INCREASING ,
@@ -743,7 +762,7 @@ class FoxEssEntityDescription(SensorEntityDescription):
743
762
),
744
763
FoxEssEntityDescription (
745
764
key = "discharged_energy_total" ,
746
- name = "Discharged Energy Total" ,
765
+ name = "Daily Discharged Energy Total" ,
747
766
icon = "mdi:battery-minus-outline" ,
748
767
device_class = SensorDeviceClass .ENERGY ,
749
768
state_class = SensorStateClass .TOTAL_INCREASING ,
0 commit comments