Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'current_summ_delivered' attrib for ZHA Smart energy channel #50471

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions homeassistant/components/zha/core/channels/smartenergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import zigpy.zcl.clusters.smartenergy as smartenergy

from homeassistant.const import (
ENERGY_KILO_WATT_HOUR,
POWER_WATT,
TIME_HOURS,
TIME_SECONDS,
Expand Down Expand Up @@ -63,10 +64,12 @@ class Messaging(ZigbeeChannel):
class Metering(ZigbeeChannel):
"""Metering channel."""

REPORT_CONFIG = [{"attr": "instantaneous_demand", "config": REPORT_CONFIG_DEFAULT}]
REPORT_CONFIG = [
{"attr": "current_summ_delivered", "config": REPORT_CONFIG_DEFAULT}
]

unit_of_measure_map = {
0x00: POWER_WATT,
0x00: ENERGY_KILO_WATT_HOUR,
0x01: VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR,
0x02: VOLUME_FLOW_RATE_CUBIC_FEET_PER_MINUTE,
0x03: f"ccf/{TIME_HOURS}",
Expand Down Expand Up @@ -122,16 +125,18 @@ def unit_of_measurement(self) -> str:
async def fetch_config(self, from_cache: bool) -> None:
"""Fetch config from device and updates format specifier."""
results = await self.get_attributes(
["divisor", "multiplier", "unit_of_measure", "demand_formatting"],
["divisor", "multiplier", "unit_of_measure", "summa_formatting"],
from_cache=from_cache,
)

fmting = results.get(
"demand_formatting", 0xF9
"summa_formatting", 0xF9
) # 1 digit to the right, 15 digits to the left

r_digits = int(fmting & 0x07) # digits to the right of decimal point
l_digits = (fmting >> 3) & 0x0F # digits to the left of decimal point
if r_digits == 0:
r_digits = 2
if l_digits == 0:
l_digits = 15
width = r_digits + l_digits + (1 if r_digits > 0 else 0)
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/zha/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_POWER,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
DOMAIN,
Expand Down Expand Up @@ -255,8 +256,8 @@ def formatter(value: int) -> float:
class SmartEnergyMetering(Sensor):
"""Metering sensor."""

SENSOR_ATTR = "instantaneous_demand"
_device_class = DEVICE_CLASS_POWER
SENSOR_ATTR = "current_summ_delivered"
_device_class = DEVICE_CLASS_ENERGY

def formatter(self, value: int) -> int | float:
"""Pass through channel formatter."""
Expand Down