def get_dbt_rh_points(self):
"""Extract temperature - humidity points from sensors."""
def _mean(values: Union[List[float],
Tuple[float]]) -> Optional[float]:
if values:
try:
return sum(values) / len(values)
except TypeError:
_LOGGER.error('Bad values in mean: %s', values)
return None
results = yield from self.collect_states()
points = {}
for key, value in results.items():
if isinstance(value, dict):
temp_zone = humid_zone = counter = 0
for k_room, s_values in value.items():
temp = _mean([v[0] for v in s_values])
humid = _mean([v[1] for v in s_values])
if temp is not None and humid is not None:
points[k_room] = (int(100 * temp) / 100.,
int(100 * humid) / 100.)
temp_zone += temp
humid_zone += humid
counter += 1
if counter:
points[key] = (int(100 * temp_zone / counter) / 100.,
int(100 * humid_zone / counter) / 100.)
else:
temp = _mean([v[0] for v in value])
humid = _mean([v[1] for v in value])
if temp is not None and humid is not None:
points[key] = (int(100 * temp) / 100.,
int(100 * humid) / 100.)
return points
评论列表
文章目录