Add 'internal_state' to return the results from the last update query (#306)

This can be useful for debugging purposes, e.g., for homeassistant diagnostics
This commit is contained in:
Teemu R 2022-02-07 09:13:47 +01:00 committed by GitHub
parent 700f3859c2
commit b61c0feea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -721,6 +721,15 @@ class SmartDevice:
"""Return True if the device supports color changes.""" """Return True if the device supports color changes."""
return False 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): def __repr__(self):
if self._last_update is None: if self._last_update is None:
return f"<{self._device_type} at {self.host} - update() needed>" return f"<{self._device_type} at {self.host} - update() needed>"

View File

@ -134,3 +134,8 @@ async def test_childrens(dev):
assert len(dev.children) > 0 assert len(dev.children) > 0
else: else:
assert len(dev.children) == 0 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