mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-11 22:34:04 +02:00
fix ha/core pre-commit issues and submit this code as PR
This commit is contained in:
parent
2109921eee
commit
5be04625b6
4 changed files with 17 additions and 7 deletions
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
Adaptive Lighting Component for Home-Assistant.
|
||||
|
||||
"""Adaptive Lighting Component in Home-Assistant.
|
||||
|
||||
This component calculates color temperature and brightness to synchronize
|
||||
your color-changing lights with the perceived color temperature of the sky
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
"""Config flow for Coronavirus integration."""
|
||||
import logging
|
||||
from copy import copy
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
|
@ -47,6 +46,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
|
||||
def validate_options(user_input, errors):
|
||||
"""Validate the options in the OptionsFlow.
|
||||
|
||||
This is an extra validation step because the validators
|
||||
in `EXTRA_VALIDATION` cannot be serialized to json.
|
||||
"""
|
||||
for key, (validate, _) in EXTRA_VALIDATION.items():
|
||||
# these are unserializable validators
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
"""Constants for the Adaptive Lighting Component in Home-Assistant."""
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
|
@ -43,6 +44,7 @@ CONF_ON_LIGHTS_ONLY = "on_lights_only"
|
|||
|
||||
|
||||
def int_between(a, b):
|
||||
"""Return an integer between 'a' and 'b'."""
|
||||
return vol.All(vol.Coerce(int), vol.Range(min=a, max=b))
|
||||
|
||||
|
||||
|
|
@ -71,10 +73,15 @@ VALIDATION_TUPLES = [
|
|||
|
||||
|
||||
def timedelta_as_int(value):
|
||||
"""Convert a `datetime.timedelta` object to an integer.
|
||||
|
||||
This integer can be serialized to json but a timedelta cannot.
|
||||
"""
|
||||
return value.total_seconds()
|
||||
|
||||
|
||||
def join_strings(lst):
|
||||
"""Join a list to comma-separated values string."""
|
||||
return ",".join(lst)
|
||||
|
||||
|
||||
|
|
@ -94,6 +101,7 @@ EXTRA_VALIDATION = {
|
|||
|
||||
|
||||
def maybe_coerce(key, validation):
|
||||
"""Coerce the validation into a json serializable type."""
|
||||
validation, coerce = EXTRA_VALIDATION.get(key, (validation, None))
|
||||
if coerce is not None:
|
||||
return vol.All(validation, vol.Coerce(coerce))
|
||||
|
|
@ -101,7 +109,7 @@ def maybe_coerce(key, validation):
|
|||
|
||||
|
||||
def replace_none_str(value, replace_with=None):
|
||||
"""Replaces "None" -> replace_with."""
|
||||
"""Replace "None" -> replace_with."""
|
||||
return value if value != NONE_STR else replace_with
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
{
|
||||
vol.Required(CONF_LIGHTS): cv.entity_ids,
|
||||
vol.Optional(
|
||||
CONF_TRANSITION, default=self._initial_transition
|
||||
CONF_TRANSITION, default=switch._initial_transition
|
||||
): VALID_TRANSITION,
|
||||
vol.Optional(CONF_COLORS_ONLY, default=False): cv.boolean,
|
||||
vol.Optional(CONF_ON_LIGHTS_ONLY, default=False): cv.boolean,
|
||||
|
|
@ -139,7 +139,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
|
||||
|
||||
def validate(config_entry):
|
||||
"""Gets the options and data from the config_entry and adds defaults."""
|
||||
"""Get the options and data from the config_entry and add defaults."""
|
||||
defaults = {key: default for key, default, _ in VALIDATION_TUPLES}
|
||||
data = deepcopy(defaults)
|
||||
data.update(config_entry.options) # come from options flow
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue