From 66d5988647974cb34f6e266fff46d8743273266e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Mon, 5 Dec 2016 11:07:56 +0100 Subject: [PATCH 1/3] Allow toggle to accept parameters --- homeassistant/components/light/__init__.py | 7 +--- homeassistant/components/light/services.yaml | 40 ++++++++++++++++++++ homeassistant/helpers/entity.py | 12 +++--- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 04eb8fabc687af..c598ee3e2e452e 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -115,11 +115,6 @@ ATTR_FLASH: vol.In([FLASH_SHORT, FLASH_LONG]), }) -LIGHT_TOGGLE_SCHEMA = vol.Schema({ - ATTR_ENTITY_ID: cv.entity_ids, - ATTR_TRANSITION: VALID_TRANSITION, -}) - PROFILE_SCHEMA = vol.Schema( vol.ExactSequence((str, cv.small_float, cv.small_float, cv.byte)) ) @@ -270,7 +265,7 @@ def async_handle_light_service(service): hass.services.async_register( DOMAIN, SERVICE_TOGGLE, async_handle_light_service, - descriptions.get(SERVICE_TOGGLE), schema=LIGHT_TOGGLE_SCHEMA) + descriptions.get(SERVICE_TOGGLE), schema=LIGHT_TURN_ON_SCHEMA) return True diff --git a/homeassistant/components/light/services.yaml b/homeassistant/components/light/services.yaml index 8931a46bb73bd4..7770cada405738 100644 --- a/homeassistant/components/light/services.yaml +++ b/homeassistant/components/light/services.yaml @@ -82,6 +82,46 @@ toggle: description: Duration in seconds it takes to get to next state example: 60 + rgb_color: + description: Color for the light in RGB-format + example: '[255, 100, 100]' + + color_name: + description: A human readable color name + example: 'red' + + xy_color: + description: Color for the light in XY-format + example: '[0.52, 0.43]' + + color_temp: + description: Color temperature for the light in mireds (154-500) + example: '250' + + white_value: + description: Number between 0..255 indicating level of white + example: '250' + + brightness: + description: Number between 0..255 indicating brightness + example: 120 + + profile: + description: Name of a light profile to use + example: relax + + flash: + description: If the light should flash + values: + - short + - long + + effect: + description: Light effect + values: + - colorloop + - random + hue_activate_scene: description: Activate a hue scene stored in the hue hub diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 87b05ded264aa2..06793494d0dce6 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -358,17 +358,17 @@ def async_turn_off(self, **kwargs): yield from self.hass.loop.run_in_executor( None, ft.partial(self.turn_off, **kwargs)) - def toggle(self) -> None: + def toggle(self, **kwargs) -> None: """Toggle the entity.""" if self.is_on: - self.turn_off() + self.turn_off(**kwargs) else: - self.turn_on() + self.turn_on(**kwargs) @asyncio.coroutine - def async_toggle(self): + def async_toggle(self, **kwargs): """Toggle the entity.""" if self.is_on: - yield from self.async_turn_off() + yield from self.async_turn_off(**kwargs) else: - yield from self.async_turn_on() + yield from self.async_turn_on(**kwargs) From f83d041b096c5f182cd1ddb101a4f20107fcabed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Mon, 5 Dec 2016 17:07:51 +0100 Subject: [PATCH 2/3] Use LIGHT_TOGGLE_SCHEMA for SERVICE_TOGGLE --- homeassistant/components/light/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index c598ee3e2e452e..d69d18a6118263 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -115,6 +115,8 @@ ATTR_FLASH: vol.In([FLASH_SHORT, FLASH_LONG]), }) +LIGHT_TOGGLE_SCHEMA = LIGHT_TURN_ON_SCHEMA + PROFILE_SCHEMA = vol.Schema( vol.ExactSequence((str, cv.small_float, cv.small_float, cv.byte)) ) @@ -265,7 +267,7 @@ def async_handle_light_service(service): hass.services.async_register( DOMAIN, SERVICE_TOGGLE, async_handle_light_service, - descriptions.get(SERVICE_TOGGLE), schema=LIGHT_TURN_ON_SCHEMA) + descriptions.get(SERVICE_TOGGLE), schema=LIGHT_TOGGLE_SCHEMA) return True From 92d9672442e1bda056ca1d8a353db6cd8caf6697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Tue, 3 Jan 2017 21:56:54 +0100 Subject: [PATCH 3/3] newline. dropped @asyncio.coroutine --- homeassistant/helpers/entity.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index c65271f40b5ece..b331b75bd54d21 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -373,7 +373,6 @@ def toggle(self, **kwargs) -> None: else: self.turn_on(**kwargs) - @asyncio.coroutine def async_toggle(self, **kwargs): """Toggle the entity. @@ -382,4 +381,5 @@ def async_toggle(self, **kwargs): if self.is_on: return self.async_turn_off(**kwargs) else: - return self.async_turn_on(**kwargs) \ No newline at end of file + return self.async_turn_on(**kwargs) +