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:
Teemu R
2024-04-23 19:49:04 +02:00
committed by GitHub
parent b860c32d5f
commit 6e5cae1f47
3 changed files with 50 additions and 6 deletions

View File

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