mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-11 22:34:04 +02:00
simplify
This commit is contained in:
parent
21cc22d42c
commit
ab069de4aa
2 changed files with 7 additions and 17 deletions
|
|
@ -97,8 +97,9 @@ def maybe_coerce(key, validation):
|
|||
return validation
|
||||
|
||||
|
||||
def replace_none(x):
|
||||
return x if x != NONE_STR else vol.UNDEFINED
|
||||
def replace_none(value, replace_with=None):
|
||||
"""Replaces "None" -> replace_with."""
|
||||
return value if value != NONE_STR else replace_with
|
||||
|
||||
|
||||
validation_tuples = [
|
||||
|
|
@ -108,7 +109,7 @@ validation_tuples = [
|
|||
|
||||
_DOMAIN_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(key, default=replace_none(default)): validation
|
||||
vol.Optional(key, default=replace_none(default, vol.UNDEFINED)): validation
|
||||
for key, default, validation in validation_tuples
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import bisect
|
|||
import logging
|
||||
from copy import deepcopy
|
||||
from datetime import timedelta
|
||||
from functools import partial
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
|
@ -74,11 +73,11 @@ from .const import (
|
|||
DOMAIN,
|
||||
EXTRA_VALIDATION,
|
||||
ICON,
|
||||
NONE_STR,
|
||||
SERVICE_APPLY,
|
||||
SUN_EVENT_MIDNIGHT,
|
||||
SUN_EVENT_NOON,
|
||||
VALIDATION_TUPLES,
|
||||
replace_none,
|
||||
)
|
||||
|
||||
_SUPPORT_OPTS = {
|
||||
|
|
@ -88,13 +87,8 @@ _SUPPORT_OPTS = {
|
|||
"transition": SUPPORT_TRANSITION,
|
||||
}
|
||||
|
||||
_ALLOWED_ORDERS = {
|
||||
(SUN_EVENT_SUNRISE, SUN_EVENT_NOON, SUN_EVENT_SUNSET, SUN_EVENT_MIDNIGHT),
|
||||
(SUN_EVENT_SUNSET, SUN_EVENT_MIDNIGHT, SUN_EVENT_SUNRISE, SUN_EVENT_NOON),
|
||||
(SUN_EVENT_MIDNIGHT, SUN_EVENT_SUNRISE, SUN_EVENT_NOON, SUN_EVENT_SUNSET),
|
||||
(SUN_EVENT_NOON, SUN_EVENT_SUNSET, SUN_EVENT_MIDNIGHT, SUN_EVENT_SUNRISE),
|
||||
}
|
||||
|
||||
_ORDER = (SUN_EVENT_SUNRISE, SUN_EVENT_NOON, SUN_EVENT_SUNSET, SUN_EVENT_MIDNIGHT)
|
||||
_ALLOWED_ORDERS = {_ORDER[i:] + _ORDER[:i] for i in range(len(_ORDER))}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -133,11 +127,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
async_add_entities([switch], update_before_add=True)
|
||||
|
||||
|
||||
def replace_none(value):
|
||||
"""Replaces "None" -> None."""
|
||||
return value if value != NONE_STR else None
|
||||
|
||||
|
||||
def validate(config_entry):
|
||||
"""Gets the options and data from the config_entry and adds defaults."""
|
||||
defaults = {key: default for key, default, _ in VALIDATION_TUPLES}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue