Remove service helper (4) (#16892)

* Update media_player

* Update lock

* Update notify

* Update remote

* Update scene

* Update vacuum

* Remove timer helpers

* Removed unused legacy helpers
This commit is contained in:
cdce8p authored and Paulus Schoutsen committed 2018-09-26 18:02:05 +02:00
1 parent d0ddc28f96
commit dd45e99302
23 files changed
+499 -520

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
"""Collection of helper methods.
All containing methods are legacy helpers that should not be used by new
components. Instead call the service directly.
"""
from homeassistant.components.remote import (
ATTR_ACTIVITY, ATTR_COMMAND, ATTR_DELAY_SECS, ATTR_DEVICE,
ATTR_NUM_REPEATS, DOMAIN, SERVICE_SEND_COMMAND)
from homeassistant.const import (
ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON)
from homeassistant.loader import bind_hass
@bind_hass
def turn_on(hass, activity=None, entity_id=None):
"""Turn all or specified remote on."""
data = {
key: value for key, value in [
(ATTR_ACTIVITY, activity),
(ATTR_ENTITY_ID, entity_id),
] if value is not None}
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
@bind_hass
def turn_off(hass, activity=None, entity_id=None):
"""Turn all or specified remote off."""
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 send_command(hass, command, entity_id=None, device=None,
num_repeats=None, delay_secs=None):
"""Send a command to a device."""
data = {ATTR_COMMAND: command}
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
if device:
data[ATTR_DEVICE] = device
if num_repeats:
data[ATTR_NUM_REPEATS] = num_repeats
if delay_secs:
data[ATTR_DELAY_SECS] = delay_secs
hass.services.call(DOMAIN, SERVICE_SEND_COMMAND, data)
+6 -4
View File
@@ -5,7 +5,9 @@ import unittest
from homeassistant.setup import setup_component
import homeassistant.components.remote as remote
from homeassistant.const import STATE_ON, STATE_OFF
from tests.common import get_test_home_assistant
from tests.components.remote import common
ENTITY_ID = 'remote.remote_one'
@@ -28,22 +30,22 @@ class TestDemoRemote(unittest.TestCase):
def test_methods(self):
"""Test if services call the entity methods as expected."""
remote.turn_on(self.hass, entity_id=ENTITY_ID)
common.turn_on(self.hass, entity_id=ENTITY_ID)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ID)
self.assertEqual(state.state, STATE_ON)
remote.turn_off(self.hass, entity_id=ENTITY_ID)
common.turn_off(self.hass, entity_id=ENTITY_ID)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ID)
self.assertEqual(state.state, STATE_OFF)
remote.turn_on(self.hass, entity_id=ENTITY_ID)
common.turn_on(self.hass, entity_id=ENTITY_ID)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ID)
self.assertEqual(state.state, STATE_ON)
remote.send_command(self.hass, 'test', entity_id=ENTITY_ID)
common.send_command(self.hass, 'test', entity_id=ENTITY_ID)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ID)
self.assertEqual(
+5 -3
View File
@@ -10,6 +10,8 @@ from homeassistant.const import (
import homeassistant.components.remote as remote
from tests.common import mock_service, get_test_home_assistant
from tests.components.remote import common
TEST_PLATFORM = {remote.DOMAIN: {CONF_PLATFORM: 'test'}}
SERVICE_SEND_COMMAND = 'send_command'
@@ -46,7 +48,7 @@ class TestRemote(unittest.TestCase):
turn_on_calls = mock_service(
self.hass, remote.DOMAIN, SERVICE_TURN_ON)
remote.turn_on(
common.turn_on(
self.hass,
entity_id='entity_id_val')
@@ -62,7 +64,7 @@ class TestRemote(unittest.TestCase):
turn_off_calls = mock_service(
self.hass, remote.DOMAIN, SERVICE_TURN_OFF)
remote.turn_off(
common.turn_off(
self.hass, entity_id='entity_id_val')
self.hass.block_till_done()
@@ -79,7 +81,7 @@ class TestRemote(unittest.TestCase):
send_command_calls = mock_service(
self.hass, remote.DOMAIN, SERVICE_SEND_COMMAND)
remote.send_command(
common.send_command(
self.hass, entity_id='entity_id_val',
device='test_device', command=['test_command'],
num_repeats='4', delay_secs='0.6')