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
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
2024-02-22 22:09:38 +00:00
|
|
|
|
2024-04-24 16:38:52 +00:00
|
|
|
from ...feature import Feature
|
2024-02-22 22:09:38 +00:00
|
|
|
from ..smartmodule import SmartModule
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..smartdevice import SmartDevice
|
|
|
|
|
|
|
|
|
|
|
|
class AlarmModule(SmartModule):
|
|
|
|
"""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-17 13:39:24 +00:00
|
|
|
def __init__(self, device: SmartDevice, module: str):
|
2024-02-22 22:09:38 +00:00
|
|
|
super().__init__(device, module)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
|
|
|
"Alarm",
|
|
|
|
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,
|
|
|
|
"Alarm source",
|
|
|
|
container=self,
|
|
|
|
attribute_getter="source",
|
|
|
|
icon="mdi:bell",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device, "Alarm sound", container=self, attribute_getter="alarm_sound"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device, "Alarm volume", container=self, attribute_getter="alarm_volume"
|
|
|
|
)
|
|
|
|
)
|
2024-04-23 17:49:04 +00:00
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
|
|
|
"Test alarm",
|
|
|
|
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,
|
|
|
|
"Stop alarm",
|
|
|
|
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"]
|
|
|
|
|
|
|
|
@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"]
|
|
|
|
|
|
|
|
@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")
|