2024-05-10 18:29:28 +00:00
|
|
|
"""Module for led controls."""
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-05-11 18:28:18 +00:00
|
|
|
from ...interfaces.led import Led as LedInterface
|
2024-05-10 18:29:28 +00:00
|
|
|
from ..iotmodule import IotModule
|
|
|
|
|
|
|
|
|
2024-05-11 18:28:18 +00:00
|
|
|
class Led(IotModule, LedInterface):
|
2024-05-10 18:29:28 +00:00
|
|
|
"""Implementation of led controls."""
|
|
|
|
|
|
|
|
def query(self) -> dict:
|
|
|
|
"""Query to execute during the update cycle."""
|
|
|
|
return {}
|
|
|
|
|
|
|
|
@property
|
2024-11-10 18:55:13 +00:00
|
|
|
def mode(self) -> str:
|
2024-05-10 18:29:28 +00:00
|
|
|
"""LED mode setting.
|
|
|
|
|
|
|
|
"always", "never"
|
|
|
|
"""
|
|
|
|
return "always" if self.led else "never"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def led(self) -> bool:
|
|
|
|
"""Return the state of the led."""
|
|
|
|
sys_info = self.data
|
|
|
|
return bool(1 - sys_info["led_off"])
|
|
|
|
|
2024-11-10 18:55:13 +00:00
|
|
|
async def set_led(self, state: bool) -> dict:
|
2024-05-10 18:29:28 +00:00
|
|
|
"""Set the state of the led (night mode)."""
|
|
|
|
return await self.call("set_led_off", {"off": int(not state)})
|
2024-06-17 10:22:05 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_supported(self) -> bool:
|
|
|
|
"""Return whether the module is supported by the device."""
|
|
|
|
return "led_off" in self.data
|