mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Improve feature setter robustness (#870)
This adds a test to check that all feature.set_value() calls will cause a query, i.e., that there are no self.call()s that are not awaited, and fixes existing code in this context. This also fixes an issue where it was not possible to print out the feature if the value threw an exception.
This commit is contained in:
@@ -172,9 +172,14 @@ class Feature:
|
||||
return await getattr(container, self.attribute_setter)(value)
|
||||
|
||||
def __repr__(self):
|
||||
value = self.value
|
||||
try:
|
||||
value = self.value
|
||||
except Exception as ex:
|
||||
return f"Unable to read value ({self.id}): {ex}"
|
||||
|
||||
if self.precision_hint is not None and value is not None:
|
||||
value = round(self.value, self.precision_hint)
|
||||
|
||||
s = f"{self.name} ({self.id}): {value}"
|
||||
if self.unit is not None:
|
||||
s += f" {self.unit}"
|
||||
|
Reference in New Issue
Block a user