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

@@ -38,11 +38,11 @@ class Energy(Module, ABC):
self._add_feature(
Feature(
device,
name="Current consumption",
attribute_getter="current_consumption",
name="Power",
attribute_getter="power",
container=self,
unit_getter=lambda: "W",
id="current_consumption",
id="power",
precision_hint=1,
category=Feature.Category.Primary,
type=Feature.Type.Sensor,
@@ -64,11 +64,11 @@ class Energy(Module, ABC):
self._add_feature(
Feature(
device,
id="consumption_this_month",
name="This month's consumption",
attribute_getter="consumption_this_month",
container=self,
unit_getter=lambda: "kWh",
id="consumption_this_month",
precision_hint=3,
category=Feature.Category.Info,
type=Feature.Type.Sensor,
@@ -123,8 +123,8 @@ class Energy(Module, ABC):
@property
@abstractmethod
def current_consumption(self) -> float | None:
"""Get the current power consumption in Watt."""
def power(self) -> float | None:
"""Get the current power draw in Watts."""
@property
@abstractmethod
@@ -182,6 +182,7 @@ class Energy(Module, ABC):
"erase_emeter_stats": "erase_stats",
"get_daystat": "get_daily_stats",
"get_monthstat": "get_monthly_stats",
"current_consumption": "power",
}
if not TYPE_CHECKING: