mirror of
				https://github.com/python-kasa/python-kasa.git
				synced 2025-10-31 04:31:54 +00:00 
			
		
		
		
	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:
		| @@ -85,7 +85,7 @@ state | ||||
| rssi | ||||
| on_since | ||||
| reboot | ||||
| current_consumption | ||||
| power | ||||
| consumption_today | ||||
| consumption_this_month | ||||
| consumption_total | ||||
| @@ -559,7 +559,7 @@ class Device(ABC): | ||||
|         "emeter_realtime": (Module.Energy, ["status"]), | ||||
|         "emeter_today": (Module.Energy, ["consumption_today"]), | ||||
|         "emeter_this_month": (Module.Energy, ["consumption_this_month"]), | ||||
|         "current_consumption": (Module.Energy, ["current_consumption"]), | ||||
|         "current_consumption": (Module.Energy, ["power"]), | ||||
|         "get_emeter_daily": (Module.Energy, ["get_daily_stats"]), | ||||
|         "get_emeter_monthly": (Module.Energy, ["get_monthly_stats"]), | ||||
|         # Other attributes | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
| @@ -195,10 +195,10 @@ class StripEmeter(IotModule, Energy): | ||||
|         return {} | ||||
|  | ||||
|     @property | ||||
|     def current_consumption(self) -> float | None: | ||||
|     def power(self) -> float | None: | ||||
|         """Get the current power consumption in watts.""" | ||||
|         return sum( | ||||
|             v if (v := plug.modules[Module.Energy].current_consumption) else 0.0 | ||||
|             v if (v := plug.modules[Module.Energy].power) else 0.0 | ||||
|             for plug in self._device.children | ||||
|         ) | ||||
|  | ||||
|   | ||||
| @@ -51,8 +51,8 @@ class Emeter(Usage, EnergyInterface): | ||||
|         return data.get(current_month, 0.0) | ||||
|  | ||||
|     @property | ||||
|     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.""" | ||||
|         return self.status.power | ||||
|  | ||||
|     @property | ||||
|   | ||||
| @@ -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.""" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Ryan Nitcher
					Ryan Nitcher