-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from theneweinstein/alarm_days
Add custom alarm days
- Loading branch information
Showing
11 changed files
with
310 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
# github: theneweinstein | ||
ko_fi: theneweinstein |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Text entities for Somneo.""" | ||
import logging | ||
from typing import Any | ||
import voluptuous as vol | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import CONF_NAME | ||
from homeassistant.core import HomeAssistant, callback | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
from homeassistant.components.text import TextEntity | ||
from homeassistant.helpers import config_validation as cv, entity_platform | ||
|
||
from .const import ( | ||
DOMAIN, | ||
WORKDAYS_ICON | ||
) | ||
from .entity import SomneoEntity | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Add Somneo from config_entry.""" | ||
|
||
coordinator = hass.data[DOMAIN][config_entry.entry_id] | ||
unique_id = config_entry.unique_id | ||
assert unique_id is not None | ||
name = config_entry.data[CONF_NAME] | ||
device_info = config_entry.data["dev_info"] | ||
|
||
alarms = [] | ||
for alarm in list(coordinator.data["alarms"]): | ||
alarms.append( | ||
SomneoAlarmDays(coordinator, unique_id, name, device_info, alarm) | ||
) | ||
|
||
async_add_entities(alarms, update_before_add=True) | ||
|
||
|
||
class SomneoAlarmDays(SomneoEntity, TextEntity): | ||
"""Representation of a alarm switch.""" | ||
|
||
_attr_should_poll = True | ||
_attr_assumed_state = False | ||
_attr_available = True | ||
_attr_icon = WORKDAYS_ICON | ||
_attr_native_value = None | ||
_attr_pattern = "^((tomorrow|mon|tue|wed|thu|fri|sat|sun)(,)?)+$" | ||
|
||
def __init__(self, coordinator, unique_id, name, device_info, alarm): | ||
"""Initialize the switches.""" | ||
super().__init__(coordinator, unique_id, name, device_info, alarm) | ||
|
||
self._attr_translation_key = alarm + '_days_str' | ||
self._alarm = alarm | ||
|
||
@callback | ||
def _handle_coordinator_update(self) -> None: | ||
days_list = self.coordinator.data["alarm_day_list"][self._alarm] | ||
self._attr_native_value = ",".join([str(item) for item in days_list if item]) | ||
|
||
self.async_write_ha_state() | ||
|
||
async def async_set_value(self, value: str) -> None: | ||
"""Set the text value.""" | ||
await self.coordinator.async_set_alarm_day(self._alarm, value.split(',')) |
Oops, something went wrong.