mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
Implement action feature (#849)
Adds `FeatureType.Action` making it possible to expose features like "reboot", "test alarm", "pair" etc. The `attribute_getter` is no longer mandatory, but it will raise an exception if not defined for other types than actions. Trying to read returns a static string `<Action>`. This overloads the `set_value` to call the given callable on any value. This also fixes the `play` and `stop` coroutines of the alarm module to await the call.
This commit is contained in:
@@ -54,6 +54,24 @@ class AlarmModule(SmartModule):
|
||||
device, "Alarm volume", container=self, attribute_getter="alarm_volume"
|
||||
)
|
||||
)
|
||||
self._add_feature(
|
||||
Feature(
|
||||
device,
|
||||
"Test alarm",
|
||||
container=self,
|
||||
attribute_setter="play",
|
||||
type=FeatureType.Action,
|
||||
)
|
||||
)
|
||||
self._add_feature(
|
||||
Feature(
|
||||
device,
|
||||
"Stop alarm",
|
||||
container=self,
|
||||
attribute_setter="stop",
|
||||
type=FeatureType.Action,
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def alarm_sound(self):
|
||||
@@ -83,8 +101,8 @@ class AlarmModule(SmartModule):
|
||||
|
||||
async def play(self):
|
||||
"""Play alarm."""
|
||||
return self.call("play_alarm")
|
||||
return await self.call("play_alarm")
|
||||
|
||||
async def stop(self):
|
||||
"""Stop alarm."""
|
||||
return self.call("stop_alarm")
|
||||
return await self.call("stop_alarm")
|
||||
|
Reference in New Issue
Block a user