core/tests/components/remote/test_demo.py

99 lines
3.1 KiB
Python
Raw Normal View History

Remote Component and Harmony Platform (#4254) * Initial Harmony device support, working current activity sensor and switch for each activity TODO: add new device per hub to send device specific activity Changes to be committed: new file: homeassistant/components/harmony.py new file: homeassistant/components/sensor/harmony.py new file: homeassistant/components/switch/harmony.py * ready for beta, I think Changes to be committed: modified: homeassistant/components/harmony.py modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py * Changes to be committed: modified: homeassistant/components/harmony.py new file: homeassistant/components/remote/__init__.py new file: homeassistant/components/remote/harmony.py new file: homeassistant/components/remote/services.yaml modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py Implemented remote component and harmony platform * streamlined harmony support * typo * Initial Harmony device support, working current activity sensor and switch for each activity TODO: add new device per hub to send device specific activity Changes to be committed: new file: homeassistant/components/harmony.py new file: homeassistant/components/sensor/harmony.py new file: homeassistant/components/switch/harmony.py * ready for beta, I think Changes to be committed: modified: homeassistant/components/harmony.py modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py * Changes to be committed: modified: homeassistant/components/harmony.py new file: homeassistant/components/remote/__init__.py new file: homeassistant/components/remote/harmony.py new file: homeassistant/components/remote/services.yaml modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py Implemented remote component and harmony platform * streamlined harmony support * typo * reworked token generation * delete * Initial Harmony device support, working current activity sensor and switch for each activity TODO: add new device per hub to send device specific activity Changes to be committed: new file: homeassistant/components/harmony.py new file: homeassistant/components/sensor/harmony.py new file: homeassistant/components/switch/harmony.py * Initial Harmony device support, working current activity sensor and switch for each activity TODO: add new device per hub to send device specific activity Changes to be committed: new file: homeassistant/components/harmony.py new file: homeassistant/components/sensor/harmony.py new file: homeassistant/components/switch/harmony.py * ready for beta, I think Changes to be committed: modified: homeassistant/components/harmony.py modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py * ready for beta, I think Changes to be committed: modified: homeassistant/components/harmony.py modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py * Changes to be committed: modified: homeassistant/components/harmony.py new file: homeassistant/components/remote/__init__.py new file: homeassistant/components/remote/harmony.py new file: homeassistant/components/remote/services.yaml modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py Implemented remote component and harmony platform * streamlined harmony support * typo * reworked token generation * delete * readded after rebase * cleaning up style errors * modified .coveragerc * moved import statements * added more debug logging * Added URL encoding of token received from Logitech * Corrected import for python 3 * new pyharmony version * new pyharmony version * remote tests * only write config file if not present or sync service is called * more tests * more tests * bumped pyharmony version to work with new auth * bumped pyharmony version to work with new auth * style corrections * harmony local auth and remote demo platform * style fix * PR refinements and permission issues * forgot a blank line * removed sync test from test_init * removed sync test from test_init * visual indent * send_command test in demo platform
2016-12-01 20:48:08 +00:00
"""The tests for the demo remote component."""
# pylint: disable=protected-access
import unittest
from homeassistant.setup import setup_component
Remote Component and Harmony Platform (#4254) * Initial Harmony device support, working current activity sensor and switch for each activity TODO: add new device per hub to send device specific activity Changes to be committed: new file: homeassistant/components/harmony.py new file: homeassistant/components/sensor/harmony.py new file: homeassistant/components/switch/harmony.py * ready for beta, I think Changes to be committed: modified: homeassistant/components/harmony.py modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py * Changes to be committed: modified: homeassistant/components/harmony.py new file: homeassistant/components/remote/__init__.py new file: homeassistant/components/remote/harmony.py new file: homeassistant/components/remote/services.yaml modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py Implemented remote component and harmony platform * streamlined harmony support * typo * Initial Harmony device support, working current activity sensor and switch for each activity TODO: add new device per hub to send device specific activity Changes to be committed: new file: homeassistant/components/harmony.py new file: homeassistant/components/sensor/harmony.py new file: homeassistant/components/switch/harmony.py * ready for beta, I think Changes to be committed: modified: homeassistant/components/harmony.py modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py * Changes to be committed: modified: homeassistant/components/harmony.py new file: homeassistant/components/remote/__init__.py new file: homeassistant/components/remote/harmony.py new file: homeassistant/components/remote/services.yaml modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py Implemented remote component and harmony platform * streamlined harmony support * typo * reworked token generation * delete * Initial Harmony device support, working current activity sensor and switch for each activity TODO: add new device per hub to send device specific activity Changes to be committed: new file: homeassistant/components/harmony.py new file: homeassistant/components/sensor/harmony.py new file: homeassistant/components/switch/harmony.py * Initial Harmony device support, working current activity sensor and switch for each activity TODO: add new device per hub to send device specific activity Changes to be committed: new file: homeassistant/components/harmony.py new file: homeassistant/components/sensor/harmony.py new file: homeassistant/components/switch/harmony.py * ready for beta, I think Changes to be committed: modified: homeassistant/components/harmony.py modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py * ready for beta, I think Changes to be committed: modified: homeassistant/components/harmony.py modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py * Changes to be committed: modified: homeassistant/components/harmony.py new file: homeassistant/components/remote/__init__.py new file: homeassistant/components/remote/harmony.py new file: homeassistant/components/remote/services.yaml modified: homeassistant/components/sensor/harmony.py modified: homeassistant/components/switch/harmony.py Implemented remote component and harmony platform * streamlined harmony support * typo * reworked token generation * delete * readded after rebase * cleaning up style errors * modified .coveragerc * moved import statements * added more debug logging * Added URL encoding of token received from Logitech * Corrected import for python 3 * new pyharmony version * new pyharmony version * remote tests * only write config file if not present or sync service is called * more tests * more tests * bumped pyharmony version to work with new auth * bumped pyharmony version to work with new auth * style corrections * harmony local auth and remote demo platform * style fix * PR refinements and permission issues * forgot a blank line * removed sync test from test_init * removed sync test from test_init * visual indent * send_command test in demo platform
2016-12-01 20:48:08 +00:00
import homeassistant.components.remote as remote
from homeassistant.const import (
ATTR_ENTITY_ID, STATE_ON, STATE_OFF, CONF_PLATFORM,
SERVICE_TURN_ON, SERVICE_TURN_OFF)
from tests.common import get_test_home_assistant, mock_service
SERVICE_SEND_COMMAND = 'send_command'
class TestDemoRemote(unittest.TestCase):
"""Test the demo remote."""
# pylint: disable=invalid-name
def setUp(self):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.assertTrue(setup_component(self.hass, remote.DOMAIN, {'remote': {
'platform': 'demo',
}}))
# pylint: disable=invalid-name
def tearDown(self):
"""Stop down everything that was started."""
self.hass.stop()
def test_methods(self):
"""Test if methods call the services as expected."""
self.assertTrue(
setup_component(self.hass, remote.DOMAIN,
{remote.DOMAIN: {CONF_PLATFORM: 'demo'}}))
# Test is_on
self.hass.states.set('remote.demo', STATE_ON)
self.assertTrue(remote.is_on(self.hass, 'remote.demo'))
self.hass.states.set('remote.demo', STATE_OFF)
self.assertFalse(remote.is_on(self.hass, 'remote.demo'))
self.hass.states.set(remote.ENTITY_ID_ALL_REMOTES, STATE_ON)
self.assertTrue(remote.is_on(self.hass))
self.hass.states.set(remote.ENTITY_ID_ALL_REMOTES, STATE_OFF)
self.assertFalse(remote.is_on(self.hass))
def test_services(self):
"""Test the provided services."""
# Test turn_on
turn_on_calls = mock_service(
self.hass, remote.DOMAIN, SERVICE_TURN_ON)
remote.turn_on(
self.hass,
entity_id='entity_id_val')
self.hass.block_till_done()
self.assertEqual(1, len(turn_on_calls))
call = turn_on_calls[-1]
self.assertEqual(remote.DOMAIN, call.domain)
# Test turn_off
turn_off_calls = mock_service(
self.hass, remote.DOMAIN, SERVICE_TURN_OFF)
remote.turn_off(
self.hass, entity_id='entity_id_val')
self.hass.block_till_done()
self.assertEqual(1, len(turn_off_calls))
call = turn_off_calls[-1]
self.assertEqual(remote.DOMAIN, call.domain)
self.assertEqual(SERVICE_TURN_OFF, call.service)
self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])
# Test send_command
send_command_calls = mock_service(
self.hass, remote.DOMAIN, SERVICE_SEND_COMMAND)
remote.send_command(
self.hass, entity_id='entity_id_val',
device='test_device', command='test_command')
self.hass.block_till_done()
self.assertEqual(1, len(send_command_calls))
call = send_command_calls[-1]
self.assertEqual(remote.DOMAIN, call.domain)
self.assertEqual(SERVICE_SEND_COMMAND, call.service)
self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])