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
pull/37942/head
Abílio Costa 2020-07-17 15:04:04 +01:00 committed by GitHub
parent 24ed932b01
commit 8beaccf2dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -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()