From 71cd8f738546448feb19c6b9c7e1c03f048f2137 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sun, 20 Sep 2020 22:44:14 +0200 Subject: [PATCH] style --- custom_components/adaptive_lighting/const.py | 12 ----- custom_components/adaptive_lighting/switch.py | 45 ++++--------------- 2 files changed, 8 insertions(+), 49 deletions(-) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index e6cd5989..1943de1f 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -1,8 +1,3 @@ -import voluptuous as vol - -import homeassistant.helpers.config_validation as cv -from homeassistant.components.light import VALID_TRANSITION - ICON = "mdi:theme-light-dark" DOMAIN = "adaptive_lighting" @@ -35,10 +30,3 @@ CONF_SUNSET_TIME = "sunset_time" CONF_TRANSITION, DEFAULT_TRANSITION = "transition", 60 UNDO_UPDATE_LISTENER = "undo_update_listener" - -# _COMMON_SCHEMA = { -# vol.Optional(CONF_DISABLE_ENTITY): cv.entity_id, -# vol.Optional(CONF_DISABLE_STATE): vol.All(cv.ensure_list, [cv.string]), -# vol.Optional(CONF_SLEEP_ENTITY): cv.entity_id, -# vol.Optional(CONF_SLEEP_STATE): vol.All(cv.ensure_list, [cv.string]), -# } diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 16b64166..5a25bec8 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -86,7 +86,6 @@ from .const import ( ICON, SUN_EVENT_MIDNIGHT, SUN_EVENT_NOON, - UNDO_UPDATE_LISTENER, ) _SUPPORT_OPTS = { @@ -119,39 +118,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities([switch], update_before_add=True) -def _difference_between_states(from_state, to_state): - start = "Lights adjusting because " - if from_state is None and to_state is None: - return start + "both states None" - if from_state is None: - return start + f"from_state: None, to_state: {to_state}" - if to_state is None: - return start + f"from_state: {from_state}, to_state: None" - - changed_attrs = ", ".join( - [ - f"{key}: {val}" - for key, val in to_state.attributes.items() - if from_state.attributes.get(key) != val - ] - ) - if from_state.state == to_state.state: - return start + ( - f"{from_state.entity_id} is still {to_state.state} but" - f" these attributes changes: {changed_attrs}." - ) - elif changed_attrs != "": - return start + ( - f"{from_state.entity_id} changed from {from_state.state} to" - f" {to_state.state} and these attributes changes: {changed_attrs}." - ) - else: - return start + ( - f"{from_state.entity_id} changed from {from_state.state} to" - f" {to_state.state} and no attributes changed." - ) - - class AdaptiveSwitch(SwitchEntity, RestoreEntity): """Representation of a Adaptive Lighting switch.""" @@ -209,7 +175,6 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): elif attr == "none": setattr(self, name, None) - # Initialize attributes that will be set in self._update_attrs self._percent = None self._brightness = None @@ -487,11 +452,17 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): async def _light_state_changed(self, entity_id, from_state, to_state): assert to_state.state == "on" and from_state.state == "off" - _LOGGER.debug(_difference_between_states(from_state, to_state)) + _LOGGER.debug( + "_light_state_changed, from_state: '%s', to_state: '%s'", + from_state, + to_state, + ) await self._update_lights( lights=[entity_id], transition=self._initial_transition, force=True ) async def _state_changed(self, entity_id, from_state, to_state): - _LOGGER.debug(_difference_between_states(from_state, to_state)) + _LOGGER.debug( + "_state_changed, from_state: '%s', to_state: '%s'", from_state, to_state + ) await self._update_lights(transition=self._initial_transition, force=True)