diff --git a/homeassistant/components/nuheat.py b/homeassistant/components/nuheat.py index 41db3e51842..fb14f119dbd 100644 --- a/homeassistant/components/nuheat.py +++ b/homeassistant/components/nuheat.py @@ -16,8 +16,6 @@ REQUIREMENTS = ["nuheat==0.3.0"] _LOGGER = logging.getLogger(__name__) -DATA_NUHEAT = "nuheat" - DOMAIN = "nuheat" CONFIG_SCHEMA = vol.Schema({ @@ -41,7 +39,7 @@ def setup(hass, config): api = nuheat.NuHeat(username, password) api.authenticate() - hass.data[DATA_NUHEAT] = (api, devices) + hass.data[DOMAIN] = (api, devices) discovery.load_platform(hass, "climate", DOMAIN, {}, config) return True diff --git a/tests/components/climate/test_nuheat.py b/tests/components/climate/test_nuheat.py index aedb925277e..b2ad57731ba 100644 --- a/tests/components/climate/test_nuheat.py +++ b/tests/components/climate/test_nuheat.py @@ -42,6 +42,7 @@ class TestNuHeat(unittest.TestCase): target_celsius=22, target_fahrenheit=72) + thermostat.get_data = Mock() thermostat.resume_schedule = Mock() api = Mock() @@ -132,6 +133,17 @@ class TestNuHeat(unittest.TestCase): self.assertEqual( self.thermostat.current_hold_mode, nuheat.MODE_TEMPORARY_HOLD) + self.thermostat._thermostat.schedule_mode = None + self.assertEqual( + self.thermostat.current_hold_mode, nuheat.MODE_AUTO) + + def test_operation_list(self): + """Test the operation list.""" + self.assertEqual( + self.thermostat.operation_list, + [STATE_HEAT, STATE_IDLE] + ) + def test_resume_program(self): """Test resume schedule.""" self.thermostat.resume_program() @@ -167,7 +179,7 @@ class TestNuHeat(unittest.TestCase): self.assertTrue(self.thermostat._force_update) @patch.object(nuheat.NuHeatThermostat, "_throttled_update") - def test_forced_update(self, throttled_update): + def test_update_without_throttle(self, throttled_update): """Test update without throttle.""" self.thermostat._force_update = True self.thermostat.update() @@ -175,9 +187,14 @@ class TestNuHeat(unittest.TestCase): self.assertFalse(self.thermostat._force_update) @patch.object(nuheat.NuHeatThermostat, "_throttled_update") - def test_throttled_update(self, throttled_update): + def test_update_with_throttle(self, throttled_update): """Test update with throttle.""" self.thermostat._force_update = False self.thermostat.update() throttled_update.assert_called_once_with() self.assertFalse(self.thermostat._force_update) + + def test_throttled_update(self): + """Test update with throttle.""" + self.thermostat._throttled_update() + self.thermostat._thermostat.get_data.assert_called_once_with() diff --git a/tests/components/test_nuheat.py b/tests/components/test_nuheat.py new file mode 100644 index 00000000000..6b091b8df35 --- /dev/null +++ b/tests/components/test_nuheat.py @@ -0,0 +1,44 @@ +"""NuHeat component tests.""" +import unittest + +from unittest.mock import patch +from tests.common import get_test_home_assistant, MockDependency + +from homeassistant.components import nuheat + +VALID_CONFIG = { + "nuheat": { + "username": "warm", + "password": "feet", + "devices": "thermostat123" + } +} + + +class TestNuHeat(unittest.TestCase): + """Test the NuHeat component.""" + + def setUp(self): + """Initialize the values for this test class.""" + self.hass = get_test_home_assistant() + self.config = VALID_CONFIG + + def tearDown(self): + """Teardown this test class. Stop hass.""" + self.hass.stop() + + @MockDependency("nuheat") + @patch("homeassistant.helpers.discovery.load_platform") + def test_setup(self, mocked_nuheat, mocked_load): + """Test setting up the NuHeat component.""" + nuheat.setup(self.hass, self.config) + + mocked_nuheat.NuHeat.assert_called_with("warm", "feet") + self.assertIn(nuheat.DOMAIN, self.hass.data) + self.assertEquals(2, len(self.hass.data[nuheat.DOMAIN])) + self.assertEquals(self.hass.data[nuheat.DOMAIN][0], "thermostat123") + self.assertEquals(self.hass.data[nuheat.DOMAIN][1], "thermostat123") + + mocked_load.assert_called_with( + self.hass, "climate", nuheat.DOMAIN, {}, self.config + )