allow for the configuring of a minimum away temperature

This commit is contained in:
Derek Brooks 2017-11-13 11:00:33 -06:00
parent 7859b76429
commit f21b9988e9
3 changed files with 28 additions and 8 deletions

View File

@ -43,9 +43,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.info("Loading NuHeat thermostat climate component")
temperature_unit = hass.config.units.temperature_unit
api, serial_numbers = hass.data[DATA_NUHEAT]
api, serial_numbers, min_away_temp = hass.data[DATA_NUHEAT]
thermostats = [
NuHeatThermostat(api, serial_number, temperature_unit)
NuHeatThermostat(api, serial_number, min_away_temp, temperature_unit)
for serial_number in serial_numbers
]
add_devices(thermostats, True)
@ -53,9 +53,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class NuHeatThermostat(ClimateDevice):
"""Representation of a NuHeat Thermostat."""
def __init__(self, api, serial_number, temperature_unit):
def __init__(self, api, serial_number, min_away_temp, temperature_unit):
self._thermostat = api.get_thermostat(serial_number)
self._temperature_unit = temperature_unit
self._min_away_temp = min_away_temp
self._force_update = False
@property
@ -87,6 +88,14 @@ class NuHeatThermostat(ClimateDevice):
return STATE_IDLE
@property
def min_away_temp(self):
"""Return the minimum target temperature to be used in away mode."""
if self._min_away_temp:
return self._min_away_temp
return self.min_temp
@property
def min_temp(self):
"""Return the minimum supported temperature for the thermostat."""
@ -156,7 +165,7 @@ class NuHeatThermostat(ClimateDevice):
return
kwargs = {}
kwargs[ATTR_TEMPERATURE] = self.min_temp
kwargs[ATTR_TEMPERATURE] = self.min_away_temp
self.set_temperature(**kwargs)
self._force_update = True

View File

@ -20,12 +20,15 @@ DATA_NUHEAT = "nuheat"
DOMAIN = "nuheat"
CONF_MIN_AWAY_TEMP = 'min_away_temp'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_DEVICES, default=[]):
vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_MIN_AWAY_TEMP): cv.string,
}),
}, extra=vol.ALLOW_EXTRA)
@ -38,10 +41,11 @@ def setup(hass, config):
username = conf.get(CONF_USERNAME)
password = conf.get(CONF_PASSWORD)
devices = conf.get(CONF_DEVICES)
min_away_temp = conf.get(CONF_MIN_AWAY_TEMP)
api = nuheat.NuHeat(username, password)
api.authenticate()
hass.data[DATA_NUHEAT] = (api, devices)
hass.data[DATA_NUHEAT] = (api, devices, min_away_temp)
discovery.load_platform(hass, "climate", DOMAIN, {}, config)
_LOGGER.debug("NuHeat initialized")

View File

@ -18,6 +18,7 @@ class TestNuHeat(unittest.TestCase):
def setUp(self):
serial_number = "12345"
min_away_temp = None
temperature_unit = "F"
thermostat = Mock(
@ -42,13 +43,13 @@ class TestNuHeat(unittest.TestCase):
api.get_thermostat.return_value = thermostat
self.thermostat = nuheat.NuHeatThermostat(
api, serial_number, temperature_unit)
api, serial_number, min_away_temp, temperature_unit)
@patch("homeassistant.components.climate.nuheat.NuHeatThermostat")
def test_setup_platform(self, mocked_thermostat):
"""Test setup_platform."""
api = Mock()
data = {"nuheat": (api, ["12345"])}
data = {"nuheat": (api, ["12345"], 50)}
hass = Mock()
hass.config.units.temperature_unit.return_value = "F"
@ -60,7 +61,7 @@ class TestNuHeat(unittest.TestCase):
discovery_info = {}
nuheat.setup_platform(hass, config, add_devices, discovery_info)
thermostats = [mocked_thermostat(api, "12345", "F")]
thermostats = [mocked_thermostat(api, "12345", 50, "F")]
add_devices.assert_called_once_with(thermostats, True)
def test_name(self):
@ -85,6 +86,12 @@ class TestNuHeat(unittest.TestCase):
self.thermostat._thermostat.heating = False
self.assertEqual(self.thermostat.current_operation, STATE_IDLE)
def test_min_away_temp(self):
"""Test the minimum target temperature to be used in away mode."""
self.assertEqual(self.thermostat.min_away_temp, 41)
self.thermostat._min_away_temp = 60
self.assertEqual(self.thermostat.min_away_temp, 60)
def test_min_temp(self):
"""Test min temp."""
self.assertEqual(self.thermostat.min_temp, 41)