From 8beaccf2ddb5a6e67619738996b86420b7ba831e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ab=C3=ADlio=20Costa?= Date: Fri, 17 Jul 2020 15:04:04 +0100 Subject: [PATCH] Change ZHA power unit from kW to W (#37896) * Change ZHA power unit from kW to W * Use POWER_WATT * Move kW to W conversion; ignore unit for power --- .../components/zha/core/channels/smartenergy.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/zha/core/channels/smartenergy.py b/homeassistant/components/zha/core/channels/smartenergy.py index 7b12411b84f..9138ea09782 100644 --- a/homeassistant/components/zha/core/channels/smartenergy.py +++ b/homeassistant/components/zha/core/channels/smartenergy.py @@ -3,7 +3,7 @@ import logging import zigpy.zcl.clusters.smartenergy as smartenergy -from homeassistant.const import LENGTH_FEET, TIME_HOURS, TIME_SECONDS +from homeassistant.const import LENGTH_FEET, POWER_WATT, TIME_HOURS, TIME_SECONDS from homeassistant.core import callback from .. import registries, typing as zha_typing @@ -60,7 +60,7 @@ class Metering(ZigbeeChannel): REPORT_CONFIG = [{"attr": "instantaneous_demand", "config": REPORT_CONFIG_DEFAULT}] unit_of_measure_map = { - 0x00: "kW", + 0x00: POWER_WATT, 0x01: f"m³/{TIME_HOURS}", 0x02: f"{LENGTH_FEET}³/{TIME_HOURS}", 0x03: f"ccf/{TIME_HOURS}", @@ -135,6 +135,12 @@ class Metering(ZigbeeChannel): def formatter_function(self, value): """Return formatted value for display.""" + if self.unit_of_measurement == POWER_WATT: + # Zigbee spec power unit is kW, but we show the value in W + value_watt = value * 1000 + if value_watt < 100: + return round(value_watt, 1) + return round(value_watt) return self._format_spec.format(value).lstrip()