mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Heat control config validation
* heat control configuration validation * fix heat contol test
This commit is contained in:
parent
d3fb69783d
commit
3318c55c65
@ -5,7 +5,9 @@ For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/thermostat.heat_control/
|
||||
"""
|
||||
import logging
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import homeassistant.util as util
|
||||
from homeassistant.components import switch
|
||||
from homeassistant.components.thermostat import (
|
||||
@ -28,21 +30,26 @@ CONF_TARGET_TEMP = 'target_temp'
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORM_SCHEMA = vol.Schema({
|
||||
vol.Required("platform"): "heat_control",
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Required(CONF_HEATER): cv.entity_id,
|
||||
vol.Required(CONF_SENSOR): cv.entity_id,
|
||||
vol.Optional(CONF_MIN_TEMP): vol.Coerce(float),
|
||||
vol.Optional(CONF_MAX_TEMP): vol.Coerce(float),
|
||||
vol.Optional(CONF_TARGET_TEMP): vol.Coerce(float),
|
||||
})
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the heat control thermostat."""
|
||||
name = config.get(CONF_NAME, DEFAULT_NAME)
|
||||
name = config.get(CONF_NAME)
|
||||
heater_entity_id = config.get(CONF_HEATER)
|
||||
sensor_entity_id = config.get(CONF_SENSOR)
|
||||
min_temp = util.convert(config.get(CONF_MIN_TEMP), float, None)
|
||||
max_temp = util.convert(config.get(CONF_MAX_TEMP), float, None)
|
||||
target_temp = util.convert(config.get(CONF_TARGET_TEMP), float, None)
|
||||
|
||||
if None in (heater_entity_id, sensor_entity_id):
|
||||
_LOGGER.error('Missing required key %s or %s', CONF_HEATER,
|
||||
CONF_SENSOR)
|
||||
return False
|
||||
min_temp = config.get(CONF_MIN_TEMP)
|
||||
max_temp = config.get(CONF_MAX_TEMP)
|
||||
target_temp = config.get(CONF_TARGET_TEMP)
|
||||
|
||||
add_devices([HeatControl(hass, name, heater_entity_id, sensor_entity_id,
|
||||
min_temp, max_temp, target_temp)])
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""The tests for the heat control thermostat."""
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from homeassistant.bootstrap import _setup_component
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
SERVICE_TURN_OFF,
|
||||
@ -11,7 +11,6 @@ from homeassistant.const import (
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.components import thermostat
|
||||
import homeassistant.components.thermostat.heat_control as heat_control
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
@ -41,9 +40,17 @@ class TestSetupThermostatHeatControl(unittest.TestCase):
|
||||
'name': 'test',
|
||||
'target_sensor': ENT_SENSOR
|
||||
}
|
||||
add_devices = mock.MagicMock()
|
||||
result = heat_control.setup_platform(self.hass, config, add_devices)
|
||||
self.assertEqual(False, result)
|
||||
self.assertFalse(_setup_component(self.hass, 'thermostat', {
|
||||
'thermostat': config}))
|
||||
|
||||
def test_valid_conf(self):
|
||||
"""Test set up heat_control with valid config values."""
|
||||
self.assertTrue(_setup_component(self.hass, 'thermostat',
|
||||
{'thermostat': {
|
||||
'platform': 'heat_control',
|
||||
'name': 'test',
|
||||
'heater': ENT_SWITCH,
|
||||
'target_sensor': ENT_SENSOR}}))
|
||||
|
||||
def test_setup_with_sensor(self):
|
||||
"""Test set up heat_control with sensor to trigger update at init."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user