| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5cd8d30 commit 33e35b1
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ | |||
| 18 | 18 | requires_update, | |
| 19 | 19 | ) | |
| 20 | 20 | from .iotplug import IotPlug | |
| 21 | - from .modules import Antitheft, Countdown, Emeter, Schedule, Time, Usage | ||
| 21 | + from .modules import Antitheft, Countdown, Schedule, Time, Usage | ||
| 22 | 22 | ||
| 23 | 23 | _LOGGER = logging.getLogger(__name__) | |
| 24 | 24 | ||
@@ -100,7 +100,6 @@ def __init__( | |||
| 100 | 100 | self.add_module("usage", Usage(self, "schedule")) | |
| 101 | 101 | self.add_module("time", Time(self, "time")) | |
| 102 | 102 | self.add_module("countdown", Countdown(self, "countdown")) | |
| 103 | - self.add_module("emeter", Emeter(self, "emeter")) | ||
| 104 | 103 | ||
| 105 | 104 | @property # type: ignore | |
| 106 | 105 | @requires_update | |
@@ -217,13 +216,13 @@ async def erase_emeter_stats(self): | |||
| 217 | 216 | @requires_update | |
| 218 | 217 | def emeter_this_month(self) -> float | None: | |
| 219 | 218 | """Return this month's energy consumption in kWh.""" | |
| 220 | - return sum(plug.emeter_this_month for plug in self.children) | ||
| 219 | + return sum(v if (v := plug.emeter_this_month) else 0 for plug in self.children) | ||
| 221 | 220 | ||
| 222 | 221 | @property # type: ignore | |
| 223 | 222 | @requires_update | |
| 224 | 223 | def emeter_today(self) -> float | None: | |
| 225 | 224 | """Return this month's energy consumption in kWh.""" | |
| 226 | - return sum(plug.emeter_today for plug in self.children) | ||
| 225 | + return sum(v if (v := plug.emeter_today) else 0 for plug in self.children) | ||
| 227 | 226 | ||
| 228 | 227 | @property # type: ignore | |
| 229 | 228 | @requires_update | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,13 +4,77 @@ | |||
| 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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments