diff --git a/custom_components/adaptive_lighting/__init__.py b/custom_components/adaptive_lighting/__init__.py index 207ea4e6..0a053fb0 100755 --- a/custom_components/adaptive_lighting/__init__.py +++ b/custom_components/adaptive_lighting/__init__.py @@ -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 diff --git a/custom_components/adaptive_lighting/config_flow.py b/custom_components/adaptive_lighting/config_flow.py index 6874114b..ba3e8a04 100644 --- a/custom_components/adaptive_lighting/config_flow.py +++ b/custom_components/adaptive_lighting/config_flow.py @@ -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: diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index ba526dfc..228689c0 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -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 diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 0e3546f8..74319e14 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -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