test resume program service
This commit is contained in:
parent
f0244d7982
commit
63d9bd4a9c
3 changed files with 50 additions and 17 deletions
|
@ -19,7 +19,7 @@ from homeassistant.components.climate import (
|
|||
STATE_AUTO,
|
||||
STATE_HEAT,
|
||||
STATE_IDLE)
|
||||
from homeassistant.components.nuheat import DATA_NUHEAT
|
||||
from homeassistant.components.nuheat import DOMAIN as NUHEAT_DOMAIN
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
|
@ -64,7 +64,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
return
|
||||
|
||||
temperature_unit = hass.config.units.temperature_unit
|
||||
api, serial_numbers = hass.data[DATA_NUHEAT]
|
||||
api, serial_numbers = hass.data[NUHEAT_DOMAIN]
|
||||
thermostats = [
|
||||
NuHeatThermostat(api, serial_number, temperature_unit)
|
||||
for serial_number in serial_numbers
|
||||
|
@ -74,7 +74,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
def resume_program_set_service(service):
|
||||
"""Resume the program on the target thermostats."""
|
||||
entity_id = service.data.get(ATTR_ENTITY_ID)
|
||||
|
||||
if entity_id:
|
||||
target_thermostats = [device for device in thermostats
|
||||
if device.entity_id in entity_id]
|
||||
|
@ -94,6 +93,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
descriptions.get(SERVICE_RESUME_PROGRAM),
|
||||
schema=RESUME_PROGRAM_SCHEMA)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class NuHeatThermostat(ClimateDevice):
|
||||
"""Representation of a NuHeat Thermostat."""
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""The test for the NuHeat thermostat module."""
|
||||
import unittest
|
||||
from unittest.mock import Mock, patch
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
SUPPORT_HOLD_MODE,
|
||||
|
@ -21,7 +22,7 @@ class TestNuHeat(unittest.TestCase):
|
|||
|
||||
# pylint: disable=protected-access, no-self-use
|
||||
|
||||
def setUp(self):
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Set up test variables."""
|
||||
serial_number = "12345"
|
||||
temperature_unit = "F"
|
||||
|
@ -45,31 +46,62 @@ class TestNuHeat(unittest.TestCase):
|
|||
thermostat.get_data = Mock()
|
||||
thermostat.resume_schedule = Mock()
|
||||
|
||||
api = Mock()
|
||||
api.get_thermostat.return_value = thermostat
|
||||
self.api = Mock()
|
||||
self.api.get_thermostat.return_value = thermostat
|
||||
|
||||
self.hass = get_test_home_assistant()
|
||||
self.thermostat = nuheat.NuHeatThermostat(
|
||||
api, serial_number, temperature_unit)
|
||||
self.api, serial_number, temperature_unit)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop hass."""
|
||||
self.hass.stop()
|
||||
|
||||
@patch("homeassistant.components.climate.nuheat.NuHeatThermostat")
|
||||
def test_setup_platform(self, mocked_thermostat):
|
||||
"""Test setup_platform."""
|
||||
api = Mock()
|
||||
data = {"nuheat": (api, ["12345"])}
|
||||
mocked_thermostat.return_value = self.thermostat
|
||||
thermostat = mocked_thermostat(self.api, "12345", "F")
|
||||
thermostats = [thermostat]
|
||||
|
||||
hass = Mock()
|
||||
hass.config.units.temperature_unit.return_value = "F"
|
||||
hass.data = Mock()
|
||||
hass.data.__getitem__ = Mock(side_effect=data.__getitem__)
|
||||
self.hass.data[nuheat.NUHEAT_DOMAIN] = (self.api, ["12345"])
|
||||
|
||||
config = {}
|
||||
add_devices = Mock()
|
||||
discovery_info = {}
|
||||
|
||||
nuheat.setup_platform(hass, config, add_devices, discovery_info)
|
||||
thermostats = [mocked_thermostat(api, "12345", "F")]
|
||||
nuheat.setup_platform(self.hass, config, add_devices, discovery_info)
|
||||
add_devices.assert_called_once_with(thermostats, True)
|
||||
|
||||
@patch("homeassistant.components.climate.nuheat.NuHeatThermostat")
|
||||
def test_resume_program_service(self, mocked_thermostat):
|
||||
"""Test resume program service."""
|
||||
mocked_thermostat.return_value = self.thermostat
|
||||
thermostat = mocked_thermostat(self.api, "12345", "F")
|
||||
thermostat.resume_program = Mock()
|
||||
thermostat.schedule_update_ha_state = Mock()
|
||||
thermostat.entity_id = "climate.master_bathroom"
|
||||
|
||||
self.hass.data[nuheat.NUHEAT_DOMAIN] = (self.api, ["12345"])
|
||||
nuheat.setup_platform(self.hass, {}, Mock(), {})
|
||||
|
||||
# Explicit entity
|
||||
self.hass.services.call(nuheat.DOMAIN, nuheat.SERVICE_RESUME_PROGRAM,
|
||||
{"entity_id": "climate.master_bathroom"}, True)
|
||||
|
||||
thermostat.resume_program.assert_called_with()
|
||||
thermostat.schedule_update_ha_state.assert_called_with(True)
|
||||
|
||||
thermostat.resume_program.reset_mock()
|
||||
thermostat.schedule_update_ha_state.reset_mock()
|
||||
|
||||
# All entities
|
||||
self.hass.services.call(
|
||||
nuheat.DOMAIN, nuheat.SERVICE_RESUME_PROGRAM, {}, True)
|
||||
|
||||
thermostat.resume_program.assert_called_with()
|
||||
thermostat.schedule_update_ha_state.assert_called_with(True)
|
||||
|
||||
def test_name(self):
|
||||
"""Test name property."""
|
||||
self.assertEqual(self.thermostat.name, "Master bathroom")
|
||||
|
|
|
@ -18,12 +18,12 @@ VALID_CONFIG = {
|
|||
class TestNuHeat(unittest.TestCase):
|
||||
"""Test the NuHeat component."""
|
||||
|
||||
def setUp(self):
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Initialize the values for this test class."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.config = VALID_CONFIG
|
||||
|
||||
def tearDown(self):
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Teardown this test class. Stop hass."""
|
||||
self.hass.stop()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue