4
4
5
5
from datetime import datetime
6
6
7
+ from ... import Device
7
8
from ...emeterstatus import EmeterStatus
9
+ from ...feature import Feature
8
10
from .usage import Usage
9
11
10
12
11
13
class Emeter (Usage ):
12
14
"""Emeter module."""
13
15
16
+ def __init__ (self , device : Device , module : str ):
17
+ super ().__init__ (device , module )
18
+ self ._add_feature (
19
+ Feature (
20
+ device ,
21
+ name = "Current consumption" ,
22
+ attribute_getter = "current_consumption" ,
23
+ container = self ,
24
+ unit = "W" ,
25
+ id = "current_power_w" , # for homeassistant backwards compat
26
+ )
27
+ )
28
+ self ._add_feature (
29
+ Feature (
30
+ device ,
31
+ name = "Today's consumption" ,
32
+ attribute_getter = "emeter_today" ,
33
+ container = self ,
34
+ unit = "kWh" ,
35
+ id = "today_energy_kwh" , # for homeassistant backwards compat
36
+ )
37
+ )
38
+ self ._add_feature (
39
+ Feature (
40
+ device ,
41
+ name = "This month's consumption" ,
42
+ attribute_getter = "emeter_this_month" ,
43
+ container = self ,
44
+ unit = "kWh" ,
45
+ )
46
+ )
47
+ self ._add_feature (
48
+ Feature (
49
+ device ,
50
+ name = "Total consumption since reboot" ,
51
+ attribute_getter = "emeter_total" ,
52
+ container = self ,
53
+ unit = "kWh" ,
54
+ id = "total_energy_kwh" , # for homeassistant backwards compat
55
+ )
56
+ )
57
+ self ._add_feature (
58
+ Feature (
59
+ device ,
60
+ name = "Voltage" ,
61
+ attribute_getter = "voltage" ,
62
+ container = self ,
63
+ unit = "V" ,
64
+ id = "voltage" , # for homeassistant backwards compat
65
+ )
66
+ )
67
+ self ._add_feature (
68
+ Feature (
69
+ device ,
70
+ name = "Current" ,
71
+ attribute_getter = "current" ,
72
+ container = self ,
73
+ unit = "A" ,
74
+ id = "current_a" , # for homeassistant backwards compat
75
+ )
76
+ )
77
+
14
78
@property # type: ignore
15
79
def realtime (self ) -> EmeterStatus :
16
80
"""Return current energy readings."""
@@ -32,6 +96,26 @@ def emeter_this_month(self) -> float | None:
32
96
data = self ._convert_stat_data (raw_data , entry_key = "month" , key = current_month )
33
97
return data .get (current_month )
34
98
99
+ @property
100
+ def current_consumption (self ) -> float | None :
101
+ """Get the current power consumption in Watt."""
102
+ return self .realtime .power
103
+
104
+ @property
105
+ def emeter_total (self ) -> float | None :
106
+ """Return total consumption since last reboot in kWh."""
107
+ return self .realtime .total
108
+
109
+ @property
110
+ def current (self ) -> float | None :
111
+ """Return the current in A."""
112
+ return self .realtime .current
113
+
114
+ @property
115
+ def voltage (self ) -> float | None :
116
+ """Get the current voltage in V."""
117
+ return self .realtime .voltage
118
+
35
119
async def erase_stats (self ):
36
120
"""Erase all stats.
37
121
0 commit comments