mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
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
This commit is contained in:
parent
24ed932b01
commit
8beaccf2dd
@ -3,7 +3,7 @@ import logging
|
|||||||
|
|
||||||
import zigpy.zcl.clusters.smartenergy as smartenergy
|
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 homeassistant.core import callback
|
||||||
|
|
||||||
from .. import registries, typing as zha_typing
|
from .. import registries, typing as zha_typing
|
||||||
@ -60,7 +60,7 @@ class Metering(ZigbeeChannel):
|
|||||||
REPORT_CONFIG = [{"attr": "instantaneous_demand", "config": REPORT_CONFIG_DEFAULT}]
|
REPORT_CONFIG = [{"attr": "instantaneous_demand", "config": REPORT_CONFIG_DEFAULT}]
|
||||||
|
|
||||||
unit_of_measure_map = {
|
unit_of_measure_map = {
|
||||||
0x00: "kW",
|
0x00: POWER_WATT,
|
||||||
0x01: f"m³/{TIME_HOURS}",
|
0x01: f"m³/{TIME_HOURS}",
|
||||||
0x02: f"{LENGTH_FEET}³/{TIME_HOURS}",
|
0x02: f"{LENGTH_FEET}³/{TIME_HOURS}",
|
||||||
0x03: f"ccf/{TIME_HOURS}",
|
0x03: f"ccf/{TIME_HOURS}",
|
||||||
@ -135,6 +135,12 @@ class Metering(ZigbeeChannel):
|
|||||||
|
|
||||||
def formatter_function(self, value):
|
def formatter_function(self, value):
|
||||||
"""Return formatted value for display."""
|
"""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()
|
return self._format_spec.format(value).lstrip()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user