| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -614,12 +614,8 @@ async def state(ctx, dev: Device): | |||
| 614 | 614 | ||
| 615 | 615 | echo("\n\t[bold]== Device-specific information == [/bold]") | |
| 616 | 616 | for id_, feature in dev.features.items(): | |
| 617 | - echo(f"\t{feature.name} ({id_}): {feature.value}") | ||
| 618 | - | ||
| 619 | - if dev.has_emeter: | ||
| 620 | - echo("\n\t[bold]== Current State ==[/bold]") | ||
| 621 | - emeter_status = dev.emeter_realtime | ||
| 622 | - echo(f"\t{emeter_status}") | ||
| 617 | + unit = f" {feature.unit}" if feature.unit else "" | ||
| 618 | + echo(f"\t{feature.name} ({id_}): {feature.value}{unit}") | ||
| 623 | 619 | ||
| 624 | 620 | echo("\n\t[bold]== Modules ==[/bold]") | |
| 625 | 621 | for module in dev.modules.values(): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,8 @@ class Feature: | |||
| 36 | 36 | container: Any = None | |
| 37 | 37 | #: Icon suggestion | |
| 38 | 38 | icon: str | None = None | |
| 39 | + #: Unit, if applicable | ||
| 40 | + unit: Optional[str] = None | ||
| 39 | 41 | #: Type of the feature | |
| 40 | 42 | type: FeatureType = FeatureType.Sensor | |
| 41 | 43 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | 5 | from typing import TYPE_CHECKING | |
| 6 | 6 | ||
| 7 | - from ...emeterstatus import EmeterStatus | ||
| 8 | 7 | from ...feature import Feature | |
| 9 | 8 | from ..smartmodule import SmartModule | |
| 10 | 9 | ||
@@ -25,24 +24,27 @@ def __init__(self, device: SmartDevice, module: str): | |||
| 25 | 24 | name="Current consumption", | |
| 26 | 25 | attribute_getter="current_power", | |
| 27 | 26 | container=self, | |
| 27 | + unit="W", | ||
| 28 | 28 | ) | |
| 29 | - ) # W or mW? | ||
| 29 | + ) | ||
| 30 | 30 | self._add_feature( | |
| 31 | 31 | Feature( | |
| 32 | 32 | device, | |
| 33 | 33 | name="Today's consumption", | |
| 34 | 34 | attribute_getter="emeter_today", | |
| 35 | 35 | container=self, | |
| 36 | + unit="Wh", | ||
| 36 | 37 | ) | |
| 37 | - ) # Wh or kWh? | ||
| 38 | + ) | ||
| 38 | 39 | self._add_feature( | |
| 39 | 40 | Feature( | |
| 40 | 41 | device, | |
| 41 | 42 | name="This month's consumption", | |
| 42 | 43 | attribute_getter="emeter_this_month", | |
| 43 | 44 | container=self, | |
| 45 | + unit="Wh", | ||
| 44 | 46 | ) | |
| 45 | - ) # Wh or kWH? | ||
| 47 | + ) | ||
| 46 | 48 | ||
| 47 | 49 | def query(self) -> dict: | |
| 48 | 50 | """Query to execute during the update cycle.""" | |
@@ -54,9 +56,11 @@ def query(self) -> dict: | |||
| 54 | 56 | return req | |
| 55 | 57 | ||
| 56 | 58 | @property | |
| 57 | - def current_power(self): | ||
| 58 | - """Current power.""" | ||
| 59 | - return self.emeter_realtime.power | ||
| 59 | + def current_power(self) -> Optional[float]: | ||
| 60 | + """Current power in watts.""" | ||
| 61 | + if power := self.energy.get("current_power"): | ||
| 62 | + return power / 1_000 | ||
| 63 | + return None | ||
| 60 | 64 | ||
| 61 | 65 | @property | |
| 62 | 66 | def energy(self): | |
@@ -65,29 +69,12 @@ def energy(self): | |||
| 65 | 69 | return en | |
| 66 | 70 | return self.data | |
| 67 | 71 | ||
| 68 | - @property | ||
| 69 | - def emeter_realtime(self): | ||
| 70 | - """Get the emeter status.""" | ||
| 71 | - # TODO: Perhaps we should get rid of emeterstatus altogether for smartdevices | ||
| 72 | - return EmeterStatus( | ||
| 73 | - { | ||
| 74 | - "power_mw": self.energy.get("current_power"), | ||
| 75 | - "total": self._convert_energy_data( | ||
| 76 | - self.energy.get("today_energy"), 1 / 1000 | ||
| 77 | - ), | ||
| 78 | - } | ||
| 79 | - ) | ||
| 80 | - | ||
| 81 | 72 | @property | |
| 82 | 73 | def emeter_this_month(self) -> float | None: | |
| 83 | 74 | """Get the emeter value for this month.""" | |
| 84 | - return self._convert_energy_data(self.energy.get("month_energy"), 1 / 1000) | ||
| 75 | + return self.energy.get("month_energy") | ||
| 85 | 76 | ||
| 86 | 77 | @property | |
| 87 | 78 | def emeter_today(self) -> float | None: | |
| 88 | 79 | """Get the emeter value for today.""" | |
| 89 | - return self._convert_energy_data(self.energy.get("today_energy"), 1 / 1000) | ||
| 90 | - | ||
| 91 | - def _convert_energy_data(self, data, scale) -> float | None: | ||
| 92 | - """Return adjusted emeter information.""" | ||
| 93 | - return data if not data else data * scale | ||
| 80 | + return self.energy.get("today_energy") | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments