From acc1471a38f5036ddd1d146deb075aac2eaf9788 Mon Sep 17 00:00:00 2001 From: mib1185 Date: Sun, 14 Jan 2024 12:51:00 +0000 Subject: [PATCH] add supported features property --- .../devicetypes/fritzhomedevicefeatures.py | 31 ++++++++++--------- .../devicetypes/fritzhomeentitybase.py | 8 +++++ tests/test_fritzhomedevicebase.py | 6 ++++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/pyfritzhome/devicetypes/fritzhomedevicefeatures.py b/pyfritzhome/devicetypes/fritzhomedevicefeatures.py index cfc1e30..ccc1dc0 100644 --- a/pyfritzhome/devicetypes/fritzhomedevicefeatures.py +++ b/pyfritzhome/devicetypes/fritzhomedevicefeatures.py @@ -5,18 +5,19 @@ class FritzhomeDeviceFeatures(IntFlag): """The feature list class.""" - LIGHTBULB = 0x0004 - ALARM = 0x0010 - UNKNOWN = 0x0020 - BUTTON = 0x0020 - THERMOSTAT = 0x0040 - POWER_METER = 0x0080 - TEMPERATURE = 0x0100 - SWITCH = 0x0200 - DECT_REPEATER = 0x0400 - MICROPHONE = 0x0800 - HANFUN = 0x2000 - SWITCHABLE = 0x8000 - LEVEL = 0x10000 - COLOR = 0x20000 - BLIND = 0x40000 + HANFUN_DEVICE = 0x0001 # bit 0 + LIGHTBULB = 0x0004 # bit 2 + ALARM = 0x0010 # bit 4 + BUTTON = 0x0020 # bit 5 + THERMOSTAT = 0x0040 # bit 6 + POWER_METER = 0x0080 # bit 7 + TEMPERATURE = 0x0100 # bit 8 + SWITCH = 0x0200 # bit 9 + DECT_REPEATER = 0x0400 # bit 10 + MICROPHONE = 0x0800 # bit 11 + HANFUN_UNIT = 0x2000 # bit 13 + SWITCHABLE = 0x8000 # bit 15 + LEVEL = 0x10000 # bit 16 + COLOR = 0x20000 # bit 17 + BLIND = 0x40000 # bit 18 + HUMIDITY = 0x100000 # bit 20 diff --git a/pyfritzhome/devicetypes/fritzhomeentitybase.py b/pyfritzhome/devicetypes/fritzhomeentitybase.py index 274b5d1..1644e37 100644 --- a/pyfritzhome/devicetypes/fritzhomeentitybase.py +++ b/pyfritzhome/devicetypes/fritzhomeentitybase.py @@ -43,6 +43,14 @@ def _update_from_node(self, node): self.name = node.findtext("name").strip() + @property + def supported_features(self) -> list: + features = [] + for feature in FritzhomeDeviceFeatures: + if self._has_feature(feature): + features.append(feature) + return features + # XML Helpers def get_node_value(self, elem, node): diff --git a/tests/test_fritzhomedevicebase.py b/tests/test_fritzhomedevicebase.py index 0e3241c..d8fda23 100644 --- a/tests/test_fritzhomedevicebase.py +++ b/tests/test_fritzhomedevicebase.py @@ -4,6 +4,7 @@ from unittest.mock import MagicMock from pyfritzhome import Fritzhome +from pyfritzhome.devicetypes.fritzhomedevicefeatures import FritzhomeDeviceFeatures from .helper import Helper @@ -27,6 +28,11 @@ def test_device_init(self): assert device.has_switch assert device.has_temperature_sensor assert device.has_powermeter + assert device.supported_features == [ + FritzhomeDeviceFeatures.POWER_METER, + FritzhomeDeviceFeatures.TEMPERATURE, + FritzhomeDeviceFeatures.SWITCH, + ] def test_device_init_present_false(self): self.mock.side_effect = [