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:
@@ -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"]}
|
||||
)
|
||||
|
||||
|
@@ -34,6 +34,7 @@ class ColorTemperatureModule(SmartModule):
|
||||
attribute_setter="set_color_temp",
|
||||
range_getter="valid_temperature_range",
|
||||
category=Feature.Category.Primary,
|
||||
type=Feature.Type.Number,
|
||||
)
|
||||
)
|
||||
|
||||
|
@@ -88,9 +88,9 @@ class LightTransitionModule(SmartModule):
|
||||
|
||||
return self.data["off_state"]
|
||||
|
||||
def set_enabled_v1(self, enable: bool):
|
||||
async def set_enabled_v1(self, enable: bool):
|
||||
"""Enable gradual on/off."""
|
||||
return self.call("set_on_off_gradually_info", {"enable": enable})
|
||||
return await self.call("set_on_off_gradually_info", {"enable": enable})
|
||||
|
||||
@property
|
||||
def enabled_v1(self) -> bool:
|
||||
|
@@ -48,6 +48,7 @@ class TemperatureSensor(SmartModule):
|
||||
attribute_getter="temperature_unit",
|
||||
attribute_setter="set_temperature_unit",
|
||||
type=Feature.Type.Choice,
|
||||
choices=["celsius", "fahrenheit"],
|
||||
)
|
||||
)
|
||||
# TODO: use temperature_unit for feature creation
|
||||
|
Reference in New Issue
Block a user