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 supported features property to FritzhomeEntityBase #95

Merged
merged 1 commit into from
Jan 15, 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
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
6 changes: 6 additions & 0 deletions pyfritzhome/devicetypes/fritzhomeentitybase.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FritzhomeEntityBase(ABC):
_fritz = None
ain: str = None
_functionsbitmask = None
supported_features = None

def __init__(self, fritz=None, node=None):
"""Create an entity base object."""
Expand All @@ -43,6 +44,11 @@ def _update_from_node(self, node):

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

self.supported_features = []
for feature in FritzhomeDeviceFeatures:
if self._has_feature(feature):
self.supported_features.append(feature)

@property
def device_and_unit_id(self):
"""Get the device and possible unit id."""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_fritzhomedevicealarm.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 @@ -24,6 +25,10 @@ def test_device_alert_on(self):
device = self.fritz.get_device_by_ain("05333 0077045-1")
assert device.present
assert device.alert_state
assert device.supported_features == [
FritzhomeDeviceFeatures.ALARM,
FritzhomeDeviceFeatures.HANFUN_UNIT,
]

def test_device_alert_off(self):
self.mock.side_effect = [
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 pyfritzhome.devicetypes.fritzhomeentitybase import FritzhomeEntityBase

from .helper import Helper
Expand All @@ -28,6 +29,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
8 changes: 8 additions & 0 deletions tests/test_fritzhomedeviceblind.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 @@ -24,11 +25,18 @@ def test_device_response(self):
device1 = self.fritz.get_device_by_ain("14276 1234567")
assert device1.present
assert not device1.tx_busy
assert device1.supported_features == [FritzhomeDeviceFeatures.HANFUN_DEVICE]

device2 = self.fritz.get_device_by_ain("14276 1234567-1")
assert device2.present
assert not device2.tx_busy
assert device2.endpositionsset
assert device2.supported_features == [
FritzhomeDeviceFeatures.ALARM,
FritzhomeDeviceFeatures.HANFUN_UNIT,
FritzhomeDeviceFeatures.LEVEL,
FritzhomeDeviceFeatures.BLIND,
]

assert device2.level == 252
assert device2.levelpercentage == 99
Expand Down
5 changes: 5 additions & 0 deletions tests/test_fritzhomedevicebutton.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 @@ -29,6 +30,10 @@ def test_button_fritzdect440(self):
assert not device.battery_low
assert device.battery_level == 100
assert not device.tx_busy
assert device.supported_features == [
FritzhomeDeviceFeatures.BUTTON,
FritzhomeDeviceFeatures.TEMPERATURE,
]

button = device.get_button_by_ain("12345 0000001-1")
assert button.name == "Taster Wohnzimmer: Oben rechts"
Expand Down
9 changes: 9 additions & 0 deletions tests/test_fritzhomedevicelightbulb.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 @@ -26,6 +27,7 @@ def test_device_init(self):
assert device.ain == "12345"
assert device.fw_version == "34.10.16.16.009"
assert device.present # Lightbulb has power and is connected
assert device.supported_features == [FritzhomeDeviceFeatures.HANFUN_DEVICE]

# Get sub-device
device = self.fritz.get_device_by_ain("12345-1")
Expand All @@ -39,6 +41,13 @@ def test_device_init(self):
assert device.saturation == 180
assert device.color_temp is None
assert device.name == "FRITZ!DECT 500 Büro"
assert device.supported_features == [
FritzhomeDeviceFeatures.LIGHTBULB,
FritzhomeDeviceFeatures.HANFUN_UNIT,
FritzhomeDeviceFeatures.SWITCHABLE,
FritzhomeDeviceFeatures.LEVEL,
FritzhomeDeviceFeatures.COLOR,
]

def test_device_init_non_color_bulb(self):
self.mock.side_effect = [
Expand Down
6 changes: 6 additions & 0 deletions tests/test_fritzhomedevicepowermeter.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 @@ -25,6 +26,11 @@ def test_get_switch_power(self):
device = self.fritz.get_device_by_ain("08761 0000434")

assert device.get_switch_power() == 18000
assert device.supported_features == [
FritzhomeDeviceFeatures.POWER_METER,
FritzhomeDeviceFeatures.TEMPERATURE,
FritzhomeDeviceFeatures.SWITCH,
]
device._fritz._request.assert_called_with(
"http://10.0.0.1/webservices/homeautoswitch.lua",
{"ain": "08761 0000434", "switchcmd": "getswitchpower", "sid": None},
Expand Down
6 changes: 6 additions & 0 deletions tests/test_fritzhomedeviceswitch.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_get_switch_state(self):

assert device.get_switch_state()
assert not device.get_switch_state()
assert device.supported_features == [
FritzhomeDeviceFeatures.POWER_METER,
FritzhomeDeviceFeatures.TEMPERATURE,
FritzhomeDeviceFeatures.SWITCH,
]
device._fritz._request.assert_called_with(
"http://10.0.0.1/webservices/homeautoswitch.lua",
{"ain": "08761 0000434", "switchcmd": "getswitchstate", "sid": None},
Expand Down
5 changes: 5 additions & 0 deletions tests/test_fritzhomedevicetemperature.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 @@ -25,6 +26,10 @@ def test_get_temperature(self):
device = self.fritz.get_device_by_ain("12345")

assert device.get_temperature() == 24.5
assert device.supported_features == [
FritzhomeDeviceFeatures.THERMOSTAT,
FritzhomeDeviceFeatures.TEMPERATURE,
]
device._fritz._request.assert_called_with(
"http://10.0.0.1/webservices/homeautoswitch.lua",
{"ain": "12345", "switchcmd": "gettemperature", "sid": None},
Expand Down
9 changes: 9 additions & 0 deletions tests/test_fritzhomedevicethermostat.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, FritzhomeDevice
from pyfritzhome.devicetypes.fritzhomedevicefeatures import FritzhomeDeviceFeatures

from .helper import Helper

Expand All @@ -27,6 +28,10 @@ def test_device_hkr_fw_03_50(self):
assert device.lock is None
assert device.error_code is None
assert device.battery_low is None
assert device.supported_features == [
FritzhomeDeviceFeatures.THERMOSTAT,
FritzhomeDeviceFeatures.TEMPERATURE,
]

def test_device_hkr_fw_03_54(self):
self.mock.side_effect = [
Expand All @@ -36,6 +41,10 @@ def test_device_hkr_fw_03_54(self):
self.fritz.update_devices()
device = self.fritz.get_device_by_ain("23456")
assert device.present
assert device.supported_features == [
FritzhomeDeviceFeatures.THERMOSTAT,
FritzhomeDeviceFeatures.TEMPERATURE,
]

def test_get_target_temperature(self):
self.mock.side_effect = [
Expand Down
2 changes: 2 additions & 0 deletions tests/test_fritzhomedevicethermostat_group.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 @@ -25,3 +26,4 @@ def test_device_alert_on(self):
assert group.has_thermostat
assert group.is_group
assert group.group_members == ["16", "17"]
assert group.supported_features == [FritzhomeDeviceFeatures.THERMOSTAT]
5 changes: 5 additions & 0 deletions tests/test_fritzhometemplate.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 Down Expand Up @@ -33,6 +34,10 @@ def test_template_init(self):
assert not template.apply_level
assert not template.apply_color
assert not template.apply_dialhelper
assert template.supported_features == [
FritzhomeDeviceFeatures.THERMOSTAT,
FritzhomeDeviceFeatures.TEMPERATURE,
]

def test_template_with_single_device(self):
template = self.fritz.get_template_by_ain("tmp0B32F7-1B0650234")
Expand Down