Rename current_consumption to power

- Note: This is a breaking change.
- Fix: Rename `current_consumption` to `power` in energy modules, to deconflict and clarify.
- Fix: Report `0` instead of `None` for current when current is zero.
- Fix: Report `0` instead of `None` for voltage when voltage is zero (not that this was possible to see).
This commit is contained in:
Ryan Nitcher
2024-12-06 20:48:16 -07:00
parent cb89342be1
commit 1c250913b6
8 changed files with 22 additions and 21 deletions

View File

@@ -34,8 +34,8 @@ class Energy(SmartModule, EnergyInterface):
@property
@raise_if_update_error
def current_consumption(self) -> float | None:
"""Current power in watts."""
def power(self) -> float | None:
"""Current power draw in Watts."""
if (power := self.energy.get("current_power")) is not None or (
power := self.data.get("get_emeter_data", {}).get("power_mw")
) is not None:
@@ -105,14 +105,14 @@ class Energy(SmartModule, EnergyInterface):
def current(self) -> float | None:
"""Return the current in A."""
ma = self.data.get("get_emeter_data", {}).get("current_ma")
return ma / 1000 if ma else None
return ma / 1000 if ma is not None else None
@property
@raise_if_update_error
def voltage(self) -> float | None:
"""Get the current voltage in V."""
mv = self.data.get("get_emeter_data", {}).get("voltage_mv")
return mv / 1000 if mv else None
return mv / 1000 if mv is not None else None
async def _deprecated_get_realtime(self) -> EmeterStatus:
"""Retrieve current energy readings."""