Skip to content

Commit

Permalink
Merge pull request #16 from rappenze/add_dead_attributes
Browse files Browse the repository at this point in the history
Add dead and deadReason properties to device
  • Loading branch information
rappenze authored Apr 16, 2023
2 parents 3d4e693 + 5424d07 commit db96b01
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
22 changes: 22 additions & 0 deletions pyfibaro/fibaro_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,28 @@ def has_armed(self) -> bool:
"""Returns true if the device has a unit property."""
return "armed" in self.properties

@property
def dead(self) -> bool:
"""Returns the state if the device is reachable if supported,
otherwise False is returned.
"""
return _to_bool(self.properties.get("dead", False))

@property
def has_dead(self) -> bool:
"""Returns true if the device has a dead property."""
return "dead" in self.properties

@property
def dead_reason(self) -> str | None:
"""Returns the dead reason or None if not supported."""
return self.properties.get("deadReason")

@property
def has_dead_reason(self) -> bool:
"""Returns true if the device has a deadReason property."""
return "deadReason" in self.properties

@property
def value(self) -> ValueModel:
"""Returns the value info."""
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pyfibaro
version = 0.6.9
version = 0.7.0
description = Simple API to access fibaro home center from any Python 3 script. Designed for Home Assistant (but not only)
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
3 changes: 2 additions & 1 deletion tests/fixture/device-hc3.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"autoConfig": 0,
"configured": true,
"date": "a",
"dead": false,
"dead": true,
"deadReason": "Connection problem",
"deviceControlType": 1,
"deviceIcon": 28,
"deviceRole": "Other",
Expand Down
4 changes: 4 additions & 0 deletions tests/test_fibaro_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def test_fibaro_device() -> None:
assert devices[0].has_heating_thermostat_setpoint_future is False
assert devices[0].heating_thermostat_setpoint_future == 0
assert devices[0].target_level == 0
assert devices[0].has_dead is True
assert devices[0].dead is False
assert devices[0].has_dead_reason is False
assert devices[0].dead_reason is None

assert isinstance(devices[0].actions, dict)
assert isinstance(devices[0].properties, dict)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_fibaro_device_hc3.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def test_fibaro_device() -> None:
assert isinstance(devices[0].actions, dict)
assert isinstance(devices[0].properties, dict)
assert mock.call_count == 3
assert devices[0].has_dead is True
assert devices[0].dead is True
assert devices[0].has_dead_reason is True
assert devices[0].dead_reason == "Connection problem"


def test_fibaro_device_turn_on() -> None:
Expand Down

0 comments on commit db96b01

Please sign in to comment.