77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
"""
|
|
tests.test_component_demo
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
Tests demo component.
|
|
"""
|
|
# pylint: disable=too-many-public-methods,protected-access
|
|
import unittest
|
|
|
|
import homeassistant as ha
|
|
import homeassistant.components.demo as demo
|
|
from homeassistant.const import (
|
|
SERVICE_TURN_ON, SERVICE_TURN_OFF, STATE_ON, STATE_OFF, ATTR_ENTITY_ID)
|
|
|
|
|
|
class TestDemo(unittest.TestCase):
|
|
""" Test the demo module. """
|
|
|
|
def setUp(self): # pylint: disable=invalid-name
|
|
self.hass = ha.HomeAssistant()
|
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
|
""" Stop down stuff we started. """
|
|
self.hass.stop()
|
|
|
|
def test_services(self):
|
|
""" Test the demo services. """
|
|
# Test turning on and off different types
|
|
demo.setup(self.hass, {})
|
|
|
|
for domain in ('light', 'switch'):
|
|
# Focus on 1 entity
|
|
entity_id = self.hass.states.entity_ids(domain)[0]
|
|
|
|
self.hass.services.call(
|
|
domain, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.assertEqual(STATE_ON, self.hass.states.get(entity_id).state)
|
|
|
|
self.hass.services.call(
|
|
domain, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.assertEqual(STATE_OFF, self.hass.states.get(entity_id).state)
|
|
|
|
# Act on all
|
|
self.hass.services.call(domain, SERVICE_TURN_ON)
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
for entity_id in self.hass.states.entity_ids(domain):
|
|
self.assertEqual(
|
|
STATE_ON, self.hass.states.get(entity_id).state)
|
|
|
|
self.hass.services.call(domain, SERVICE_TURN_OFF)
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
for entity_id in self.hass.states.entity_ids(domain):
|
|
self.assertEqual(
|
|
STATE_OFF, self.hass.states.get(entity_id).state)
|
|
|
|
def test_if_demo_state_shows_by_default(self):
|
|
""" Test if demo state shows if we give no configuration. """
|
|
demo.setup(self.hass, {demo.DOMAIN: {}})
|
|
|
|
self.assertIsNotNone(self.hass.states.get('a.Demo_Mode'))
|
|
|
|
def test_hiding_demo_state(self):
|
|
""" Test if you can hide the demo card. """
|
|
demo.setup(self.hass, {demo.DOMAIN: {'hide_demo_state': 1}})
|
|
|
|
self.assertIsNone(self.hass.states.get('a.Demo_Mode'))
|