From 42944b2dd948da45e7d215b0f414c5e46b9fdbce Mon Sep 17 00:00:00 2001 From: Giang Vo Date: Thu, 2 Nov 2017 07:46:16 +1100 Subject: [PATCH] add-template: address PR comments --- homeassistant/components/fan/template.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/fan/template.py b/homeassistant/components/fan/template.py index 49df9bced7e..a58fe5c918e 100644 --- a/homeassistant/components/fan/template.py +++ b/homeassistant/components/fan/template.py @@ -94,12 +94,12 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): if str(temp_ids) != MATCH_ALL: template_entity_ids |= set(temp_ids) - if speed_template is not None: + if speed_template: temp_ids = speed_template.extract_entities() if str(temp_ids) != MATCH_ALL: template_entity_ids |= set(temp_ids) - if oscillating_template is not None: + if oscillating_template: temp_ids = oscillating_template.extract_entities() if str(temp_ids) != MATCH_ALL: template_entity_ids |= set(temp_ids) @@ -118,10 +118,6 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): ) ) - if not fans: - _LOGGER.error("No fans added") - return False - async_add_devices(fans) return True @@ -148,11 +144,11 @@ class TemplateFan(FanEntity): self._off_script = Script(hass, off_action) self._set_speed_script = None - if set_speed_action is not None: + if set_speed_action: self._set_speed_script = Script(hass, set_speed_action) self._set_oscillating_script = None - if set_oscillating_action is not None: + if set_oscillating_action: self._set_oscillating_script = Script(hass, set_oscillating_action) self._state = False @@ -160,10 +156,10 @@ class TemplateFan(FanEntity): self._oscillating = None self._template.hass = self.hass - if self._speed_template is not None: + if self._speed_template: self._speed_template.hass = self.hass self._supported_features |= SUPPORT_SET_SPEED - if self._oscillating_template is not None: + if self._oscillating_template: self._oscillating_template.hass = self.hass self._supported_features |= SUPPORT_OSCILLATE @@ -225,7 +221,7 @@ class TemplateFan(FanEntity): This method is a coroutine. """ self._state = False - self.hass.async_add_job(self._off_script.async_run()) + yield from self.hass.async_add_job(self._off_script.async_run()) @asyncio.coroutine def async_set_speed(self, speed: str) -> None: @@ -308,7 +304,7 @@ class TemplateFan(FanEntity): self._state = None # Update speed if 'speed_template' is configured - if self._speed_template is not None: + if self._speed_template: try: speed = self._speed_template.async_render().lower() except TemplateError as ex: @@ -328,7 +324,7 @@ class TemplateFan(FanEntity): self._speed = None # Update oscillating if 'oscillating_template' is configured - if self._oscillating_template is not None: + if self._oscillating_template: try: oscillating = self._oscillating_template.async_render().lower() except TemplateError as ex: