diff --git a/homeassistant/components/remote/__init__.py b/homeassistant/components/remote/__init__.py index bec4adcaa7e..64a5c77e5dd 100755 --- a/homeassistant/components/remote/__init__.py +++ b/homeassistant/components/remote/__init__.py @@ -18,7 +18,8 @@ from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity import ToggleEntity import homeassistant.helpers.config_validation as cv 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 from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa @@ -51,7 +52,7 @@ REMOTE_SERVICE_SCHEMA = vol.Schema({ vol.Required(ATTR_ENTITY_ID): cv.entity_ids, }) -REMOTE_SERVICE_TURN_ON_SCHEMA = REMOTE_SERVICE_SCHEMA.extend({ +REMOTE_SERVICE_ACTIVITY_SCHEMA = REMOTE_SERVICE_SCHEMA.extend({ vol.Optional(ATTR_ACTIVITY): cv.string }) @@ -80,12 +81,31 @@ def turn_on(hass, activity=None, entity_id=None): @bind_hass -def turn_off(hass, entity_id=None): +def turn_off(hass, activity=None, entity_id=None): """Turn all or specified remote off.""" - data = {ATTR_ENTITY_ID: entity_id} if entity_id else None + data = {} + if activity: + data[ATTR_ACTIVITY] = activity + + if entity_id: + data[ATTR_ENTITY_ID] = entity_id + hass.services.call(DOMAIN, SERVICE_TURN_OFF, data) +@bind_hass +def toggle(hass, activity=None, entity_id=None): + """Toggle all or specified remote.""" + data = {} + if activity: + data[ATTR_ACTIVITY] = activity + + if entity_id: + data[ATTR_ENTITY_ID] = entity_id + + hass.services.call(DOMAIN, SERVICE_TOGGLE, data) + + @bind_hass def send_command(hass, device, command, entity_id=None, num_repeats=None, delay_secs=None): @@ -124,12 +144,14 @@ def async_setup(hass, config): for remote in target_remotes: if service.service == SERVICE_TURN_ON: yield from remote.async_turn_on(activity=activity_id) + elif service.service == SERVICE_TOGGLE: + yield from remote.async_toggle(activity=activity_id) elif service.service == SERVICE_SEND_COMMAND: yield from remote.async_send_command( device=device, command=command, num_repeats=num_repeats, delay_secs=delay_secs) else: - yield from remote.async_turn_off() + yield from remote.async_turn_off(activity=activity_id) update_tasks = [] for remote in target_remotes: @@ -152,11 +174,15 @@ def async_setup(hass, config): hass.services.async_register( DOMAIN, SERVICE_TURN_OFF, async_handle_remote_service, descriptions.get(SERVICE_TURN_OFF), - schema=REMOTE_SERVICE_SCHEMA) + schema=REMOTE_SERVICE_ACTIVITY_SCHEMA) hass.services.async_register( DOMAIN, SERVICE_TURN_ON, async_handle_remote_service, descriptions.get(SERVICE_TURN_ON), - schema=REMOTE_SERVICE_TURN_ON_SCHEMA) + schema=REMOTE_SERVICE_ACTIVITY_SCHEMA) + hass.services.async_register( + DOMAIN, SERVICE_TOGGLE, async_handle_remote_service, + descriptions.get(SERVICE_TOGGLE), + schema=REMOTE_SERVICE_ACTIVITY_SCHEMA) hass.services.async_register( DOMAIN, SERVICE_SEND_COMMAND, async_handle_remote_service, descriptions.get(SERVICE_SEND_COMMAND), diff --git a/homeassistant/components/remote/apple_tv.py b/homeassistant/components/remote/apple_tv.py index e89234c60ac..50f31f57a5b 100644 --- a/homeassistant/components/remote/apple_tv.py +++ b/homeassistant/components/remote/apple_tv.py @@ -68,7 +68,7 @@ class AppleTVRemote(remote.RemoteDevice): self._power.set_power_on(True) @asyncio.coroutine - def async_turn_off(self): + def async_turn_off(self, **kwargs): """Turn the device off. This method is a coroutine. diff --git a/homeassistant/components/remote/harmony.py b/homeassistant/components/remote/harmony.py index cdc6a7ac61f..9c551e5cbc6 100755 --- a/homeassistant/components/remote/harmony.py +++ b/homeassistant/components/remote/harmony.py @@ -202,7 +202,7 @@ class HarmonyRemote(remote.RemoteDevice): else: _LOGGER.error("No activity specified with turn_on service") - def turn_off(self): + def turn_off(self, **kwargs): """Start the PowerOff activity.""" import pyharmony pyharmony.ha_power_off(self._token, self.host, self._port) diff --git a/homeassistant/components/remote/itach.py b/homeassistant/components/remote/itach.py index 9feb2d1141d..5f6ee0c6ad7 100644 --- a/homeassistant/components/remote/itach.py +++ b/homeassistant/components/remote/itach.py @@ -102,7 +102,7 @@ class ITachIP2IRRemote(remote.RemoteDevice): self.itachip2ir.send(self._name, "ON", 1) self.schedule_update_ha_state() - def turn_off(self): + def turn_off(self, **kwargs): """Turn the device off.""" self._power = False self.itachip2ir.send(self._name, "OFF", 1) diff --git a/homeassistant/components/remote/services.yaml b/homeassistant/components/remote/services.yaml index ff9cc3d3b16..e59cd709a71 100644 --- a/homeassistant/components/remote/services.yaml +++ b/homeassistant/components/remote/services.yaml @@ -11,6 +11,14 @@ turn_on: description: Activity ID or Activity Name to start example: 'BedroomTV' +toggle: + description: Toggles a device + + fields: + entity_id: + description: Name(s) of entities to toggle + example: 'remote.family_room' + turn_off: description: Sends the Power Off Command