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:
Teemu R
2024-05-02 15:32:06 +02:00
committed by GitHub
parent 9dcd8ec91b
commit 5ef81f4669
8 changed files with 91 additions and 19 deletions

View File

@@ -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}"