fix data in switch

This commit is contained in:
Bas Nijholt 2020-09-24 20:56:01 +02:00
commit e9ee147e20
3 changed files with 7 additions and 5 deletions

View file

@ -50,7 +50,6 @@ def _all_unique_profiles(value):
_DOMAIN_SCHEMA = get_domain_schema(yaml=True)
_LOGGER.error(_DOMAIN_SCHEMA)
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.All(

View file

@ -44,7 +44,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
_DOMAIN_SCHEMA = get_domain_schema(yaml=False)
schema = {k: v for k, v in _DOMAIN_SCHEMA.items() if k in user_input}
vol.Schema(schema)(user_input)
_LOGGER.error(str(user_input) + str(schema))
return self.async_create_entry(title=user_input["name"], data=user_input)
@staticmethod

View file

@ -3,6 +3,7 @@
import asyncio
import bisect
import logging
from copy import deepcopy
from datetime import timedelta
import homeassistant.util.dt as dt_util
@ -113,14 +114,15 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
def __init__(self, hass, name, config_entry):
"""Initialize the Adaptive Lighting switch."""
_LOGGER.error(f"title={config_entry.title}")
self.hass = hass
self._name = name
self._entity_id = f"switch.{DOMAIN}_{slugify(name)}"
self._icon = ICON
defaults = {key: default for key, default, _ in VALIDATION_TUPLES}
data = dict(defaults, **config_entry.options, **config_entry.data)
data = deepcopy(defaults)
data.update(config_entry.options) # come from options flow
data.update(config_entry.data) # all yaml settings come from data
data = {key: replace_none(value) for key, value in data.items()}
for key, (validate, coerce) in EXTRA_VALIDATION.items():
# Fix the types of the inputs
@ -161,7 +163,9 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
# Set and unset tracker in async_turn_on and async_turn_off
self.unsub_tracker = None
_LOGGER.error(
f"Setting up with {self._lights}: config_entry.data: {config_entry.data}, config_entry.options: {config_entry.options}, converted to {data}"
f"Setting up with '{self._lights}',"
f" config_entry.data: '{config_entry.data}',"
f" config_entry.options: '{config_entry.options}', converted to '{data}'."
)
@property