Added toggle service
Added a toggle service to the homeassistant, light, switch, and media_player domains.
This commit is contained in:
1 parent
1ed314f6f6
commit
342a819fd4
7 files changed
+82
-6
No files matched your search
@@ -15,7 +15,8 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
|
||||
from homeassistant.const import (
|
||||
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID)
|
||||
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE,
|
||||
ATTR_ENTITY_ID)
|
||||
from homeassistant.components import (
|
||||
group, discovery, wink, isy994, verisure, zwave, tellduslive, mysensors)
|
||||
|
||||
@@ -71,6 +72,12 @@ def turn_off(hass, entity_id=None):
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||
|
||||
|
||||
def toggle(hass, entity_id=None):
|
||||
""" Toggle all or specified switch. """
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, data)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
""" Track states and offer events for switches. """
|
||||
component = EntityComponent(
|
||||
@@ -85,6 +92,8 @@ def setup(hass, config):
|
||||
for switch in target_switches:
|
||||
if service.service == SERVICE_TURN_ON:
|
||||
switch.turn_on()
|
||||
elif service.service == SERVICE_TOGGLE:
|
||||
switch.toggle()
|
||||
else:
|
||||
switch.turn_off()
|
||||
|
||||
@@ -97,6 +106,8 @@ def setup(hass, config):
|
||||
descriptions.get(SERVICE_TURN_OFF))
|
||||
hass.services.register(DOMAIN, SERVICE_TURN_ON, handle_switch_service,
|
||||
descriptions.get(SERVICE_TURN_ON))
|
||||
hass.services.register(DOMAIN, SERVICE_TOGGLE, handle_switch_service,
|
||||
descriptions.get(SERVICE_TOGGLE))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
Reference in new issue
Block a user