Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions homeassistant/components/light/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove this, extend your Schema.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the schema from turn_on

vol.ExactSequence((str, cv.small_float, cv.small_float, cv.byte))
)
Expand Down Expand Up @@ -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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turn on is not toggle. see above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is that SERVICE_TOGGLE can do everything SERVICE_TURNON can do, therefore the LIGHT_TOGGLE_SCHEMA is identical to LIGHT_TOGGLE_SCHEMA. Do you still want to make a seperate schema for this? Should I do something like the following then?

LIGHT_TOGGLE_SCHEMA = LIGHT_TURN_ON_SCHEMA.extend()


return True

Expand Down
40 changes: 40 additions & 0 deletions homeassistant/components/light/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,46 @@ toggle:
description: Duration in seconds it takes to get to next state
example: 60

rgb_color:

@pvizeli pvizeli Dec 5, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't copy stuff. Make a comment of possibility

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should I do this?

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

Expand Down
12 changes: 6 additions & 6 deletions homeassistant/helpers/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)