mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
bug fixes and linting
This commit is contained in:
parent
c91d52a587
commit
5fe2db228c
@ -143,6 +143,9 @@ omit =
|
|||||||
homeassistant/components/netatmo.py
|
homeassistant/components/netatmo.py
|
||||||
homeassistant/components/*/netatmo.py
|
homeassistant/components/*/netatmo.py
|
||||||
|
|
||||||
|
homeassistant/components/nuheat.py
|
||||||
|
homeassistant/components/*/nuheat.py
|
||||||
|
|
||||||
homeassistant/components/octoprint.py
|
homeassistant/components/octoprint.py
|
||||||
homeassistant/components/*/octoprint.py
|
homeassistant/components/*/octoprint.py
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ from homeassistant.components.climate import (
|
|||||||
ClimateDevice,
|
ClimateDevice,
|
||||||
STATE_HEAT,
|
STATE_HEAT,
|
||||||
STATE_IDLE)
|
STATE_IDLE)
|
||||||
|
from homeassistant.components.nuheat import DATA_NUHEAT
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
@ -26,7 +27,6 @@ MODE_AUTO = "auto" # Run device schedule
|
|||||||
MODE_AWAY = "away"
|
MODE_AWAY = "away"
|
||||||
MODE_HOLD_TEMPERATURE = "temperature"
|
MODE_HOLD_TEMPERATURE = "temperature"
|
||||||
MODE_TEMPORARY_HOLD = "temporary_temperature"
|
MODE_TEMPORARY_HOLD = "temporary_temperature"
|
||||||
# TODO: offline?
|
|
||||||
|
|
||||||
OPERATION_LIST = [STATE_HEAT, STATE_IDLE]
|
OPERATION_LIST = [STATE_HEAT, STATE_IDLE]
|
||||||
|
|
||||||
@ -36,15 +36,13 @@ SCHEDULE_TEMPORARY_HOLD = 2
|
|||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
"""Set up the NuHeat thermostat(s)."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
_LOGGER.info("Loading NuHeat thermostat component")
|
_LOGGER.info("Loading NuHeat thermostat climate component")
|
||||||
|
|
||||||
temperature_unit = hass.config.units.temperature_unit
|
temperature_unit = hass.config.units.temperature_unit
|
||||||
_LOGGER.debug("temp_unit is %s", temperature_unit)
|
|
||||||
api, serial_numbers = hass.data[DATA_NUHEAT]
|
api, serial_numbers = hass.data[DATA_NUHEAT]
|
||||||
|
|
||||||
thermostats = [
|
thermostats = [
|
||||||
NuHeatThermostat(api, serial_number, temperature_unit)
|
NuHeatThermostat(api, serial_number, temperature_unit)
|
||||||
for serial_number in serial_numbers
|
for serial_number in serial_numbers
|
||||||
@ -77,7 +75,7 @@ class NuHeatThermostat(ClimateDevice):
|
|||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
if self._temperature_unit == "C":
|
if self._temperature_unit == "C":
|
||||||
return self._thermostat.celsius
|
return self._thermostat.celsius
|
||||||
|
|
||||||
return self._thermostat.fahrenheit
|
return self._thermostat.fahrenheit
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -158,7 +156,7 @@ class NuHeatThermostat(ClimateDevice):
|
|||||||
|
|
||||||
if self._thermostat.schedule_mode != SCHEDULE_HOLD:
|
if self._thermostat.schedule_mode != SCHEDULE_HOLD:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def turn_away_mode_on(self):
|
def turn_away_mode_on(self):
|
||||||
@ -203,6 +201,6 @@ class NuHeatThermostat(ClimateDevice):
|
|||||||
self._throttled_update()
|
self._throttled_update()
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def _throttled_update(self):
|
def _throttled_update(self, **kwargs):
|
||||||
"""Get the latest state from the thermostat... but throttled!"""
|
"""Get the latest state from the thermostat... but throttled!"""
|
||||||
self._thermostat.get_data()
|
self._thermostat.get_data()
|
||||||
|
@ -5,8 +5,6 @@ For more details about this platform, please refer to the documentation at
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_DEVICES
|
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_DEVICES
|
||||||
@ -25,7 +23,8 @@ 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): vol.All(cv.ensure_list, cv.string)
|
vol.Required(CONF_DEVICES, default=[]):
|
||||||
|
vol.All(cv.ensure_list, [cv.string]),
|
||||||
}),
|
}),
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ SCHEDULE_TEMPORARY_HOLD = 2
|
|||||||
|
|
||||||
class TestNuHeat(unittest.TestCase):
|
class TestNuHeat(unittest.TestCase):
|
||||||
"""Tests for NuHeat climate."""
|
"""Tests for NuHeat climate."""
|
||||||
|
# pylint: disable=protected-access, no-self-use
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
||||||
@ -41,6 +42,25 @@ class TestNuHeat(unittest.TestCase):
|
|||||||
self.thermostat = nuheat.NuHeatThermostat(
|
self.thermostat = nuheat.NuHeatThermostat(
|
||||||
api, serial_number, temperature_unit)
|
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):
|
def test_name(self):
|
||||||
"""Test name property."""
|
"""Test name property."""
|
||||||
self.assertEqual(self.thermostat.name, "Master bathroom")
|
self.assertEqual(self.thermostat.name, "Master bathroom")
|
||||||
@ -48,42 +68,36 @@ class TestNuHeat(unittest.TestCase):
|
|||||||
def test_temperature_unit(self):
|
def test_temperature_unit(self):
|
||||||
"""Test temperature unit."""
|
"""Test temperature unit."""
|
||||||
self.assertEqual(self.thermostat.temperature_unit, TEMP_FAHRENHEIT)
|
self.assertEqual(self.thermostat.temperature_unit, TEMP_FAHRENHEIT)
|
||||||
|
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.temperature_unit, TEMP_CELSIUS)
|
self.assertEqual(self.thermostat.temperature_unit, TEMP_CELSIUS)
|
||||||
|
|
||||||
def test_current_temperature(self):
|
def test_current_temperature(self):
|
||||||
"""Test current temperature."""
|
"""Test current temperature."""
|
||||||
self.assertEqual(self.thermostat.current_temperature, 72)
|
self.assertEqual(self.thermostat.current_temperature, 72)
|
||||||
|
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.current_temperature, 22)
|
self.assertEqual(self.thermostat.current_temperature, 22)
|
||||||
|
|
||||||
def test_current_operation(self):
|
def test_current_operation(self):
|
||||||
"""Test current operation."""
|
"""Test current operation."""
|
||||||
self.assertEqual(self.thermostat.current_operation, STATE_HEAT)
|
self.assertEqual(self.thermostat.current_operation, STATE_HEAT)
|
||||||
|
|
||||||
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_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)
|
||||||
|
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.min_temp, 5)
|
self.assertEqual(self.thermostat.min_temp, 5)
|
||||||
|
|
||||||
def test_max_temp(self):
|
def test_max_temp(self):
|
||||||
"""Test max temp."""
|
"""Test max temp."""
|
||||||
self.assertEqual(self.thermostat.max_temp, 157)
|
self.assertEqual(self.thermostat.max_temp, 157)
|
||||||
|
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.max_temp, 69)
|
self.assertEqual(self.thermostat.max_temp, 69)
|
||||||
|
|
||||||
def test_target_temperature(self):
|
def test_target_temperature(self):
|
||||||
"""Test target temperature."""
|
"""Test target temperature."""
|
||||||
self.assertEqual(self.thermostat.target_temperature, 72)
|
self.assertEqual(self.thermostat.target_temperature, 72)
|
||||||
|
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.target_temperature, 22)
|
self.assertEqual(self.thermostat.target_temperature, 22)
|
||||||
|
|
||||||
@ -91,14 +105,12 @@ class TestNuHeat(unittest.TestCase):
|
|||||||
def test_target_temperature_low(self):
|
def test_target_temperature_low(self):
|
||||||
"""Test low target temperature."""
|
"""Test low target temperature."""
|
||||||
self.assertEqual(self.thermostat.target_temperature_low, 72)
|
self.assertEqual(self.thermostat.target_temperature_low, 72)
|
||||||
|
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.target_temperature_low, 22)
|
self.assertEqual(self.thermostat.target_temperature_low, 22)
|
||||||
|
|
||||||
def test_target_temperature_high(self):
|
def test_target_temperature_high(self):
|
||||||
"""Test high target temperature."""
|
"""Test high target temperature."""
|
||||||
self.assertEqual(self.thermostat.target_temperature_high, 72)
|
self.assertEqual(self.thermostat.target_temperature_high, 72)
|
||||||
|
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.target_temperature_high, 22)
|
self.assertEqual(self.thermostat.target_temperature_high, 22)
|
||||||
|
|
||||||
@ -143,7 +155,7 @@ class TestNuHeat(unittest.TestCase):
|
|||||||
@patch.object(
|
@patch.object(
|
||||||
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
|
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
|
||||||
@patch.object(nuheat.NuHeatThermostat, "set_temperature")
|
@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."""
|
"""Test turn away mode on when not away."""
|
||||||
is_away_mode_on.return_value = False
|
is_away_mode_on.return_value = False
|
||||||
self.thermostat.turn_away_mode_on()
|
self.thermostat.turn_away_mode_on()
|
||||||
@ -153,7 +165,7 @@ class TestNuHeat(unittest.TestCase):
|
|||||||
@patch.object(
|
@patch.object(
|
||||||
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
|
nuheat.NuHeatThermostat, "is_away_mode_on", new_callable=PropertyMock)
|
||||||
@patch.object(nuheat.NuHeatThermostat, "set_temperature")
|
@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."""
|
"""Test turn away mode on when away."""
|
||||||
is_away_mode_on.return_value = True
|
is_away_mode_on.return_value = True
|
||||||
self.thermostat.turn_away_mode_on()
|
self.thermostat.turn_away_mode_on()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user