-
-
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.
Rewrote the component to support the new time entity.
- Loading branch information
1 parent
71635e3
commit 979ddec
Showing
9 changed files
with
234 additions
and
281 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,52 @@ | ||
|
||
from homeassistant.const import (UnitOfTemperature, PERCENTAGE, LIGHT_LUX, UnitOfSoundPressure) | ||
from homeassistant.const import ( | ||
UnitOfTemperature, | ||
PERCENTAGE, | ||
LIGHT_LUX, | ||
UnitOfSoundPressure, | ||
) | ||
from typing import Final | ||
|
||
DOMAIN: Final = 'somneo' | ||
DOMAIN: Final = "somneo" | ||
VERSION: Final = "0.3" | ||
|
||
DEFAULT_NAME: Final = "Somneo" | ||
|
||
CONF_SENS: Final = 'sensors' | ||
CONF_SESSION: Final = 'session' | ||
|
||
ALARM: Final = 'alarm' | ||
PW: Final = 'powerwake' | ||
ALARMS: Final = 'alarms' | ||
HOURS: Final = 'hours' | ||
MINUTES: Final = 'minutes' | ||
WORKDAYS: Final = 'workdays' | ||
WEEKEND: Final = 'weekend' | ||
TOMORROW: Final = 'tomorrow' | ||
EVERYDAY: Final = 'daily' | ||
UNKNOWN: Final = 'unknown' | ||
PW_DELTA: Final = 'powerwake_delta' | ||
|
||
ALARMS_ICON: Final = 'hass:alarm' | ||
PW_ICON: Final = 'hass:alarm-plus' | ||
HOURS_ICON: Final = 'hass:counter' | ||
MINUTES_ICON: Final = 'hass:counter' | ||
WORKDAYS_ICON: Final = 'hass:calendar-range' | ||
WEEKEND_ICON: Final = 'hass:calendar-range' | ||
|
||
ATTR_ALARM: Final = 'alarm' | ||
ATTR_CURVE: Final = 'curve' | ||
ATTR_LEVEL: Final = 'level' | ||
ATTR_DURATION: Final = 'duration' | ||
ATTR_SOURCE: Final = 'source' | ||
ATTR_CHANNEL: Final = 'channel' | ||
|
||
|
||
SENSORS: Final = {'temperature': UnitOfTemperature.CELSIUS, 'humidity': PERCENTAGE, 'luminance': LIGHT_LUX, 'noise': UnitOfSoundPressure.DECIBEL} | ||
CONF_SENS: Final = "sensors" | ||
CONF_SESSION: Final = "session" | ||
|
||
ALARM: Final = "alarm" | ||
PW: Final = "powerwake" | ||
ALARMS: Final = "alarms" | ||
HOURS: Final = "hours" | ||
MINUTES: Final = "minutes" | ||
WORKDAYS: Final = "workdays" | ||
WEEKEND: Final = "weekend" | ||
TOMORROW: Final = "tomorrow" | ||
EVERYDAY: Final = "daily" | ||
UNKNOWN: Final = "unknown" | ||
PW_DELTA: Final = "powerwake_delta" | ||
|
||
ALARMS_ICON: Final = "hass:alarm" | ||
PW_ICON: Final = "hass:alarm-plus" | ||
TIME_ICON: Final = "hass:clock-digital" | ||
SNOOZE_ICON: Final = "hass:alarm-snooze" | ||
WORKDAYS_ICON: Final = "hass:calendar-range" | ||
WEEKEND_ICON: Final = "hass:calendar-range" | ||
|
||
ATTR_ALARM: Final = "alarm" | ||
ATTR_CURVE: Final = "curve" | ||
ATTR_LEVEL: Final = "level" | ||
ATTR_DURATION: Final = "duration" | ||
ATTR_SOURCE: Final = "source" | ||
ATTR_CHANNEL: Final = "channel" | ||
|
||
|
||
SENSORS: Final = { | ||
"temperature": UnitOfTemperature.CELSIUS, | ||
"humidity": PERCENTAGE, | ||
"luminance": LIGHT_LUX, | ||
"noise": UnitOfSoundPressure.DECIBEL, | ||
} | ||
|
||
NOTIFICATION_ID: Final = "somneosensor_notification" | ||
NOTIFICATION_TITLE: Final = "SomneoSensor Setup" | ||
|
||
|
||
|
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 |
---|---|---|
|
@@ -16,5 +16,5 @@ | |
"requirements": [ | ||
"pysomneo==2.5.2" | ||
], | ||
"version": "3.2.0" | ||
} | ||
"version": "4.0.0" | ||
} |
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,67 @@ | ||
"""Platform for number entity to catch hour/minute of alarms.""" | ||
import logging | ||
from datetime import time | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.components.time import TimeEntity | ||
from homeassistant.const import CONF_NAME | ||
from homeassistant.core import HomeAssistant, callback | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from .const import DOMAIN, TIME_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 = [] | ||
# Add hour & min number_entity for each alarms | ||
for alarm in list(coordinator.data["alarms"]): | ||
alarms.append(SomneoTime(coordinator, unique_id, name, device_info, alarm)) | ||
|
||
async_add_entities(alarms, update_before_add=True) | ||
|
||
|
||
class SomneoTime(SomneoEntity, TimeEntity): | ||
_attr_should_poll = True | ||
_attr_assumed_state = False | ||
_attr_available = True | ||
_attr_has_entity_name = True | ||
_attr_icon = TIME_ICON | ||
_attr_native_value = None | ||
|
||
def __init__(self, coordinator, unique_id, name, dev_info, alarm): | ||
"""Initialize number entities.""" | ||
super().__init__(coordinator, unique_id, name, dev_info, alarm + "_time") | ||
|
||
self._attr_translation_key = alarm + "_time" | ||
|
||
self._alarm = alarm | ||
|
||
@callback | ||
def _handle_coordinator_update(self) -> None: | ||
self._attr_native_value = time( | ||
self.coordinator.data["alarms_hour"][self._alarm], | ||
self.coordinator.data["alarms_minute"][self._alarm], | ||
) | ||
|
||
self.async_write_ha_state() | ||
|
||
async def async_set_value(self, value: time) -> None: | ||
"""Called when user adjust Hours / Minutes in the UI""" | ||
await self.coordinator.async_set_alarm( | ||
self._alarm, hours=value.hour, minutes=value.minute | ||
) |
Oops, something went wrong.