From 6498e94bac9b80d09c2f5b3ba018a9091077be83 Mon Sep 17 00:00:00 2001 From: Daniel Muehlbachler-Pietrzykowski Date: Tue, 12 Dec 2023 10:18:33 +0100 Subject: [PATCH] chore: add __str__ method to device --- onyx_client/client.py | 4 ++-- onyx_client/device/device.py | 5 +++++ tests/device/test_device.py | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/onyx_client/client.py b/onyx_client/client.py index 115a063..befc733 100644 --- a/onyx_client/client.py +++ b/onyx_client/client.py @@ -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( diff --git a/onyx_client/device/device.py b/onyx_client/device/device.py index d2b3841..b456b60 100644 --- a/onyx_client/device/device.py +++ b/onyx_client/device/device.py @@ -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 diff --git a/tests/device/test_device.py b/tests/device/test_device.py index 964a844..fc917c1 100644 --- a/tests/device/test_device.py +++ b/tests/device/test_device.py @@ -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)