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')
|
||||
|
||||
Reference in new issue
Block a user