Skip to content

Commit

Permalink
chore: add __str__ method to device
Browse files Browse the repository at this point in the history
  • Loading branch information
muhlba91 committed Dec 12, 2023
1 parent 0d45376 commit 6498e94
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions onyx_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ async def _read_loop(self, include_details: bool = False):
if self._shutdown:
break
if self._event_callback is not None:
_LOGGER.info("Received device: %s", device)
_LOGGER.debug("Received device: %s", device)
self._event_callback(device)
else:
_LOGGER.warning("Received data but no callback is defined")
_LOGGER.warning("Received data but no callback is defined.")


def create(
Expand Down
5 changes: 5 additions & 0 deletions onyx_client/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def __init__(
self.device_mode = device_mode
self.actions = actions

def __str__(self):
return (
f"Device(id={self.identifier}, name={self.name}, type={self.device_type})"
)

def __eq__(self, other):
if isinstance(self, other.__class__):
return self.identifier == other.identifier
Expand Down
6 changes: 6 additions & 0 deletions tests/device/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def test_init(self, device_mode):
assert device.device_type == DeviceType.AWNING
assert device.device_mode.mode == DeviceType.ROLLERSHUTTER

def test_str(self, device_mode):
assert (
str(Device("id", "name", DeviceType.AWNING, device_mode, list(Action)))
== "Device(id=id, name=name, type=DeviceType.AWNING)"
)

def test_eq(self, device_mode):
assert Device(
"id", "name", DeviceType.AWNING, device_mode, list(Action)
Expand Down

0 comments on commit 6498e94

Please sign in to comment.