Fix files left behind (#16855)

* Light demo test to not write entity registry

* Fix Manual MQTT alarm control panel
This commit is contained in:
Paulus Schoutsen 2018-09-25 17:19:46 +02:00 committed by GitHub
parent 0dbfd77402
commit 399040de46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 70 deletions

View File

@ -1,7 +1,7 @@
"""The tests for the manual_mqtt Alarm Control Panel component.""" """The tests for the manual_mqtt Alarm Control Panel component."""
from datetime import timedelta from datetime import timedelta
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch, Mock
from homeassistant.setup import setup_component from homeassistant.setup import setup_component
from homeassistant.const import ( from homeassistant.const import (
@ -23,6 +23,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started.""" """Set up things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
self.hass.config_entries._async_schedule_save = Mock()
self.mock_publish = mock_mqtt_component(self.hass) self.mock_publish = mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name def tearDown(self): # pylint: disable=invalid-name

View File

@ -1,81 +1,77 @@
"""The tests for the demo light component.""" """The tests for the demo light component."""
# pylint: disable=protected-access import pytest
import unittest
from homeassistant.setup import setup_component from homeassistant.setup import async_setup_component
import homeassistant.components.light as light from homeassistant.components import light
from tests.common import get_test_home_assistant
ENTITY_LIGHT = 'light.bed_light' ENTITY_LIGHT = 'light.bed_light'
class TestDemoLight(unittest.TestCase): @pytest.fixture(autouse=True)
"""Test the demo light.""" def setup_comp(hass):
"""Set up demo component."""
# pylint: disable=invalid-name hass.loop.run_until_complete(async_setup_component(hass, light.DOMAIN, {
def setUp(self): 'light': {
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.assertTrue(setup_component(self.hass, light.DOMAIN, {'light': {
'platform': 'demo', 'platform': 'demo',
}})) }}))
# pylint: disable=invalid-name
def tearDown(self):
"""Stop down everything that was started."""
self.hass.stop()
def test_state_attributes(self): async def test_state_attributes(hass):
"""Test light state attributes.""" """Test light state attributes."""
light.turn_on( light.async_turn_on(
self.hass, ENTITY_LIGHT, xy_color=(.4, .4), brightness=25) hass, ENTITY_LIGHT, xy_color=(.4, .4), brightness=25)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get(ENTITY_LIGHT) state = hass.states.get(ENTITY_LIGHT)
self.assertTrue(light.is_on(self.hass, ENTITY_LIGHT)) assert light.is_on(hass, ENTITY_LIGHT)
self.assertEqual((0.4, 0.4), state.attributes.get( assert (0.4, 0.4) == state.attributes.get(light.ATTR_XY_COLOR)
light.ATTR_XY_COLOR)) assert 25 == state.attributes.get(light.ATTR_BRIGHTNESS)
self.assertEqual(25, state.attributes.get(light.ATTR_BRIGHTNESS)) assert (255, 234, 164) == state.attributes.get(light.ATTR_RGB_COLOR)
self.assertEqual( assert 'rainbow' == state.attributes.get(light.ATTR_EFFECT)
(255, 234, 164), state.attributes.get(light.ATTR_RGB_COLOR)) light.async_turn_on(
self.assertEqual('rainbow', state.attributes.get(light.ATTR_EFFECT)) hass, ENTITY_LIGHT, rgb_color=(251, 253, 255),
light.turn_on(
self.hass, ENTITY_LIGHT, rgb_color=(251, 253, 255),
white_value=254) white_value=254)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get(ENTITY_LIGHT) state = hass.states.get(ENTITY_LIGHT)
self.assertEqual(254, state.attributes.get(light.ATTR_WHITE_VALUE)) assert 254 == state.attributes.get(light.ATTR_WHITE_VALUE)
self.assertEqual( assert (250, 252, 255) == state.attributes.get(light.ATTR_RGB_COLOR)
(250, 252, 255), state.attributes.get(light.ATTR_RGB_COLOR)) assert (0.319, 0.326) == state.attributes.get(light.ATTR_XY_COLOR)
self.assertEqual( light.async_turn_on(hass, ENTITY_LIGHT, color_temp=400, effect='none')
(0.319, 0.326), state.attributes.get(light.ATTR_XY_COLOR)) await hass.async_block_till_done()
light.turn_on(self.hass, ENTITY_LIGHT, color_temp=400, effect='none') state = hass.states.get(ENTITY_LIGHT)
self.hass.block_till_done() assert 400 == state.attributes.get(light.ATTR_COLOR_TEMP)
state = self.hass.states.get(ENTITY_LIGHT) assert 153 == state.attributes.get(light.ATTR_MIN_MIREDS)
self.assertEqual(400, state.attributes.get(light.ATTR_COLOR_TEMP)) assert 500 == state.attributes.get(light.ATTR_MAX_MIREDS)
self.assertEqual(153, state.attributes.get(light.ATTR_MIN_MIREDS)) assert 'none' == state.attributes.get(light.ATTR_EFFECT)
self.assertEqual(500, state.attributes.get(light.ATTR_MAX_MIREDS)) light.async_turn_on(hass, ENTITY_LIGHT, kelvin=3000, brightness_pct=50)
self.assertEqual('none', state.attributes.get(light.ATTR_EFFECT)) await hass.async_block_till_done()
light.turn_on(self.hass, ENTITY_LIGHT, kelvin=3000, brightness_pct=50) state = hass.states.get(ENTITY_LIGHT)
self.hass.block_till_done() assert 333 == state.attributes.get(light.ATTR_COLOR_TEMP)
state = self.hass.states.get(ENTITY_LIGHT) assert 127 == state.attributes.get(light.ATTR_BRIGHTNESS)
self.assertEqual(333, state.attributes.get(light.ATTR_COLOR_TEMP))
self.assertEqual(127, state.attributes.get(light.ATTR_BRIGHTNESS))
def test_turn_off(self):
async def test_turn_off(hass):
"""Test light turn off method.""" """Test light turn off method."""
light.turn_on(self.hass, ENTITY_LIGHT) await hass.services.async_call('light', 'turn_on', {
self.hass.block_till_done() 'entity_id': ENTITY_LIGHT
self.assertTrue(light.is_on(self.hass, ENTITY_LIGHT)) }, blocking=True)
light.turn_off(self.hass, ENTITY_LIGHT)
self.hass.block_till_done()
self.assertFalse(light.is_on(self.hass, ENTITY_LIGHT))
def test_turn_off_without_entity_id(self): assert light.is_on(hass, ENTITY_LIGHT)
await hass.services.async_call('light', 'turn_off', {
'entity_id': ENTITY_LIGHT
}, blocking=True)
assert not light.is_on(hass, ENTITY_LIGHT)
async def test_turn_off_without_entity_id(hass):
"""Test light turn off all lights.""" """Test light turn off all lights."""
light.turn_on(self.hass, ENTITY_LIGHT) await hass.services.async_call('light', 'turn_on', {
self.hass.block_till_done() }, blocking=True)
self.assertTrue(light.is_on(self.hass, ENTITY_LIGHT))
light.turn_off(self.hass) assert light.is_on(hass, ENTITY_LIGHT)
self.hass.block_till_done()
self.assertFalse(light.is_on(self.hass, ENTITY_LIGHT)) await hass.services.async_call('light', 'turn_off', {
}, blocking=True)
assert not light.is_on(hass, ENTITY_LIGHT)