Fix SET_TEMPERATURE_SCHEMA in climate component (#8879)

* Require either temperature or high/low target temperatures.
* Add tests.
This commit is contained in:
Martin Hjelmare
2017-08-12 10:57:10 -07:00
committed by Paulus Schoutsen
parent 08899ade00
commit eef3dda1e9
3 changed files with 54 additions and 9 deletions
+40
View File
@@ -0,0 +1,40 @@
"""The tests for the climate component."""
import asyncio
from homeassistant.components.climate import SET_TEMPERATURE_SCHEMA
from tests.common import async_mock_service
@asyncio.coroutine
def test_set_temp_schema_no_req(hass, caplog):
"""Test the set temperature schema with missing required data."""
domain = 'climate'
service = 'test_set_temperature'
schema = SET_TEMPERATURE_SCHEMA
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)
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
def test_set_temp_schema(hass, caplog):
"""Test the set temperature schema with ok required data."""
domain = 'climate'
service = 'test_set_temperature'
schema = SET_TEMPERATURE_SCHEMA
calls = async_mock_service(hass, domain, service, schema)
data = {
'temperature': 20.0, 'operation_mode': 'test',
'entity_id': ['climate.test_id']}
yield from hass.services.async_call(domain, service, data)
yield from hass.async_block_till_done()
assert len(calls) == 1
assert calls[-1].data == data