remove nuheat away functionality. :(

This commit is contained in:
Derek Brooks 2017-12-06 22:34:13 -06:00
parent c262a387dc
commit 3193e825d5
3 changed files with 11 additions and 175 deletions

View File

@ -9,7 +9,6 @@ from datetime import timedelta
from homeassistant.components.climate import ( from homeassistant.components.climate import (
ClimateDevice, ClimateDevice,
SUPPORT_AWAY_MODE,
SUPPORT_HOLD_MODE, SUPPORT_HOLD_MODE,
SUPPORT_OPERATION_MODE, SUPPORT_OPERATION_MODE,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE,
@ -33,7 +32,6 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=5)
# Hold modes # Hold modes
MODE_AUTO = STATE_HOME # Run device schedule MODE_AUTO = STATE_HOME # Run device schedule
MODE_AWAY = "away"
MODE_HOLD_TEMPERATURE = "temperature" MODE_HOLD_TEMPERATURE = "temperature"
MODE_TEMPORARY_HOLD = "temporary_temperature" MODE_TEMPORARY_HOLD = "temporary_temperature"
@ -44,7 +42,7 @@ SCHEDULE_RUN = 1
SCHEDULE_TEMPORARY_HOLD = 2 SCHEDULE_TEMPORARY_HOLD = 2
SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_HOLD_MODE | SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_HOLD_MODE |
SUPPORT_AWAY_MODE | SUPPORT_OPERATION_MODE) SUPPORT_OPERATION_MODE)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
@ -53,9 +51,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
return return
temperature_unit = hass.config.units.temperature_unit temperature_unit = hass.config.units.temperature_unit
api, serial_numbers, min_away_temp = hass.data[DATA_NUHEAT] api, serial_numbers = hass.data[DATA_NUHEAT]
thermostats = [ thermostats = [
NuHeatThermostat(api, serial_number, min_away_temp, temperature_unit) NuHeatThermostat(api, serial_number, temperature_unit)
for serial_number in serial_numbers for serial_number in serial_numbers
] ]
add_devices(thermostats, True) add_devices(thermostats, True)
@ -64,11 +62,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, min_away_temp, temperature_unit): def __init__(self, api, serial_number, temperature_unit):
"""Initialize the thermostat.""" """Initialize the thermostat."""
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
@ -110,14 +107,6 @@ 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 and self._min_away_temp > self.min_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."""
@ -145,9 +134,6 @@ class NuHeatThermostat(ClimateDevice):
@property @property
def current_hold_mode(self): def current_hold_mode(self):
"""Return current hold mode.""" """Return current hold mode."""
if self.is_away_mode_on:
return MODE_AWAY
schedule_mode = self._thermostat.schedule_mode schedule_mode = self._thermostat.schedule_mode
if schedule_mode == SCHEDULE_RUN: if schedule_mode == SCHEDULE_RUN:
return MODE_AUTO return MODE_AUTO
@ -165,48 +151,6 @@ class NuHeatThermostat(ClimateDevice):
"""Return list of possible operation modes.""" """Return list of possible operation modes."""
return OPERATION_LIST return OPERATION_LIST
@property
def is_away_mode_on(self):
"""
Return true if away mode is on.
Away mode is determined by setting and HOLDing the target temperature
to the user-defined minimum away temperature or the minimum
temperature supported by the thermostat.
"""
min_target = self.min_away_temp
if self._temperature_unit == "C":
target = self._thermostat.target_celsius
else:
target = self._thermostat.target_fahrenheit
if target > min_target:
return False
if self._thermostat.schedule_mode != SCHEDULE_HOLD:
return False
return True
def turn_away_mode_on(self):
"""Turn away mode on."""
if self.is_away_mode_on:
return
kwargs = {}
kwargs[ATTR_TEMPERATURE] = self.min_away_temp
self.set_temperature(**kwargs)
self._force_update = True
def turn_away_mode_off(self):
"""Turn away mode off."""
if not self.is_away_mode_on:
return
self.resume_program()
self._force_update = True
def resume_program(self): def resume_program(self):
"""Resume the thermostat's programmed schedule.""" """Resume the thermostat's programmed schedule."""
self._thermostat.resume_schedule() self._thermostat.resume_schedule()

View File

@ -20,15 +20,12 @@ 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)
@ -42,20 +39,9 @@ def setup(hass, config):
password = conf.get(CONF_PASSWORD) password = conf.get(CONF_PASSWORD)
devices = conf.get(CONF_DEVICES) devices = conf.get(CONF_DEVICES)
min_away_temp = None
_min_away_temp = conf.get(CONF_MIN_AWAY_TEMP)
if _min_away_temp:
try:
min_away_temp = int(_min_away_temp)
except ValueError:
_LOGGER.error(
"Configuration error. %s.%s=%s is invalid. Please provide a "
"numeric value.", DATA_NUHEAT, CONF_MIN_AWAY_TEMP,
_min_away_temp)
api = nuheat.NuHeat(username, password) api = nuheat.NuHeat(username, password)
api.authenticate() api.authenticate()
hass.data[DATA_NUHEAT] = (api, devices, min_away_temp) hass.data[DATA_NUHEAT] = (api, devices)
discovery.load_platform(hass, "climate", DOMAIN, {}, config) discovery.load_platform(hass, "climate", DOMAIN, {}, config)
return True return True

View File

@ -1,9 +1,8 @@
"""The test for the NuHeat thermostat module.""" """The test for the NuHeat thermostat module."""
import unittest import unittest
from unittest.mock import PropertyMock, Mock, patch from unittest.mock import Mock, patch
from homeassistant.components.climate import ( from homeassistant.components.climate import (
SUPPORT_AWAY_MODE,
SUPPORT_HOLD_MODE, SUPPORT_HOLD_MODE,
SUPPORT_OPERATION_MODE, SUPPORT_OPERATION_MODE,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE,
@ -25,7 +24,6 @@ class TestNuHeat(unittest.TestCase):
def setUp(self): def setUp(self):
"""Set up test variables.""" """Set up test variables."""
serial_number = "12345" serial_number = "12345"
min_away_temp = None
temperature_unit = "F" temperature_unit = "F"
thermostat = Mock( thermostat = Mock(
@ -50,13 +48,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, min_away_temp, temperature_unit) api, serial_number, 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"], 50)} data = {"nuheat": (api, ["12345"])}
hass = Mock() hass = Mock()
hass.config.units.temperature_unit.return_value = "F" hass.config.units.temperature_unit.return_value = "F"
@ -68,7 +66,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", 50, "F")] thermostats = [mocked_thermostat(api, "12345", "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):
@ -82,7 +80,7 @@ class TestNuHeat(unittest.TestCase):
def test_supported_features(self): def test_supported_features(self):
"""Test name property.""" """Test name property."""
features = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_HOLD_MODE | features = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_HOLD_MODE |
SUPPORT_AWAY_MODE | SUPPORT_OPERATION_MODE) SUPPORT_OPERATION_MODE)
self.assertEqual(self.thermostat.supported_features, features) self.assertEqual(self.thermostat.supported_features, features)
def test_temperature_unit(self): def test_temperature_unit(self):
@ -103,18 +101,6 @@ 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)
# User defined minimum
self.thermostat._min_away_temp = 60
self.assertEqual(self.thermostat.min_away_temp, 60)
# User defined minimum below the thermostat's supported minimum
self.thermostat._min_away_temp = 0
self.assertEqual(self.thermostat.min_away_temp, 41)
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)
@ -133,19 +119,8 @@ class TestNuHeat(unittest.TestCase):
self.thermostat._temperature_unit = "C" self.thermostat._temperature_unit = "C"
self.assertEqual(self.thermostat.target_temperature, 22) self.assertEqual(self.thermostat.target_temperature, 22)
@patch.object( def test_current_hold_mode(self):
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
def test_current_hold_mode_away(self, is_away_mode_on):
"""Test current hold mode while away."""
is_away_mode_on.return_value = True
self.assertEqual(self.thermostat.current_hold_mode, nuheat.MODE_AWAY)
@patch.object(
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
def test_current_hold_mode(self, is_away_mode_on):
"""Test current hold mode.""" """Test current hold mode."""
is_away_mode_on.return_value = False
self.thermostat._thermostat.schedule_mode = SCHEDULE_RUN self.thermostat._thermostat.schedule_mode = SCHEDULE_RUN
self.assertEqual(self.thermostat.current_hold_mode, nuheat.MODE_AUTO) self.assertEqual(self.thermostat.current_hold_mode, nuheat.MODE_AUTO)
@ -157,75 +132,6 @@ class TestNuHeat(unittest.TestCase):
self.assertEqual( self.assertEqual(
self.thermostat.current_hold_mode, nuheat.MODE_TEMPORARY_HOLD) self.thermostat.current_hold_mode, nuheat.MODE_TEMPORARY_HOLD)
def test_is_away_mode_on(self):
"""Test is away mode on."""
_thermostat = self.thermostat._thermostat
_thermostat.schedule_mode = SCHEDULE_HOLD
# user-defined minimum fahrenheit
self.thermostat._min_away_temp = 59
_thermostat.target_fahrenheit = 59
self.assertTrue(self.thermostat.is_away_mode_on)
# user-defined minimum celsius
self.thermostat._temperature_unit = "C"
self.thermostat._min_away_temp = 15
_thermostat.target_celsius = 15
self.assertTrue(self.thermostat.is_away_mode_on)
# thermostat's minimum supported temperature
self.thermostat._min_away_temp = None
_thermostat.target_celsius = _thermostat.min_celsius
self.assertTrue(self.thermostat.is_away_mode_on)
# thermostat held at a temperature above the minimum
_thermostat.target_celsius = _thermostat.min_celsius + 1
self.assertFalse(self.thermostat.is_away_mode_on)
# thermostat not on HOLD
_thermostat.target_celsius = _thermostat.min_celsius
_thermostat.schedule_mode = SCHEDULE_RUN
self.assertFalse(self.thermostat.is_away_mode_on)
@patch.object(
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
@patch.object(nuheat.NuHeatThermostat, "set_temperature")
def test_turn_away_mode_on_home(self, set_temp, is_away_mode_on):
"""Test turn away mode on when not away."""
is_away_mode_on.return_value = False
self.thermostat.turn_away_mode_on()
set_temp.assert_called_once_with(temperature=self.thermostat.min_temp)
self.assertTrue(self.thermostat._force_update)
@patch.object(
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
@patch.object(nuheat.NuHeatThermostat, "set_temperature")
def test_turn_away_mode_on_away(self, set_temp, is_away_mode_on):
"""Test turn away mode on when away."""
is_away_mode_on.return_value = True
self.thermostat.turn_away_mode_on()
set_temp.assert_not_called()
@patch.object(
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
@patch.object(nuheat.NuHeatThermostat, "resume_program")
def test_turn_away_mode_off_home(self, resume, is_away_mode_on):
"""Test turn away mode off when home."""
is_away_mode_on.return_value = False
self.thermostat.turn_away_mode_off()
self.assertFalse(self.thermostat._force_update)
resume.assert_not_called()
@patch.object(
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
@patch.object(nuheat.NuHeatThermostat, "resume_program")
def test_turn_away_mode_off_away(self, resume, is_away_mode_on):
"""Test turn away mode off when away."""
is_away_mode_on.return_value = True
self.thermostat.turn_away_mode_off()
self.assertTrue(self.thermostat._force_update)
resume.assert_called_once_with()
def test_resume_program(self): def test_resume_program(self):
"""Test resume schedule.""" """Test resume schedule."""
self.thermostat.resume_program() self.thermostat.resume_program()