2024-02-22 22:09:38 +00:00
|
|
|
"""Implementation of alarm module."""
|
2024-04-16 18:21:20 +00:00
|
|
|
|
2024-04-17 13:39:24 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-04-24 16:38:52 +00:00
|
|
|
from ...feature import Feature
|
2024-02-22 22:09:38 +00:00
|
|
|
from ..smartmodule import SmartModule
|
|
|
|
|
|
|
|
|
2024-05-11 18:28:18 +00:00
|
|
|
class Alarm(SmartModule):
|
2024-02-22 22:09:38 +00:00
|
|
|
"""Implementation of alarm module."""
|
|
|
|
|
|
|
|
REQUIRED_COMPONENT = "alarm"
|
|
|
|
|
2024-04-17 13:39:24 +00:00
|
|
|
def query(self) -> dict:
|
2024-02-22 22:09:38 +00:00
|
|
|
"""Query to execute during the update cycle."""
|
|
|
|
return {
|
|
|
|
"get_alarm_configure": None,
|
|
|
|
"get_support_alarm_type_list": None, # This should be needed only once
|
|
|
|
}
|
|
|
|
|
2024-04-30 06:56:09 +00:00
|
|
|
def _initialize_features(self):
|
|
|
|
"""Initialize features.
|
|
|
|
|
|
|
|
This is implemented as some features depend on device responses.
|
|
|
|
"""
|
|
|
|
device = self._device
|
2024-02-22 22:09:38 +00:00
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
id="alarm",
|
|
|
|
name="Alarm",
|
2024-02-22 22:09:38 +00:00
|
|
|
container=self,
|
|
|
|
attribute_getter="active",
|
|
|
|
icon="mdi:bell",
|
2024-04-24 16:38:52 +00:00
|
|
|
type=Feature.Type.BinarySensor,
|
2024-02-22 22:09:38 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
id="alarm_source",
|
|
|
|
name="Alarm source",
|
2024-02-22 22:09:38 +00:00
|
|
|
container=self,
|
|
|
|
attribute_getter="source",
|
|
|
|
icon="mdi:bell",
|
2024-06-25 16:30:36 +00:00
|
|
|
type=Feature.Type.Sensor,
|
2024-02-22 22:09:38 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
2024-04-30 06:56:09 +00:00
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
id="alarm_sound",
|
|
|
|
name="Alarm sound",
|
2024-04-30 06:56:09 +00:00
|
|
|
container=self,
|
|
|
|
attribute_getter="alarm_sound",
|
|
|
|
attribute_setter="set_alarm_sound",
|
|
|
|
category=Feature.Category.Config,
|
|
|
|
type=Feature.Type.Choice,
|
|
|
|
choices_getter="alarm_sounds",
|
2024-02-22 22:09:38 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
2024-04-30 06:56:09 +00:00
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
id="alarm_volume",
|
|
|
|
name="Alarm volume",
|
2024-04-30 06:56:09 +00:00
|
|
|
container=self,
|
|
|
|
attribute_getter="alarm_volume",
|
|
|
|
attribute_setter="set_alarm_volume",
|
|
|
|
category=Feature.Category.Config,
|
|
|
|
type=Feature.Type.Choice,
|
2024-05-07 08:38:09 +00:00
|
|
|
choices=["low", "normal", "high"],
|
2024-02-22 22:09:38 +00:00
|
|
|
)
|
|
|
|
)
|
2024-04-23 17:49:04 +00:00
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
id="test_alarm",
|
|
|
|
name="Test alarm",
|
2024-04-23 17:49:04 +00:00
|
|
|
container=self,
|
|
|
|
attribute_setter="play",
|
2024-04-24 16:38:52 +00:00
|
|
|
type=Feature.Type.Action,
|
2024-04-23 17:49:04 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
id="stop_alarm",
|
|
|
|
name="Stop alarm",
|
2024-04-23 17:49:04 +00:00
|
|
|
container=self,
|
|
|
|
attribute_setter="stop",
|
2024-04-24 16:38:52 +00:00
|
|
|
type=Feature.Type.Action,
|
2024-04-23 17:49:04 +00:00
|
|
|
)
|
|
|
|
)
|
2024-02-22 22:09:38 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def alarm_sound(self):
|
|
|
|
"""Return current alarm sound."""
|
|
|
|
return self.data["get_alarm_configure"]["type"]
|
|
|
|
|
2024-04-30 06:56:09 +00:00
|
|
|
async def set_alarm_sound(self, sound: str):
|
|
|
|
"""Set alarm sound.
|
|
|
|
|
|
|
|
See *alarm_sounds* for list of available sounds.
|
|
|
|
"""
|
|
|
|
payload = self.data["get_alarm_configure"].copy()
|
|
|
|
payload["type"] = sound
|
|
|
|
return await self.call("set_alarm_configure", payload)
|
|
|
|
|
2024-02-22 22:09:38 +00:00
|
|
|
@property
|
2024-04-17 13:39:24 +00:00
|
|
|
def alarm_sounds(self) -> list[str]:
|
2024-02-22 22:09:38 +00:00
|
|
|
"""Return list of available alarm sounds."""
|
|
|
|
return self.data["get_support_alarm_type_list"]["alarm_type_list"]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def alarm_volume(self):
|
|
|
|
"""Return alarm volume."""
|
|
|
|
return self.data["get_alarm_configure"]["volume"]
|
|
|
|
|
2024-04-30 06:56:09 +00:00
|
|
|
async def set_alarm_volume(self, volume: str):
|
|
|
|
"""Set alarm volume."""
|
|
|
|
payload = self.data["get_alarm_configure"].copy()
|
|
|
|
payload["volume"] = volume
|
|
|
|
return await self.call("set_alarm_configure", payload)
|
|
|
|
|
2024-02-22 22:09:38 +00:00
|
|
|
@property
|
|
|
|
def active(self) -> bool:
|
|
|
|
"""Return true if alarm is active."""
|
|
|
|
return self._device.sys_info["in_alarm"]
|
|
|
|
|
|
|
|
@property
|
2024-04-17 13:39:24 +00:00
|
|
|
def source(self) -> str | None:
|
2024-02-22 22:09:38 +00:00
|
|
|
"""Return the alarm cause."""
|
|
|
|
src = self._device.sys_info["in_alarm_source"]
|
|
|
|
return src if src else None
|
|
|
|
|
|
|
|
async def play(self):
|
|
|
|
"""Play alarm."""
|
2024-04-23 17:49:04 +00:00
|
|
|
return await self.call("play_alarm")
|
2024-02-22 22:09:38 +00:00
|
|
|
|
|
|
|
async def stop(self):
|
|
|
|
"""Stop alarm."""
|
2024-04-23 17:49:04 +00:00
|
|
|
return await self.call("stop_alarm")
|