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

View File

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

View File

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