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

@@ -55,9 +55,9 @@ class AutoOffModule(SmartModule):
"""Return True if enabled."""
return self.data["enable"]
def set_enabled(self, enable: bool):
async def set_enabled(self, enable: bool):
"""Enable/disable auto off."""
return self.call(
return await self.call(
"set_auto_off_config",
{"enable": enable, "delay_min": self.data["delay_min"]},
)
@@ -67,9 +67,9 @@ class AutoOffModule(SmartModule):
"""Return time until auto off."""
return self.data["delay_min"]
def set_delay(self, delay: int):
async def set_delay(self, delay: int):
"""Set time until auto off."""
return self.call(
return await self.call(
"set_auto_off_config", {"delay_min": delay, "enable": self.data["enable"]}
)