RFC: Call services directly (#18720)
* Call services directly * Simplify * Type * Lint * Update name * Fix tests * Catch exceptions in HTTP view * Lint * Handle ServiceNotFound in API endpoints that call services * Type * Don't crash recorder on non-JSON serializable objects
This commit is contained in:
1 parent
53cbb28926
commit
df21dd21f2
30 files changed
+312
-186
No files matched your search
@@ -1,6 +1,9 @@
|
||||
"""The tests for the demo climate component."""
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.util.unit_system import (
|
||||
METRIC_SYSTEM
|
||||
)
|
||||
@@ -57,7 +60,8 @@ class TestDemoClimate(unittest.TestCase):
|
||||
"""Test setting the target temperature without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert 21 == state.attributes.get('temperature')
|
||||
common.set_temperature(self.hass, None, ENTITY_CLIMATE)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_temperature(self.hass, None, ENTITY_CLIMATE)
|
||||
self.hass.block_till_done()
|
||||
assert 21 == state.attributes.get('temperature')
|
||||
|
||||
@@ -99,9 +103,11 @@ class TestDemoClimate(unittest.TestCase):
|
||||
assert state.attributes.get('temperature') is None
|
||||
assert 21.0 == state.attributes.get('target_temp_low')
|
||||
assert 24.0 == state.attributes.get('target_temp_high')
|
||||
common.set_temperature(self.hass, temperature=None,
|
||||
entity_id=ENTITY_ECOBEE, target_temp_low=None,
|
||||
target_temp_high=None)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_temperature(self.hass, temperature=None,
|
||||
entity_id=ENTITY_ECOBEE,
|
||||
target_temp_low=None,
|
||||
target_temp_high=None)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||
assert state.attributes.get('temperature') is None
|
||||
@@ -112,7 +118,8 @@ class TestDemoClimate(unittest.TestCase):
|
||||
"""Test setting the target humidity without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert 67 == state.attributes.get('humidity')
|
||||
common.set_humidity(self.hass, None, ENTITY_CLIMATE)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_humidity(self.hass, None, ENTITY_CLIMATE)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert 67 == state.attributes.get('humidity')
|
||||
@@ -130,7 +137,8 @@ class TestDemoClimate(unittest.TestCase):
|
||||
"""Test setting fan mode without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "On High" == state.attributes.get('fan_mode')
|
||||
common.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "On High" == state.attributes.get('fan_mode')
|
||||
@@ -148,7 +156,8 @@ class TestDemoClimate(unittest.TestCase):
|
||||
"""Test setting swing mode without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "Off" == state.attributes.get('swing_mode')
|
||||
common.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "Off" == state.attributes.get('swing_mode')
|
||||
@@ -170,7 +179,8 @@ class TestDemoClimate(unittest.TestCase):
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "cool" == state.attributes.get('operation_mode')
|
||||
assert "cool" == state.state
|
||||
common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "cool" == state.attributes.get('operation_mode')
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""The tests for the climate component."""
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.climate import SET_TEMPERATURE_SCHEMA
|
||||
from tests.common import async_mock_service
|
||||
|
||||
@@ -14,12 +17,11 @@ def test_set_temp_schema_no_req(hass, caplog):
|
||||
calls = async_mock_service(hass, domain, service, schema)
|
||||
|
||||
data = {'operation_mode': 'test', 'entity_id': ['climate.test_id']}
|
||||
yield from hass.services.async_call(domain, service, data)
|
||||
with pytest.raises(vol.Invalid):
|
||||
yield from hass.services.async_call(domain, service, data)
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 0
|
||||
assert 'ERROR' in caplog.text
|
||||
assert 'Invalid service data' in caplog.text
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
import unittest
|
||||
import copy
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.util.unit_system import (
|
||||
METRIC_SYSTEM
|
||||
)
|
||||
@@ -91,7 +94,8 @@ class TestMQTTClimate(unittest.TestCase):
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('operation_mode')
|
||||
assert "off" == state.state
|
||||
common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('operation_mode')
|
||||
@@ -177,7 +181,8 @@ class TestMQTTClimate(unittest.TestCase):
|
||||
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "low" == state.attributes.get('fan_mode')
|
||||
common.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "low" == state.attributes.get('fan_mode')
|
||||
@@ -225,7 +230,8 @@ class TestMQTTClimate(unittest.TestCase):
|
||||
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('swing_mode')
|
||||
common.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('swing_mode')
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""Test deCONZ component setup process."""
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import deconz
|
||||
|
||||
@@ -163,11 +166,13 @@ async def test_service_configure(hass):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# field does not start with /
|
||||
with patch('pydeconz.DeconzSession.async_put_state',
|
||||
return_value=mock_coro(True)):
|
||||
await hass.services.async_call('deconz', 'configure', service_data={
|
||||
'entity': 'light.test', 'field': 'state', 'data': data})
|
||||
await hass.async_block_till_done()
|
||||
with pytest.raises(vol.Invalid):
|
||||
with patch('pydeconz.DeconzSession.async_put_state',
|
||||
return_value=mock_coro(True)):
|
||||
await hass.services.async_call(
|
||||
'deconz', 'configure', service_data={
|
||||
'entity': 'light.test', 'field': 'state', 'data': data})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_service_refresh_devices(hass):
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
"""Tests for Home Assistant View."""
|
||||
from aiohttp.web_exceptions import HTTPInternalServerError
|
||||
import pytest
|
||||
from unittest.mock import Mock
|
||||
|
||||
from homeassistant.components.http.view import HomeAssistantView
|
||||
from aiohttp.web_exceptions import (
|
||||
HTTPInternalServerError, HTTPBadRequest, HTTPUnauthorized)
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.http.view import (
|
||||
HomeAssistantView, request_handler_factory)
|
||||
from homeassistant.exceptions import ServiceNotFound, Unauthorized
|
||||
|
||||
from tests.common import mock_coro_func
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_request():
|
||||
"""Mock a request."""
|
||||
return Mock(
|
||||
app={'hass': Mock(is_running=True)},
|
||||
match_info={},
|
||||
)
|
||||
|
||||
|
||||
async def test_invalid_json(caplog):
|
||||
@@ -13,3 +30,30 @@ async def test_invalid_json(caplog):
|
||||
view.json(float("NaN"))
|
||||
|
||||
assert str(float("NaN")) in caplog.text
|
||||
|
||||
|
||||
async def test_handling_unauthorized(mock_request):
|
||||
"""Test handling unauth exceptions."""
|
||||
with pytest.raises(HTTPUnauthorized):
|
||||
await request_handler_factory(
|
||||
Mock(requires_auth=False),
|
||||
mock_coro_func(exception=Unauthorized)
|
||||
)(mock_request)
|
||||
|
||||
|
||||
async def test_handling_invalid_data(mock_request):
|
||||
"""Test handling unauth exceptions."""
|
||||
with pytest.raises(HTTPBadRequest):
|
||||
await request_handler_factory(
|
||||
Mock(requires_auth=False),
|
||||
mock_coro_func(exception=vol.Invalid('yo'))
|
||||
)(mock_request)
|
||||
|
||||
|
||||
async def test_handling_service_not_found(mock_request):
|
||||
"""Test handling unauth exceptions."""
|
||||
with pytest.raises(HTTPInternalServerError):
|
||||
await request_handler_factory(
|
||||
Mock(requires_auth=False),
|
||||
mock_coro_func(exception=ServiceNotFound('test', 'test'))
|
||||
)(mock_request)
|
||||
@@ -3,6 +3,9 @@ import unittest
|
||||
from unittest.mock import patch
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.const import HTTP_HEADER_HA_AUTH
|
||||
import homeassistant.components.media_player as mp
|
||||
@@ -43,7 +46,8 @@ class TestDemoMediaPlayer(unittest.TestCase):
|
||||
state = self.hass.states.get(entity_id)
|
||||
assert 'dvd' == state.attributes.get('source')
|
||||
|
||||
common.select_source(self.hass, None, entity_id)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.select_source(self.hass, None, entity_id)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(entity_id)
|
||||
assert 'dvd' == state.attributes.get('source')
|
||||
@@ -72,7 +76,8 @@ class TestDemoMediaPlayer(unittest.TestCase):
|
||||
state = self.hass.states.get(entity_id)
|
||||
assert 1.0 == state.attributes.get('volume_level')
|
||||
|
||||
common.set_volume_level(self.hass, None, entity_id)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_volume_level(self.hass, None, entity_id)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(entity_id)
|
||||
assert 1.0 == state.attributes.get('volume_level')
|
||||
@@ -201,7 +206,8 @@ class TestDemoMediaPlayer(unittest.TestCase):
|
||||
state.attributes.get('supported_features'))
|
||||
assert state.attributes.get('media_content_id') is not None
|
||||
|
||||
common.play_media(self.hass, None, 'some_id', ent_id)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.play_media(self.hass, None, 'some_id', ent_id)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ent_id)
|
||||
assert 0 < (mp.SUPPORT_PLAY_MEDIA &
|
||||
@@ -216,7 +222,8 @@ class TestDemoMediaPlayer(unittest.TestCase):
|
||||
assert 'some_id' == state.attributes.get('media_content_id')
|
||||
|
||||
assert not mock_seek.called
|
||||
common.media_seek(self.hass, None, ent_id)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.media_seek(self.hass, None, ent_id)
|
||||
self.hass.block_till_done()
|
||||
assert not mock_seek.called
|
||||
common.media_seek(self.hass, 100, ent_id)
|
||||
|
||||
@@ -223,7 +223,7 @@ class TestMonopriceMediaPlayer(unittest.TestCase):
|
||||
# Restoring wrong media player to its previous state
|
||||
# Nothing should be done
|
||||
self.hass.services.call(DOMAIN, SERVICE_RESTORE,
|
||||
{'entity_id': 'not_existing'},
|
||||
{'entity_id': 'media.not_existing'},
|
||||
blocking=True)
|
||||
# self.hass.block_till_done()
|
||||
|
||||
|
||||
@@ -113,11 +113,12 @@ class TestMQTTComponent(unittest.TestCase):
|
||||
"""
|
||||
payload = "not a template"
|
||||
payload_template = "a template"
|
||||
self.hass.services.call(mqtt.DOMAIN, mqtt.SERVICE_PUBLISH, {
|
||||
mqtt.ATTR_TOPIC: "test/topic",
|
||||
mqtt.ATTR_PAYLOAD: payload,
|
||||
mqtt.ATTR_PAYLOAD_TEMPLATE: payload_template
|
||||
}, blocking=True)
|
||||
with pytest.raises(vol.Invalid):
|
||||
self.hass.services.call(mqtt.DOMAIN, mqtt.SERVICE_PUBLISH, {
|
||||
mqtt.ATTR_TOPIC: "test/topic",
|
||||
mqtt.ATTR_PAYLOAD: payload,
|
||||
mqtt.ATTR_PAYLOAD_TEMPLATE: payload_template
|
||||
}, blocking=True)
|
||||
assert not self.hass.data['mqtt'].async_publish.called
|
||||
|
||||
def test_service_call_with_ascii_qos_retain_flags(self):
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.components.notify as notify
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.components.notify import demo
|
||||
@@ -81,7 +84,8 @@ class TestNotifyDemo(unittest.TestCase):
|
||||
def test_sending_none_message(self):
|
||||
"""Test send with None as message."""
|
||||
self._setup_notify()
|
||||
common.send_message(self.hass, None)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.send_message(self.hass, None)
|
||||
self.hass.block_till_done()
|
||||
assert len(self.events) == 0
|
||||
|
||||
|
||||
@@ -99,6 +99,7 @@ class TestAlert(unittest.TestCase):
|
||||
def setUp(self):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self._setup_notify()
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
|
||||
@@ -6,6 +6,7 @@ from unittest.mock import patch
|
||||
|
||||
from aiohttp import web
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import const
|
||||
from homeassistant.bootstrap import DATA_LOGGING
|
||||
@@ -578,3 +579,29 @@ async def test_rendering_template_legacy_user(
|
||||
json={"template": '{{ states.sensor.temperature.state }}'}
|
||||
)
|
||||
assert resp.status == 401
|
||||
|
||||
|
||||
async def test_api_call_service_not_found(hass, mock_api_client):
|
||||
"""Test if the API failes 400 if unknown service."""
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_SERVICES_SERVICE.format(
|
||||
"test_domain", "test_service"))
|
||||
assert resp.status == 400
|
||||
|
||||
|
||||
async def test_api_call_service_bad_data(hass, mock_api_client):
|
||||
"""Test if the API failes 400 if unknown service."""
|
||||
test_value = []
|
||||
|
||||
@ha.callback
|
||||
def listener(service_call):
|
||||
"""Record that our service got called."""
|
||||
test_value.append(1)
|
||||
|
||||
hass.services.async_register("test_domain", "test_service", listener,
|
||||
schema=vol.Schema({'hello': str}))
|
||||
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_SERVICES_SERVICE.format(
|
||||
"test_domain", "test_service"), json={'hello': 5})
|
||||
assert resp.status == 400
|
||||
@@ -3,6 +3,9 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.core import CoreState, State, Context
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.input_datetime import (
|
||||
@@ -109,10 +112,11 @@ def test_set_invalid(hass):
|
||||
dt_obj = datetime.datetime(2017, 9, 7, 19, 46)
|
||||
time_portion = dt_obj.time()
|
||||
|
||||
yield from hass.services.async_call('input_datetime', 'set_datetime', {
|
||||
'entity_id': 'test_date',
|
||||
'time': time_portion
|
||||
})
|
||||
with pytest.raises(vol.Invalid):
|
||||
yield from hass.services.async_call('input_datetime', 'set_datetime', {
|
||||
'entity_id': 'test_date',
|
||||
'time': time_portion
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
@@ -4,6 +4,9 @@ import logging
|
||||
from datetime import (timedelta, datetime)
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import sun
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.const import (
|
||||
@@ -89,7 +92,9 @@ class TestComponentLogbook(unittest.TestCase):
|
||||
calls.append(event)
|
||||
|
||||
self.hass.bus.listen(logbook.EVENT_LOGBOOK_ENTRY, event_listener)
|
||||
self.hass.services.call(logbook.DOMAIN, 'log', {}, True)
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
self.hass.services.call(logbook.DOMAIN, 'log', {}, True)
|
||||
|
||||
# Logbook entry service call results in firing an event.
|
||||
# Our service call will unblock when the event listeners have been
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.mqtt import MQTT_PUBLISH_SCHEMA
|
||||
import homeassistant.components.snips as snips
|
||||
@@ -452,12 +455,11 @@ async def test_snips_say_invalid_config(hass, caplog):
|
||||
snips.SERVICE_SCHEMA_SAY)
|
||||
|
||||
data = {'text': 'Hello', 'badKey': 'boo'}
|
||||
await hass.services.async_call('snips', 'say', data)
|
||||
with pytest.raises(vol.Invalid):
|
||||
await hass.services.async_call('snips', 'say', data)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 0
|
||||
assert 'ERROR' in caplog.text
|
||||
assert 'Invalid service data' in caplog.text
|
||||
|
||||
|
||||
async def test_snips_say_action_invalid(hass, caplog):
|
||||
@@ -466,12 +468,12 @@ async def test_snips_say_action_invalid(hass, caplog):
|
||||
snips.SERVICE_SCHEMA_SAY_ACTION)
|
||||
|
||||
data = {'text': 'Hello', 'can_be_enqueued': 'notabool'}
|
||||
await hass.services.async_call('snips', 'say_action', data)
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
await hass.services.async_call('snips', 'say_action', data)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 0
|
||||
assert 'ERROR' in caplog.text
|
||||
assert 'Invalid service data' in caplog.text
|
||||
|
||||
|
||||
async def test_snips_feedback_on(hass, caplog):
|
||||
@@ -510,7 +512,8 @@ async def test_snips_feedback_config(hass, caplog):
|
||||
snips.SERVICE_SCHEMA_FEEDBACK)
|
||||
|
||||
data = {'site_id': 'remote', 'test': 'test'}
|
||||
await hass.services.async_call('snips', 'feedback_on', data)
|
||||
with pytest.raises(vol.Invalid):
|
||||
await hass.services.async_call('snips', 'feedback_on', data)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 0
|
||||
@@ -3,6 +3,7 @@ import asyncio
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.wake_on_lan import (
|
||||
@@ -34,10 +35,10 @@ def test_send_magic_packet(hass, caplog, mock_wakeonlan):
|
||||
assert mock_wakeonlan.mock_calls[-1][1][0] == mac
|
||||
assert mock_wakeonlan.mock_calls[-1][2]['ip_address'] == bc_ip
|
||||
|
||||
yield from hass.services.async_call(
|
||||
DOMAIN, SERVICE_SEND_MAGIC_PACKET,
|
||||
{"broadcast_address": bc_ip}, blocking=True)
|
||||
assert 'ERROR' in caplog.text
|
||||
with pytest.raises(vol.Invalid):
|
||||
yield from hass.services.async_call(
|
||||
DOMAIN, SERVICE_SEND_MAGIC_PACKET,
|
||||
{"broadcast_address": bc_ip}, blocking=True)
|
||||
assert len(mock_wakeonlan.mock_calls) == 1
|
||||
|
||||
yield from hass.services.async_call(
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""The tests for the demo water_heater component."""
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.util.unit_system import (
|
||||
IMPERIAL_SYSTEM
|
||||
)
|
||||
@@ -48,7 +51,8 @@ class TestDemowater_heater(unittest.TestCase):
|
||||
"""Test setting the target temperature without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
assert 119 == state.attributes.get('temperature')
|
||||
common.set_temperature(self.hass, None, ENTITY_WATER_HEATER)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_temperature(self.hass, None, ENTITY_WATER_HEATER)
|
||||
self.hass.block_till_done()
|
||||
assert 119 == state.attributes.get('temperature')
|
||||
|
||||
@@ -69,7 +73,8 @@ class TestDemowater_heater(unittest.TestCase):
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
assert "eco" == state.attributes.get('operation_mode')
|
||||
assert "eco" == state.state
|
||||
common.set_operation_mode(self.hass, None, ENTITY_WATER_HEATER)
|
||||
with pytest.raises(vol.Invalid):
|
||||
common.set_operation_mode(self.hass, None, ENTITY_WATER_HEATER)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
assert "eco" == state.attributes.get('operation_mode')
|
||||
|
||||
@@ -49,6 +49,25 @@ async def test_call_service(hass, websocket_client):
|
||||
assert call.data == {'hello': 'world'}
|
||||
|
||||
|
||||
async def test_call_service_not_found(hass, websocket_client):
|
||||
"""Test call service command."""
|
||||
await websocket_client.send_json({
|
||||
'id': 5,
|
||||
'type': commands.TYPE_CALL_SERVICE,
|
||||
'domain': 'domain_test',
|
||||
'service': 'test_service',
|
||||
'service_data': {
|
||||
'hello': 'world'
|
||||
}
|
||||
})
|
||||
|
||||
msg = await websocket_client.receive_json()
|
||||
assert msg['id'] == 5
|
||||
assert msg['type'] == const.TYPE_RESULT
|
||||
assert not msg['success']
|
||||
assert msg['error']['code'] == const.ERR_NOT_FOUND
|
||||
|
||||
|
||||
async def test_subscribe_unsubscribe_events(hass, websocket_client):
|
||||
"""Test subscribe/unsubscribe events command."""
|
||||
init_count = sum(hass.bus.async_listeners().values())
|
||||
|
||||
@@ -947,7 +947,7 @@ class TestZWaveServices(unittest.TestCase):
|
||||
assert self.zwave_network.stop.called
|
||||
assert len(self.zwave_network.stop.mock_calls) == 1
|
||||
assert mock_fire.called
|
||||
assert len(mock_fire.mock_calls) == 2
|
||||
assert len(mock_fire.mock_calls) == 1
|
||||
assert mock_fire.mock_calls[0][1][0] == const.EVENT_NETWORK_STOP
|
||||
|
||||
def test_rename_node(self):
|
||||
|
||||
Reference in new issue
Block a user