Skip to content

Commit

Permalink
add supported features property
Browse files Browse the repository at this point in the history
  • Loading branch information
mib1185 committed Jan 14, 2024
1 parent 53afd61 commit ad2f839
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
31 changes: 16 additions & 15 deletions pyfritzhome/devicetypes/fritzhomedevicefeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions pyfritzhome/devicetypes/fritzhomeentitybase.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def _update_from_node(self, node):

self.name = node.findtext("name").strip()

@property
def supported_features(self) -> list[FritzhomeDeviceFeatures]:
features = []
for feature in FritzhomeDeviceFeatures:
if self._has_feature(feature):
features.append(feature)
return features

# XML Helpers

def get_node_value(self, elem, node):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_fritzhomedevicebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import MagicMock

from pyfritzhome import Fritzhome
from pyfritzhome.devicetypes.fritzhomedevicefeatures import FritzhomeDeviceFeatures

from .helper import Helper

Expand All @@ -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 = [
Expand Down

0 comments on commit ad2f839

Please sign in to comment.