hass-core/tests/components/demo/test_remote.py
Felipe Martins Diel 0ed9e185b2 Add support for learning new commands (#23888)
* Add support for learning new commands

This update creates a generic service in the 'remote' component to enable remote control platforms to learn new commands.

* Update __init__.py with the proposed changes

- Add 'supported_features' property and a constant related to the 'learn_command' functionality.
- Redefine 'async_learn_command' function as a coroutine.

* Update __init__.py

* Fix assertion error

Adding the 'supported_features' attribute generated an assertion error on the 'Demo Remote' platform. This update fixes this.

* Fix duplicated 'hass' object

This update fixes a typo that occurred at the last update.
2019-06-05 11:32:59 +02:00

55 lines
1.8 KiB
Python

"""The tests for the demo remote component."""
# pylint: disable=protected-access
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'
class TestDemoRemote(unittest.TestCase):
"""Test the demo remote."""
# pylint: disable=invalid-name
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
assert 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 services call the entity methods as expected."""
common.turn_on(self.hass, entity_id=ENTITY_ID)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ID)
assert state.state == STATE_ON
common.turn_off(self.hass, entity_id=ENTITY_ID)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ID)
assert state.state == STATE_OFF
common.turn_on(self.hass, entity_id=ENTITY_ID)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ID)
assert state.state == STATE_ON
common.send_command(self.hass, 'test', entity_id=ENTITY_ID)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ID)
assert state.attributes == {
'friendly_name': 'Remote One',
'last_command_sent': 'test',
'supported_features': 0
}