mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Cleanup ZHA metering and electrical measurement channels (#33992)
* clean up homeautomation and smartenergy channels * fix get attributes on base channel
This commit is contained in:
parent
328cadbaa2
commit
5ea4a68aae
@ -263,7 +263,11 @@ class ZigbeeChannel(LogMixin):
|
|||||||
only_cache=from_cache,
|
only_cache=from_cache,
|
||||||
manufacturer=manufacturer,
|
manufacturer=manufacturer,
|
||||||
)
|
)
|
||||||
results = {attribute: result.get(attribute) for attribute in attributes}
|
results = {
|
||||||
|
attribute: result.get(attribute)
|
||||||
|
for attribute in attributes
|
||||||
|
if result.get(attribute) is not None
|
||||||
|
}
|
||||||
except (asyncio.TimeoutError, zigpy.exceptions.DeliveryError) as ex:
|
except (asyncio.TimeoutError, zigpy.exceptions.DeliveryError) as ex:
|
||||||
self.debug(
|
self.debug(
|
||||||
"failed to get attributes '%s' on '%s' cluster: %s",
|
"failed to get attributes '%s' on '%s' cluster: %s",
|
||||||
|
@ -81,27 +81,19 @@ class ElectricalMeasurementChannel(ZigbeeChannel):
|
|||||||
|
|
||||||
async def fetch_config(self, from_cache):
|
async def fetch_config(self, from_cache):
|
||||||
"""Fetch config from device and updates format specifier."""
|
"""Fetch config from device and updates format specifier."""
|
||||||
divisor = await self.get_attribute_value(
|
results = await self.get_attributes(
|
||||||
"ac_power_divisor", from_cache=from_cache
|
[
|
||||||
|
"ac_power_divisor",
|
||||||
|
"power_divisor",
|
||||||
|
"ac_power_multiplier",
|
||||||
|
"power_multiplier",
|
||||||
|
],
|
||||||
|
from_cache=from_cache,
|
||||||
)
|
)
|
||||||
if divisor is None:
|
self._divisor = results.get("ac_power_divisor", results.get("power_divisor", 1))
|
||||||
divisor = await self.get_attribute_value(
|
self._multiplier = results.get(
|
||||||
"power_divisor", from_cache=from_cache
|
"ac_power_multiplier", results.get("power_multiplier", 1)
|
||||||
)
|
|
||||||
if divisor is None:
|
|
||||||
divisor = 1
|
|
||||||
self._divisor = divisor
|
|
||||||
|
|
||||||
mult = await self.get_attribute_value(
|
|
||||||
"ac_power_multiplier", from_cache=from_cache
|
|
||||||
)
|
)
|
||||||
if mult is None:
|
|
||||||
mult = await self.get_attribute_value(
|
|
||||||
"power_multiplier", from_cache=from_cache
|
|
||||||
)
|
|
||||||
if mult is None:
|
|
||||||
mult = 1
|
|
||||||
self._multiplier = mult
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def divisor(self) -> Optional[int]:
|
def divisor(self) -> Optional[int]:
|
||||||
|
@ -98,6 +98,8 @@ class Metering(ZigbeeChannel):
|
|||||||
@callback
|
@callback
|
||||||
def attribute_updated(self, attrid, value):
|
def attribute_updated(self, attrid, value):
|
||||||
"""Handle attribute update from Metering cluster."""
|
"""Handle attribute update from Metering cluster."""
|
||||||
|
if None in (self._multiplier, self._divisor, self._format_spec):
|
||||||
|
return
|
||||||
super().attribute_updated(attrid, value * self._multiplier / self._divisor)
|
super().attribute_updated(attrid, value * self._multiplier / self._divisor)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -107,25 +109,24 @@ class Metering(ZigbeeChannel):
|
|||||||
|
|
||||||
async def fetch_config(self, from_cache):
|
async def fetch_config(self, from_cache):
|
||||||
"""Fetch config from device and updates format specifier."""
|
"""Fetch config from device and updates format specifier."""
|
||||||
self._divisor = await self.get_attribute_value("divisor", from_cache=from_cache)
|
results = await self.get_attributes(
|
||||||
self._multiplier = await self.get_attribute_value(
|
["divisor", "multiplier", "unit_of_measure", "demand_formatting"],
|
||||||
"multiplier", from_cache=from_cache
|
from_cache=from_cache,
|
||||||
)
|
|
||||||
self._unit_enum = await self.get_attribute_value(
|
|
||||||
"unit_of_measure", from_cache=from_cache
|
|
||||||
)
|
|
||||||
fmting = await self.get_attribute_value(
|
|
||||||
"demand_formatting", from_cache=from_cache
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if self._divisor is None or self._divisor == 0:
|
self._divisor = results.get("divisor", 1)
|
||||||
|
if self._divisor == 0:
|
||||||
self._divisor = 1
|
self._divisor = 1
|
||||||
if self._multiplier is None or self._multiplier == 0:
|
|
||||||
|
self._multiplier = results.get("multiplier", 1)
|
||||||
|
if self._multiplier == 0:
|
||||||
self._multiplier = 1
|
self._multiplier = 1
|
||||||
if self._unit_enum is None:
|
|
||||||
self._unit_enum = 0x7F # unknown
|
self._unit_enum = results.get("unit_of_measure", 0x7F) # default to unknown
|
||||||
if fmting is None:
|
|
||||||
fmting = 0xF9 # 1 digit to the right, 15 digits to the left
|
fmting = results.get(
|
||||||
|
"demand_formatting", 0xF9
|
||||||
|
) # 1 digit to the right, 15 digits to the left
|
||||||
|
|
||||||
r_digits = fmting & 0x07 # digits to the right of decimal point
|
r_digits = fmting & 0x07 # digits to the right of decimal point
|
||||||
l_digits = (fmting >> 3) & 0x0F # digits to the left of decimal point
|
l_digits = (fmting >> 3) & 0x0F # digits to the left of decimal point
|
||||||
|
Loading…
x
Reference in New Issue
Block a user