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

Add group support #91

Merged
merged 1 commit into from
Jan 10, 2024
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
69 changes: 68 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ add a new user.
present=True
lock=None
devicelock=None
is_group=False
Alert:
alert=True
##############################
Expand All @@ -49,6 +50,7 @@ add a new user.
present=True
lock=False
devicelock=False
is_group=False
Temperature:
temperature=19
offset=-3
Expand All @@ -63,6 +65,50 @@ add a new user.
summer=False
holiday=False
##############################
name=Wohnzimmer Couch
ain=09995 0523646
id=17
productname=FRITZ!DECT 301
manufacturer=AVM
present=True
lock=False
devicelock=False
is_group=False
Temperature:
temperature=20.5
Thermostat:
battery_low=False
battery_level=80
actual=20.5
target=21.5
comfort=21.5
eco=17.5
window=False
summer=False
holiday=False
##############################
name=Wohnzimmer Tisch
ain=09995 0517495
id=18
productname=FRITZ!DECT 301
manufacturer=AVM
present=True
lock=False
devicelock=False
is_group=False
Temperature:
temperature=21.0
Thermostat:
battery_low=False
battery_level=80
actual=21.0
target=21.5
comfort=21.5
eco=17.5
window=False
summer=False
holiday=False
##############################
name=Schalter WC Heizung
ain=08761 0402392
id=21
Expand All @@ -71,6 +117,7 @@ add a new user.
present=True
lock=True
devicelock=False
is_group=False
Switch:
switch_state=False
Powermeter:
Expand All @@ -80,7 +127,27 @@ add a new user.
Temperature:
temperature=22
offset=3

##############################
name=Wohnzimmer
ain=grp303E4F-3F7D9BE07
id=900
productname=
manufacturer=AVM
present=True
lock=False
devicelock=False
is_group=True
group_members=['17', '18']
Thermostat:
battery_low=None
battery_level=None
actual=None
target=21.5
comfort=21.5
eco=17.5
window=None
summer=None
holiday=None

Fritzbox User
-------------
Expand Down
3 changes: 3 additions & 0 deletions pyfritzhome/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def list_all(fritz, args):
print(" present=%s" % device.present)
print(" lock=%s" % device.lock)
print(" devicelock=%s" % device.device_lock)
print(" is_group=%s" % device.is_group)
if device.is_group:
print(" group_members=%s" % device.group_members)

if device.present is False:
continue
Expand Down
7 changes: 7 additions & 0 deletions pyfritzhome/devicetypes/fritzhomedevicebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion pyfritzhome/fritzhome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
101 changes: 101 additions & 0 deletions tests/responses/groups/device_list_thermostat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0"?>
<devicelist version="1" fwversion="7.57">
<device identifier="09995 0523646" id="16" functionbitmask="320" fwversion="05.08" manufacturer="AVM" productname="FRITZ!DECT 301">
<present>1</present>
<txbusy>0</txbusy>
<name>Wohnzimmer Couch</name>
<battery>80</battery>
<batterylow>0</batterylow>
<temperature>
<celsius>220</celsius>
<offset>-10</offset>
</temperature>
<hkr>
<tist>44</tist>
<tsoll>43</tsoll>
<absenk>35</absenk>
<komfort>43</komfort>
<lock>0</lock>
<devicelock>0</devicelock>
<errorcode>0</errorcode>
<windowopenactiv>0</windowopenactiv>
<windowopenactiveendtime>0</windowopenactiveendtime>
<boostactive>0</boostactive>
<boostactiveendtime>0</boostactiveendtime>
<batterylow>0</batterylow>
<battery>80</battery>
<nextchange>
<endperiod>0</endperiod>
<tchange>43</tchange>
</nextchange>
<summeractive>0</summeractive>
<holidayactive>0</holidayactive>
<adaptiveHeatingActive>1</adaptiveHeatingActive>
<adaptiveHeatingRunning>0</adaptiveHeatingRunning>
</hkr>
</device>
<device identifier="09995 0517495" id="17" functionbitmask="320" fwversion="05.08" manufacturer="AVM" productname="FRITZ!DECT 301">
<present>1</present>
<txbusy>0</txbusy>
<name>Wohnzimmer Tisch</name>
<battery>80</battery>
<batterylow>0</batterylow>
<temperature>
<celsius>220</celsius>
<offset>-10</offset>
</temperature>
<hkr>
<tist>44</tist>
<tsoll>43</tsoll>
<absenk>35</absenk>
<komfort>43</komfort>
<lock>0</lock>
<devicelock>0</devicelock>
<errorcode>0</errorcode>
<windowopenactiv>0</windowopenactiv>
<windowopenactiveendtime>0</windowopenactiveendtime>
<boostactive>0</boostactive>
<boostactiveendtime>0</boostactiveendtime>
<batterylow>0</batterylow>
<battery>80</battery>
<nextchange>
<endperiod>0</endperiod>
<tchange>43</tchange>
</nextchange>
<summeractive>0</summeractive>
<holidayactive>0</holidayactive>
<adaptiveHeatingActive>1</adaptiveHeatingActive>
<adaptiveHeatingRunning>0</adaptiveHeatingRunning>
</hkr>
</device>
<group synchronized="1" identifier="grp303E4F-3F7D9BE07" id="900" functionbitmask="4160" fwversion="1.0" manufacturer="AVM" productname="">
<present>1</present>
<txbusy>0</txbusy>
<name>Wohnzimmer</name>
<hkr>
<tist/>
<tsoll>43</tsoll>
<absenk>35</absenk>
<komfort>43</komfort>
<lock>0</lock>
<devicelock>0</devicelock>
<errorcode>0</errorcode>
<windowopenactiv>0</windowopenactiv>
<windowopenactiveendtime>0</windowopenactiveendtime>
<boostactive>0</boostactive>
<boostactiveendtime>0</boostactiveendtime>
<nextchange>
<endperiod>0</endperiod>
<tchange>43</tchange>
</nextchange>
<summeractive>0</summeractive>
<holidayactive>0</holidayactive>
<adaptiveHeatingActive>1</adaptiveHeatingActive>
<adaptiveHeatingRunning>0</adaptiveHeatingRunning>
</hkr>
<groupinfo>
<masterdeviceid>0</masterdeviceid>
<members>16,17</members>
</groupinfo>
</group>
</devicelist>
27 changes: 27 additions & 0 deletions tests/test_fritzhomedevicethermostat_group.py
Original file line number Diff line number Diff line change
@@ -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"]