bug fixes and linting

This commit is contained in:
Derek Brooks 2017-11-11 10:18:32 -06:00
parent c91d52a587
commit 5fe2db228c
4 changed files with 33 additions and 21 deletions
.coveragerc
homeassistant/components
tests/components/climate

View file

@ -143,6 +143,9 @@ omit =
homeassistant/components/netatmo.py
homeassistant/components/*/netatmo.py
homeassistant/components/nuheat.py
homeassistant/components/*/nuheat.py
homeassistant/components/octoprint.py
homeassistant/components/*/octoprint.py

View file

@ -10,6 +10,7 @@ from homeassistant.components.climate import (
ClimateDevice,
STATE_HEAT,
STATE_IDLE)
from homeassistant.components.nuheat import DATA_NUHEAT
from homeassistant.const import (
ATTR_TEMPERATURE,
TEMP_CELSIUS,
@ -26,7 +27,6 @@ MODE_AUTO = "auto" # Run device schedule
MODE_AWAY = "away"
MODE_HOLD_TEMPERATURE = "temperature"
MODE_TEMPORARY_HOLD = "temporary_temperature"
# TODO: offline?
OPERATION_LIST = [STATE_HEAT, STATE_IDLE]
@ -36,15 +36,13 @@ SCHEDULE_TEMPORARY_HOLD = 2
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the NuHeat thermostat(s)."""
if discovery_info is None:
return
_LOGGER.info("Loading NuHeat thermostat component")
_LOGGER.info("Loading NuHeat thermostat climate component")
temperature_unit = hass.config.units.temperature_unit
_LOGGER.debug("temp_unit is %s", temperature_unit)
api, serial_numbers = hass.data[DATA_NUHEAT]
thermostats = [
NuHeatThermostat(api, serial_number, temperature_unit)
for serial_number in serial_numbers
@ -77,7 +75,7 @@ class NuHeatThermostat(ClimateDevice):
"""Return the current temperature."""
if self._temperature_unit == "C":
return self._thermostat.celsius
return self._thermostat.fahrenheit
@property
@ -158,7 +156,7 @@ class NuHeatThermostat(ClimateDevice):
if self._thermostat.schedule_mode != SCHEDULE_HOLD:
return False
return True
def turn_away_mode_on(self):
@ -203,6 +201,6 @@ class NuHeatThermostat(ClimateDevice):
self._throttled_update()
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def _throttled_update(self):
def _throttled_update(self, **kwargs):
"""Get the latest state from the thermostat... but throttled!"""
self._thermostat.get_data()

View file

@ -5,8 +5,6 @@ For more details about this platform, please refer to the documentation at
"""
import logging
from datetime import timedelta
import voluptuous as vol
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_DEVICES
@ -25,7 +23,8 @@ CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_DEVICES): vol.All(cv.ensure_list, cv.string)
vol.Required(CONF_DEVICES, default=[]):
vol.All(cv.ensure_list, [cv.string]),
}),
}, extra=vol.ALLOW_EXTRA)

View file

@ -13,6 +13,7 @@ SCHEDULE_TEMPORARY_HOLD = 2
class TestNuHeat(unittest.TestCase):
"""Tests for NuHeat climate."""
# pylint: disable=protected-access, no-self-use
def setUp(self):
@ -41,6 +42,25 @@ class TestNuHeat(unittest.TestCase):
self.thermostat = nuheat.NuHeatThermostat(
api, serial_number, temperature_unit)
@patch("homeassistant.components.climate.nuheat.NuHeatThermostat")
def test_setup_platform(self, mocked_thermostat):
"""Test setup_platform."""
api = Mock()
data = {"nuheat": (api, ["12345"])}
hass = Mock()
hass.config.units.temperature_unit.return_value = "F"
hass.data = Mock()
hass.data.__getitem__ = Mock(side_effect=data.__getitem__)
config = {}
add_devices = Mock()
discovery_info = {}
nuheat.setup_platform(hass, config, add_devices, discovery_info)
thermostats = [mocked_thermostat(api, "12345", "F")]
add_devices.assert_called_once_with(thermostats, True)
def test_name(self):
"""Test name property."""
self.assertEqual(self.thermostat.name, "Master bathroom")
@ -48,42 +68,36 @@ class TestNuHeat(unittest.TestCase):
def test_temperature_unit(self):
"""Test temperature unit."""
self.assertEqual(self.thermostat.temperature_unit, TEMP_FAHRENHEIT)
self.thermostat._temperature_unit = "C"
self.assertEqual(self.thermostat.temperature_unit, TEMP_CELSIUS)
def test_current_temperature(self):
"""Test current temperature."""
self.assertEqual(self.thermostat.current_temperature, 72)
self.thermostat._temperature_unit = "C"
self.assertEqual(self.thermostat.current_temperature, 22)
def test_current_operation(self):
"""Test current operation."""
self.assertEqual(self.thermostat.current_operation, STATE_HEAT)
self.thermostat._thermostat.heating = False
self.assertEqual(self.thermostat.current_operation, STATE_IDLE)
def test_min_temp(self):
"""Test min temp."""
self.assertEqual(self.thermostat.min_temp, 41)
self.thermostat._temperature_unit = "C"
self.assertEqual(self.thermostat.min_temp, 5)
def test_max_temp(self):
"""Test max temp."""
self.assertEqual(self.thermostat.max_temp, 157)
self.thermostat._temperature_unit = "C"
self.assertEqual(self.thermostat.max_temp, 69)
def test_target_temperature(self):
"""Test target temperature."""
self.assertEqual(self.thermostat.target_temperature, 72)
self.thermostat._temperature_unit = "C"
self.assertEqual(self.thermostat.target_temperature, 22)
@ -91,14 +105,12 @@ class TestNuHeat(unittest.TestCase):
def test_target_temperature_low(self):
"""Test low target temperature."""
self.assertEqual(self.thermostat.target_temperature_low, 72)
self.thermostat._temperature_unit = "C"
self.assertEqual(self.thermostat.target_temperature_low, 22)
def test_target_temperature_high(self):
"""Test high target temperature."""
self.assertEqual(self.thermostat.target_temperature_high, 72)
self.thermostat._temperature_unit = "C"
self.assertEqual(self.thermostat.target_temperature_high, 22)
@ -143,7 +155,7 @@ class TestNuHeat(unittest.TestCase):
@patch.object(
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
@patch.object(nuheat.NuHeatThermostat, "set_temperature")
def test_turn_away_mode_on_while_home(self, set_temp, is_away_mode_on):
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()
@ -153,7 +165,7 @@ class TestNuHeat(unittest.TestCase):
@patch.object(
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
@patch.object(nuheat.NuHeatThermostat, "set_temperature")
def test_turn_away_mode_on_while_away(self, set_temp, is_away_mode_on):
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()