Skip to content
Merged
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
6 changes: 5 additions & 1 deletion homeassistant/components/zha/core/channels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ async def get_attributes(self, attributes, from_cache=True):
only_cache=from_cache,
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:
self.debug(
"failed to get attributes '%s' on '%s' cluster: %s",
Expand Down
30 changes: 11 additions & 19 deletions homeassistant/components/zha/core/channels/homeautomation.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,19 @@ async def async_initialize(self, from_cache):

async def fetch_config(self, from_cache):
"""Fetch config from device and updates format specifier."""
divisor = await self.get_attribute_value(
"ac_power_divisor", from_cache=from_cache
results = await self.get_attributes(
[
"ac_power_divisor",
"power_divisor",
"ac_power_multiplier",
"power_multiplier",
],
from_cache=from_cache,
)
if divisor is None:
divisor = await self.get_attribute_value(
"power_divisor", from_cache=from_cache
)
if divisor is None:
divisor = 1
self._divisor = divisor

mult = await self.get_attribute_value(
"ac_power_multiplier", from_cache=from_cache
self._divisor = results.get("ac_power_divisor", results.get("power_divisor", 1))
self._multiplier = results.get(
"ac_power_multiplier", results.get("power_multiplier", 1)
)
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
def divisor(self) -> Optional[int]:
Expand Down
31 changes: 16 additions & 15 deletions homeassistant/components/zha/core/channels/smartenergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ async def async_initialize(self, from_cache):
@callback
def attribute_updated(self, attrid, value):
"""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)

@property
Expand All @@ -107,25 +109,24 @@ def unit_of_measurement(self):

async def fetch_config(self, from_cache):
"""Fetch config from device and updates format specifier."""
self._divisor = await self.get_attribute_value("divisor", from_cache=from_cache)
self._multiplier = await self.get_attribute_value(
"multiplier", 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
results = await self.get_attributes(
["divisor", "multiplier", "unit_of_measure", "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
if self._multiplier is None or self._multiplier == 0:

self._multiplier = results.get("multiplier", 1)
if self._multiplier == 0:
self._multiplier = 1
if self._unit_enum is None:
self._unit_enum = 0x7F # unknown
if fmting is None:
fmting = 0xF9 # 1 digit to the right, 15 digits to the left

self._unit_enum = results.get("unit_of_measure", 0x7F) # default to unknown

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
l_digits = (fmting >> 3) & 0x0F # digits to the left of decimal point
Expand Down