From db65f5704558d7a25de362744f8983159d759927 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Sun, 6 Feb 2022 18:57:18 +0100 Subject: [PATCH] Add 'internal_state' to return the results from the last update query This can be useful for debugging purposes, e.g., for homeassistant diagnostics --- kasa/smartdevice.py | 9 +++++++++ kasa/tests/test_smartdevice.py | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index bf43cf174..25b916318 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -721,6 +721,15 @@ def is_color(self) -> bool: """Return True if the device supports color changes.""" return False + @property + def internal_state(self) -> Any: + """Return the internal state of the instance. + + The returned object contains the raw results from the last update call. + This should only be used for debugging purposes. + """ + return self._last_update + def __repr__(self): if self._last_update is None: return f"<{self._device_type} at {self.host} - update() needed>" diff --git a/kasa/tests/test_smartdevice.py b/kasa/tests/test_smartdevice.py index 380cdd1fb..2dfd96340 100644 --- a/kasa/tests/test_smartdevice.py +++ b/kasa/tests/test_smartdevice.py @@ -134,3 +134,8 @@ async def test_childrens(dev): assert len(dev.children) > 0 else: assert len(dev.children) == 0 + + +async def test_internal_state(dev): + """Make sure the internal state returns the last update results.""" + assert dev.internal_state == dev._last_update