-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for green LEDs to API (#4556)
* Add support for green LEDs to API * Save board config in supervisor and post on start * Ignore no-value-for-parameter in validate
- Loading branch information
Showing
16 changed files
with
424 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Constants for boards.""" | ||
|
||
BOARD_NAME_GREEN = "Green" | ||
BOARD_NAME_SUPERVISED = "Supervised" | ||
BOARD_NAME_YELLOW = "Yellow" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Green board management.""" | ||
|
||
import asyncio | ||
|
||
from dbus_fast.aio.message_bus import MessageBus | ||
|
||
from ....const import ATTR_ACTIVITY_LED, ATTR_POWER_LED, ATTR_USER_LED | ||
from ...const import DBUS_ATTR_ACTIVITY_LED, DBUS_ATTR_POWER_LED, DBUS_ATTR_USER_LED | ||
from ...interface import dbus_property | ||
from .const import BOARD_NAME_GREEN | ||
from .interface import BoardProxy | ||
from .validate import SCHEMA_GREEN_BOARD | ||
|
||
|
||
class Green(BoardProxy): | ||
"""Green board manager object.""" | ||
|
||
def __init__(self) -> None: | ||
"""Initialize properties.""" | ||
super().__init__(BOARD_NAME_GREEN, SCHEMA_GREEN_BOARD) | ||
|
||
@property | ||
@dbus_property | ||
def activity_led(self) -> bool: | ||
"""Get activity LED enabled.""" | ||
return self.properties[DBUS_ATTR_ACTIVITY_LED] | ||
|
||
@activity_led.setter | ||
def activity_led(self, enabled: bool) -> None: | ||
"""Enable/disable activity LED.""" | ||
self._data[ATTR_ACTIVITY_LED] = enabled | ||
asyncio.create_task(self.dbus.Boards.Green.set_activity_led(enabled)) | ||
|
||
@property | ||
@dbus_property | ||
def power_led(self) -> bool: | ||
"""Get power LED enabled.""" | ||
return self.properties[DBUS_ATTR_POWER_LED] | ||
|
||
@power_led.setter | ||
def power_led(self, enabled: bool) -> None: | ||
"""Enable/disable power LED.""" | ||
self._data[ATTR_POWER_LED] = enabled | ||
asyncio.create_task(self.dbus.Boards.Green.set_power_led(enabled)) | ||
|
||
@property | ||
@dbus_property | ||
def user_led(self) -> bool: | ||
"""Get user LED enabled.""" | ||
return self.properties[DBUS_ATTR_USER_LED] | ||
|
||
@user_led.setter | ||
def user_led(self, enabled: bool) -> None: | ||
"""Enable/disable disk LED.""" | ||
self._data[ATTR_USER_LED] = enabled | ||
asyncio.create_task(self.dbus.Boards.Green.set_user_led(enabled)) | ||
|
||
async def connect(self, bus: MessageBus) -> None: | ||
"""Connect to D-Bus.""" | ||
await super().connect(bus) | ||
|
||
# Set LEDs based on settings on connect | ||
self.activity_led = self._data[ATTR_ACTIVITY_LED] | ||
self.power_led = self._data[ATTR_POWER_LED] | ||
self.user_led = self._data[ATTR_USER_LED] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Validation for board config.""" | ||
|
||
import voluptuous as vol | ||
|
||
from ....const import ( | ||
ATTR_ACTIVITY_LED, | ||
ATTR_DISK_LED, | ||
ATTR_HEARTBEAT_LED, | ||
ATTR_POWER_LED, | ||
ATTR_USER_LED, | ||
) | ||
|
||
# pylint: disable=no-value-for-parameter | ||
SCHEMA_BASE_BOARD = vol.Schema({}, extra=vol.REMOVE_EXTRA) | ||
|
||
SCHEMA_GREEN_BOARD = vol.Schema( | ||
{ | ||
vol.Optional(ATTR_ACTIVITY_LED, default=True): vol.Boolean(), | ||
vol.Optional(ATTR_POWER_LED, default=True): vol.Boolean(), | ||
vol.Optional(ATTR_USER_LED, default=True): vol.Boolean(), | ||
}, | ||
extra=vol.REMOVE_EXTRA, | ||
) | ||
|
||
SCHEMA_YELLOW_BOARD = vol.Schema( | ||
{ | ||
vol.Optional(ATTR_DISK_LED, default=True): vol.Boolean(), | ||
vol.Optional(ATTR_HEARTBEAT_LED, default=True): vol.Boolean(), | ||
vol.Optional(ATTR_POWER_LED, default=True): vol.Boolean(), | ||
}, | ||
extra=vol.REMOVE_EXTRA, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.