From 78f07bba4d1c947837013b2f02c3a6dc36762a5b Mon Sep 17 00:00:00 2001 From: mib1185 Date: Thu, 4 Jan 2024 19:05:39 +0000 Subject: [PATCH] add group support --- .../devicetypes/fritzhomedevicebase.py | 7 ++ pyfritzhome/fritzhome.py | 2 +- .../groups/device_list_thermostat.xml | 101 ++++++++++++++++++ tests/test_fritzhomedevicethermostat_group.py | 27 +++++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 tests/responses/groups/device_list_thermostat.xml create mode 100644 tests/test_fritzhomedevicethermostat_group.py diff --git a/pyfritzhome/devicetypes/fritzhomedevicebase.py b/pyfritzhome/devicetypes/fritzhomedevicebase.py index 5cd0f43..32c4992 100644 --- a/pyfritzhome/devicetypes/fritzhomedevicebase.py +++ b/pyfritzhome/devicetypes/fritzhomedevicebase.py @@ -15,7 +15,9 @@ class FritzhomeDeviceBase(FritzhomeEntityBase): """The Fritzhome Device class.""" identifier = None + is_group = None fw_version = None + group_members = None manufacturer = None productname = None present = None @@ -44,6 +46,11 @@ def _update_from_node(self, node): self.present = bool(int(node.findtext("present"))) + groupinfo = node.find("groupinfo") + self.is_group = groupinfo is not None + if self.is_group: + self.group_members = str(groupinfo.findtext("members")).split(",") + # General def get_present(self): """Check if the device is present.""" diff --git a/pyfritzhome/fritzhome.py b/pyfritzhome/fritzhome.py index 44bd333..a6550ca 100644 --- a/pyfritzhome/fritzhome.py +++ b/pyfritzhome/fritzhome.py @@ -143,7 +143,7 @@ def _get_listinfo_elements(self, entity_type): plain = self._aha_request("get" + entity_type + "listinfos") dom = ElementTree.fromstring(plain) _LOGGER.debug(dom) - return dom.findall(entity_type) + return dom.findall("*") def get_device_elements(self): """Get the DOM elements for the device list.""" diff --git a/tests/responses/groups/device_list_thermostat.xml b/tests/responses/groups/device_list_thermostat.xml new file mode 100644 index 0000000..9d6bd4b --- /dev/null +++ b/tests/responses/groups/device_list_thermostat.xml @@ -0,0 +1,101 @@ + + + + 1 + 0 + Wohnzimmer Couch + 80 + 0 + + 220 + -10 + + + 44 + 43 + 35 + 43 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 80 + + 0 + 43 + + 0 + 0 + 1 + 0 + + + + 1 + 0 + Wohnzimmer Tisch + 80 + 0 + + 220 + -10 + + + 44 + 43 + 35 + 43 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 80 + + 0 + 43 + + 0 + 0 + 1 + 0 + + + + 1 + 0 + Wohnzimmer + + + 43 + 35 + 43 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 0 + 43 + + 0 + 0 + 1 + 0 + + + 0 + 16,17 + + + \ No newline at end of file diff --git a/tests/test_fritzhomedevicethermostat_group.py b/tests/test_fritzhomedevicethermostat_group.py new file mode 100644 index 0000000..e632ff1 --- /dev/null +++ b/tests/test_fritzhomedevicethermostat_group.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from unittest.mock import MagicMock + +from pyfritzhome import Fritzhome + +from .helper import Helper + + +class TestFritzhomeDeviceThermostat(object): + def setup_method(self): + self.mock = MagicMock() + self.fritz = Fritzhome("10.0.0.1", "user", "pass") + self.fritz._request = self.mock + self.fritz._devices = {} + + def test_device_alert_on(self): + self.mock.side_effect = [ + Helper.response("groups/device_list_thermostat"), + ] + + self.fritz.update_devices() + group = self.fritz.get_device_by_ain("grp303E4F-3F7D9BE07") + assert group.has_thermostat + assert group.is_group + assert group.group_members == ["16", "17"]