示例#1
0
 def test_set_only_target_temp_bad_attr(self):
     """Test setting the target temperature without required attribute."""
     state = self.hass.states.get(ENTITY_CLIMATE)
     self.assertEqual(21, state.attributes.get('temperature'))
     climate.set_temperature(self.hass, None, ENTITY_CLIMATE)
     self.hass.block_till_done()
     self.assertEqual(21, state.attributes.get('temperature'))
示例#2
0
    def test_set_target_temperature(self):
        """Test setting the target temperature."""
        assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)

        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(21, state.attributes.get('temperature'))
        climate.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual('heat', state.attributes.get('operation_mode'))
        self.mock_publish.async_publish.assert_called_once_with(
            'mode-topic', 'heat', 0, False)
        self.mock_publish.async_publish.reset_mock()
        climate.set_temperature(self.hass, temperature=47,
                                entity_id=ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(47, state.attributes.get('temperature'))
        self.mock_publish.async_publish.assert_called_once_with(
            'temperature-topic', 47, 0, False)

        # also test directly supplying the operation mode to set_temperature
        self.mock_publish.async_publish.reset_mock()
        climate.set_temperature(self.hass, temperature=21,
                                operation_mode="cool",
                                entity_id=ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual('cool', state.attributes.get('operation_mode'))
        self.assertEqual(21, state.attributes.get('temperature'))
        self.mock_publish.async_publish.assert_has_calls([
            unittest.mock.call('mode-topic', 'cool', 0, False),
            unittest.mock.call('temperature-topic', 21, 0, False)
        ])
        self.mock_publish.async_publish.reset_mock()
    def test_heater_switch(self):
        """Test heater switching test switch."""
        platform = loader.get_component(self.hass, 'switch.test')
        platform.init()
        self.switch_1 = platform.DEVICES[1]
        assert setup_component(self.hass, switch.DOMAIN, {'switch': {
            'platform': 'test'}})
        heater_switch = self.switch_1.entity_id

        assert setup_component(self.hass, climate.DOMAIN, {'climate': {
            'platform': 'generic_thermostat',
            'name': 'test',
            'heater': heater_switch,
            'target_sensor': ENT_SENSOR
        }})

        self.assertEqual(STATE_OFF,
                         self.hass.states.get(heater_switch).state)

        self._setup_sensor(18)
        self.hass.block_till_done()
        climate.set_temperature(self.hass, 23)
        self.hass.block_till_done()

        self.assertEqual(STATE_ON,
                         self.hass.states.get(heater_switch).state)
示例#4
0
    def test_set_target_temperature_pessimistic(self):
        """Test setting the target temperature."""
        config = copy.deepcopy(DEFAULT_CONFIG)
        config['climate']['temperature_state_topic'] = 'temperature-state'
        assert setup_component(self.hass, climate.DOMAIN, config)

        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(21, state.attributes.get('temperature'))
        climate.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
        self.hass.block_till_done()
        climate.set_temperature(self.hass, temperature=47,
                                entity_id=ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(21, state.attributes.get('temperature'))

        fire_mqtt_message(self.hass, 'temperature-state', '1701')
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(1701, state.attributes.get('temperature'))

        fire_mqtt_message(self.hass, 'temperature-state', 'not a number')
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(1701, state.attributes.get('temperature'))
示例#5
0
 def test_set_only_target_temp_with_convert(self):
     """Test the setting of the target temperature."""
     state = self.hass.states.get(ENTITY_HEATPUMP)
     self.assertEqual(20, state.attributes.get('temperature'))
     climate.set_temperature(self.hass, 21, ENTITY_HEATPUMP)
     self.hass.block_till_done()
     state = self.hass.states.get(ENTITY_HEATPUMP)
     self.assertEqual(21.0, state.attributes.get('temperature'))
示例#6
0
 def test_set_only_target_temp(self):
     """Test the setting of the target temperature."""
     state = self.hass.states.get(ENTITY_CLIMATE)
     self.assertEqual(21, state.attributes.get('temperature'))
     climate.set_temperature(self.hass, 30, ENTITY_CLIMATE)
     self.hass.block_till_done()
     state = self.hass.states.get(ENTITY_CLIMATE)
     self.assertEqual(30.0, state.attributes.get('temperature'))
 def test_temp_change_heater_on_within_tolerance(self):
     """Test if temperature change turn heater on within tolerance."""
     self._setup_switch(False)
     climate.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     self._setup_sensor(29)
     self.hass.block_till_done()
     self.assertEqual(0, len(self.calls))
 def test_temp_change_heater_trigger_on_not_long_enough(self):
     """Test if temp change doesn't turn heater on because of time."""
     self._setup_switch(False)
     climate.set_temperature(self.hass, 30)
     self.hass.pool.block_till_done()
     self._setup_sensor(25)
     self.hass.pool.block_till_done()
     self.assertEqual(0, len(self.calls))
 def test_temp_change_ac_trigger_off_not_long_enough(self):
     """Test if temperature change turn ac on."""
     self._setup_switch(True)
     climate.set_temperature(self.hass, 30)
     self.hass.pool.block_till_done()
     self._setup_sensor(25)
     self.hass.pool.block_till_done()
     self.assertEqual(0, len(self.calls))
 def test_temp_change_ac_on_within_tolerance(self):
     """Test if temperature change doesn't turn ac on within tolerance."""
     self._setup_switch(False)
     climate.set_temperature(self.hass, 25)
     self.hass.block_till_done()
     self._setup_sensor(25.2)
     self.hass.block_till_done()
     self.assertEqual(0, len(self.calls))
 def test_temp_change_ac_off_within_tolerance(self):
     """Test if temperature change doesn't turn ac off within tolerance."""
     self._setup_switch(True)
     climate.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     self._setup_sensor(29.8)
     self.hass.block_till_done()
     self.assertEqual(0, len(self.calls))
 def test_set_away_mode(self):
     """Test the setting away mode."""
     climate.set_temperature(self.hass, 23)
     self.hass.block_till_done()
     climate.set_away_mode(self.hass, True)
     self.hass.block_till_done()
     state = self.hass.states.get(ENTITY)
     self.assertEqual(16, state.attributes.get('temperature'))
 def test_turn_away_mode_on_cooling(self):
     """Test the setting away mode when cooling."""
     self._setup_sensor(25)
     self.hass.block_till_done()
     climate.set_temperature(self.hass, 19)
     self.hass.block_till_done()
     climate.set_away_mode(self.hass, True)
     self.hass.block_till_done()
     state = self.hass.states.get(ENTITY)
     self.assertEqual(30, state.attributes.get('temperature'))
 def test_no_state_change_when_operation_mode_off(self):
     """Test that the switch doesn't turn on when enabled is False."""
     self._setup_switch(False)
     climate.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     climate.set_operation_mode(self.hass, STATE_OFF)
     self.hass.block_till_done()
     self._setup_sensor(35)
     self.hass.block_till_done()
     self.assertEqual(0, len(self.calls))
 def test_temp_change_ac_on(self):
     """Test if temperature change turn ac on."""
     self._setup_switch(False)
     climate.set_temperature(self.hass, 25)
     self.hass.pool.block_till_done()
     self._setup_sensor(30)
     self.hass.pool.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('switch', call.domain)
     self.assertEqual(SERVICE_TURN_ON, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#16
0
 def test_set_target_temp_range(self):
     """Test the setting of the target temperature with range."""
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(23.0, state.attributes.get('temperature'))
     self.assertEqual(21.0, state.attributes.get('target_temp_low'))
     self.assertEqual(24.0, state.attributes.get('target_temp_high'))
     climate.set_temperature(self.hass, 30, ENTITY_ECOBEE, 25, 20)
     self.hass.pool.block_till_done()
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(30.0, state.attributes.get('temperature'))
     self.assertEqual(20.0, state.attributes.get('target_temp_low'))
     self.assertEqual(25.0, state.attributes.get('target_temp_high'))
 def test_set_target_temp_heater_off(self):
     """Test if target temperature turn heater off."""
     self._setup_switch(True)
     self._setup_sensor(30)
     self.hass.block_till_done()
     climate.set_temperature(self.hass, 25)
     self.hass.block_till_done()
     self.assertEqual(2, len(self.calls))
     call = self.calls[0]
     self.assertEqual('homeassistant', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#18
0
 def test_set_target_temp_ac_on(self):
     """Test if target temperature turn ac on."""
     self._setup_switch(False)
     self._setup_sensor(30)
     self.hass.block_till_done()
     climate.set_temperature(self.hass, 25)
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('homeassistant', call.domain)
     self.assertEqual(SERVICE_TURN_ON, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#19
0
 def test_running_when_operating_mode_is_off(self):
     """Test that the switch turns off when enabled is set False."""
     self._setup_switch(True)
     climate.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     climate.set_operation_mode(self.hass, STATE_OFF)
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('homeassistant', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#20
0
 def test_temp_change_ac_on_outside_tolerance(self):
     """Test if temperature change turn ac on."""
     self._setup_switch(False)
     climate.set_temperature(self.hass, 25)
     self.hass.block_till_done()
     self._setup_sensor(30)
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('switch', call.domain)
     self.assertEqual(SERVICE_TURN_ON, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#21
0
 def test_set_target_temp_ac_off(self):
     """Test if target temperature turn ac off."""
     self._setup_switch(True)
     self._setup_sensor(25)
     self.hass.block_till_done()
     climate.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('switch', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
 def test_temp_change_heater_on_outside_tolerance(self):
     """Test if temperature change turn heater on outside cold tolerance."""
     self._setup_switch(False)
     climate.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     self._setup_sensor(27)
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('switch', call.domain)
     self.assertEqual(SERVICE_TURN_ON, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#23
0
 def test_set_temp_change_ac_off_outside_tolerance(self):
     """Test if temperature change turn ac off."""
     self._setup_switch(True)
     climate.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     self._setup_sensor(27)
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('homeassistant', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#24
0
 def test_set_target_temp_range(self):
     """Test the setting of the target temperature with range."""
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(23.0, state.attributes.get('temperature'))
     self.assertEqual(21.0, state.attributes.get('target_temp_low'))
     self.assertEqual(24.0, state.attributes.get('target_temp_high'))
     climate.set_temperature(self.hass, 30, ENTITY_ECOBEE, 25, 20)
     self.hass.pool.block_till_done()
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(30.0, state.attributes.get('temperature'))
     self.assertEqual(20.0, state.attributes.get('target_temp_low'))
     self.assertEqual(25.0, state.attributes.get('target_temp_high'))
 def test_set_target_temp_heater_on(self):
     """Test if target temperature turn heater on."""
     self._setup_switch(False)
     self._setup_sensor(25)
     self.hass.block_till_done()
     climate.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('switch', call.domain)
     self.assertEqual(SERVICE_TURN_ON, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
 def test_temp_change_heater_off(self):
     """Test if temperature change turn heater off."""
     self._setup_switch(True)
     climate.set_temperature(self.hass, 25)
     self.hass.pool.block_till_done()
     self._setup_sensor(30)
     self.hass.pool.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('switch', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#27
0
 def test_set_target_temp_range(self):
     """Test the setting of the target temperature with range."""
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(None, state.attributes.get("temperature"))
     self.assertEqual(21.0, state.attributes.get("target_temp_low"))
     self.assertEqual(24.0, state.attributes.get("target_temp_high"))
     climate.set_temperature(self.hass, target_temp_high=25, target_temp_low=20, entity_id=ENTITY_ECOBEE)
     self.hass.block_till_done()
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(None, state.attributes.get("temperature"))
     self.assertEqual(20.0, state.attributes.get("target_temp_low"))
     self.assertEqual(25.0, state.attributes.get("target_temp_high"))
 def test_running_when_operating_mode_is_off(self):
     """Test that the switch turns off when enabled is set False."""
     self._setup_switch(True)
     climate.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     climate.set_operation_mode(self.hass, STATE_OFF)
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('homeassistant', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
 def test_set_temp_change_ac_off_outside_tolerance(self):
     """Test if temperature change turn ac off."""
     self._setup_switch(True)
     climate.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     self._setup_sensor(27)
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('homeassistant', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
 def test_set_target_temp_ac_off(self):
     """Test if target temperature turn ac off."""
     self._setup_switch(True)
     self._setup_sensor(25)
     self.hass.pool.block_till_done()
     climate.set_temperature(self.hass, 30)
     self.hass.pool.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('switch', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#31
0
 def test_set_target_temp_range_bad_attr(self):
     """Test setting the target temperature range without required
        attribute."""
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(23, state.attributes.get('temperature'))
     self.assertEqual(21.0, state.attributes.get('target_temp_low'))
     self.assertEqual(24.0, state.attributes.get('target_temp_high'))
     climate.set_temperature(self.hass, None, ENTITY_ECOBEE, None, None)
     self.hass.pool.block_till_done()
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(23, state.attributes.get('temperature'))
     self.assertEqual(21.0, state.attributes.get('target_temp_low'))
     self.assertEqual(24.0, state.attributes.get('target_temp_high'))
示例#32
0
 def test_set_target_temp_range(self):
     """Test the setting of the target temperature with range."""
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(None, state.attributes.get('temperature'))
     self.assertEqual(21.0, state.attributes.get('target_temp_low'))
     self.assertEqual(24.0, state.attributes.get('target_temp_high'))
     climate.set_temperature(self.hass, target_temp_high=25,
                             target_temp_low=20, entity_id=ENTITY_ECOBEE)
     self.hass.block_till_done()
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(None, state.attributes.get('temperature'))
     self.assertEqual(20.0, state.attributes.get('target_temp_low'))
     self.assertEqual(25.0, state.attributes.get('target_temp_high'))
示例#33
0
 def test_set_target_temp_range_bad_attr(self):
     """Test setting the target temperature range without required
        attribute."""
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(23, state.attributes.get('temperature'))
     self.assertEqual(21.0, state.attributes.get('target_temp_low'))
     self.assertEqual(24.0, state.attributes.get('target_temp_high'))
     climate.set_temperature(self.hass, None, ENTITY_ECOBEE, None, None)
     self.hass.pool.block_till_done()
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(23, state.attributes.get('temperature'))
     self.assertEqual(21.0, state.attributes.get('target_temp_low'))
     self.assertEqual(24.0, state.attributes.get('target_temp_high'))
示例#34
0
 def test_set_target_temp_range_bad_attr(self):
     """Test setting the target temperature range without attribute."""
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(None, state.attributes.get('temperature'))
     self.assertEqual(21.0, state.attributes.get('target_temp_low'))
     self.assertEqual(24.0, state.attributes.get('target_temp_high'))
     climate.set_temperature(self.hass, temperature=None,
                             entity_id=ENTITY_ECOBEE, target_temp_low=None,
                             target_temp_high=None)
     self.hass.block_till_done()
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(None, state.attributes.get('temperature'))
     self.assertEqual(21.0, state.attributes.get('target_temp_low'))
     self.assertEqual(24.0, state.attributes.get('target_temp_high'))
示例#35
0
 def test_set_target_temp_range_bad_attr(self):
     """Test setting the target temperature range without attribute."""
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(None, state.attributes.get('temperature'))
     self.assertEqual(21.0, state.attributes.get('target_temp_low'))
     self.assertEqual(24.0, state.attributes.get('target_temp_high'))
     climate.set_temperature(self.hass, temperature=None,
                             entity_id=ENTITY_ECOBEE, target_temp_low=None,
                             target_temp_high=None)
     self.hass.block_till_done()
     state = self.hass.states.get(ENTITY_ECOBEE)
     self.assertEqual(None, state.attributes.get('temperature'))
     self.assertEqual(21.0, state.attributes.get('target_temp_low'))
     self.assertEqual(24.0, state.attributes.get('target_temp_high'))
    def test_set_away_mode_and_restore_prev_temp(self):
        """Test the setting and removing away mode.

        Verify original temperature is restored.
        """
        climate.set_temperature(self.hass, 23)
        self.hass.block_till_done()
        climate.set_away_mode(self.hass, True)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY)
        self.assertEqual(16, state.attributes.get('temperature'))
        climate.set_away_mode(self.hass, False)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY)
        self.assertEqual(23, state.attributes.get('temperature'))
    def test_set_away_mode_and_restore_prev_temp(self):
        """Test the setting and removing away mode.

        Verify original temperature is restored.
        """
        climate.set_temperature(self.hass, 23)
        self.hass.block_till_done()
        climate.set_away_mode(self.hass, True)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY)
        self.assertEqual(16, state.attributes.get('temperature'))
        climate.set_away_mode(self.hass, False)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY)
        self.assertEqual(23, state.attributes.get('temperature'))
 def test_temp_change_heater_trigger_off_long_enough(self):
     """Test if temperature change turn heater off after min cycle."""
     fake_changed = datetime.datetime(1918, 11, 11, 11, 11, 11,
                                      tzinfo=datetime.timezone.utc)
     with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
                     return_value=fake_changed):
         self._setup_switch(True)
     climate.set_temperature(self.hass, 25)
     self.hass.pool.block_till_done()
     self._setup_sensor(30)
     self.hass.pool.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('switch', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#39
0
    def activate(now):
        if hass.states.get('input_boolean.' + object_id_enable).state == 'off':
            return
        if not str(now.hour) == str(
                int(
                    float(
                        hass.states.get('input_slider.' +
                                        object_id_hour).state))):
            return

        climate.set_temperature(hass,
                                hass.states.get('input_slider.' +
                                                object_id_temp).state,
                                entity_id='climate.' + target_entity)
        if not keep_on:
            hass.states.set('input_boolean.' + object_id_enable, 'off')
 def test_temp_change_heater_trigger_off_long_enough(self):
     """Test if temperature change turn heater off after min cycle."""
     fake_changed = datetime.datetime(1918, 11, 11, 11, 11, 11,
                                      tzinfo=datetime.timezone.utc)
     with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
                     return_value=fake_changed):
         self._setup_switch(True)
     climate.set_temperature(self.hass, 25)
     self.hass.block_till_done()
     self._setup_sensor(30)
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('switch', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#41
0
    def test_set_target_temperature(self):
        """Test setting the target temperature."""
        assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)

        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(21, state.attributes.get('temperature'))
        climate.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
        self.hass.block_till_done()
        self.assertEqual(('mode-topic', 'heat', 0, False),
                         self.mock_publish.mock_calls[-2][1])
        climate.set_temperature(self.hass, temperature=47,
                                entity_id=ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(47, state.attributes.get('temperature'))
        self.assertEqual(('temperature-topic', 47, 0, False),
                         self.mock_publish.mock_calls[-2][1])
示例#42
0
    def test_set_target_temperature(self):
        """Test setting the target temperature."""
        assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)

        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(21, state.attributes.get('temperature'))
        climate.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
        self.hass.block_till_done()
        self.assertEqual(('mode-topic', 'heat', 0, False),
                         self.mock_publish.mock_calls[-2][1])
        climate.set_temperature(self.hass, temperature=47,
                                entity_id=ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(47, state.attributes.get('temperature'))
        self.assertEqual(('temperature-topic', 47, 0, False),
                         self.mock_publish.mock_calls[-2][1])
    def test_operating_mode_cool(self):
        """Test change mode from OFF to COOL.

        Switch turns on when temp below setpoint and mode changes.
        """
        climate.set_operation_mode(self.hass, STATE_OFF)
        climate.set_temperature(self.hass, 25)
        self._setup_sensor(30)
        self.hass.block_till_done()
        self._setup_switch(False)
        climate.set_operation_mode(self.hass, climate.STATE_COOL)
        self.hass.block_till_done()
        self.assertEqual(1, len(self.calls))
        call = self.calls[0]
        self.assertEqual('homeassistant', call.domain)
        self.assertEqual(SERVICE_TURN_ON, call.service)
        self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#44
0
    def test_operating_mode_auto(self):
        """Test change mode from OFF to AUTO.

        Switch turns on when temp below setpoint and mode changes.
        """
        climate.set_operation_mode(self.hass, STATE_OFF)
        climate.set_temperature(self.hass, 30)
        self._setup_sensor(25)
        self.hass.block_till_done()
        self._setup_switch(False)
        climate.set_operation_mode(self.hass, climate.STATE_AUTO)
        self.hass.block_till_done()
        self.assertEqual(1, len(self.calls))
        call = self.calls[0]
        self.assertEqual('homeassistant', call.domain)
        self.assertEqual(SERVICE_TURN_ON, call.service)
        self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#45
0
 def test_temp_change_heater_trigger_off_long_enough(self):
     """Test if turn on signal is sent at keep-alive intervals."""
     self._setup_switch(False)
     self.hass.block_till_done()
     self._setup_sensor(30)
     self.hass.block_till_done()
     climate.set_temperature(self.hass, 25)
     self.hass.block_till_done()
     test_time = datetime.datetime.now(pytz.UTC)
     self._send_time_changed(test_time)
     self.hass.block_till_done()
     self.assertEqual(0, len(self.calls))
     self._send_time_changed(test_time + datetime.timedelta(minutes=5))
     self.hass.block_till_done()
     self.assertEqual(0, len(self.calls))
     self._send_time_changed(test_time + datetime.timedelta(minutes=10))
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('homeassistant', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
 def test_temp_change_heater_trigger_off_long_enough(self):
     """Test if turn on signal is sent at keep-alive intervals."""
     self._setup_switch(False)
     self.hass.block_till_done()
     self._setup_sensor(30)
     self.hass.block_till_done()
     climate.set_temperature(self.hass, 25)
     self.hass.block_till_done()
     test_time = datetime.datetime.now(pytz.UTC)
     self._send_time_changed(test_time)
     self.hass.block_till_done()
     self.assertEqual(0, len(self.calls))
     self._send_time_changed(test_time + datetime.timedelta(minutes=5))
     self.hass.block_till_done()
     self.assertEqual(0, len(self.calls))
     self._send_time_changed(test_time + datetime.timedelta(minutes=10))
     self.hass.block_till_done()
     self.assertEqual(1, len(self.calls))
     call = self.calls[0]
     self.assertEqual('homeassistant', call.domain)
     self.assertEqual(SERVICE_TURN_OFF, call.service)
     self.assertEqual(ENT_SWITCH, call.data['entity_id'])
示例#47
0
    def test_heater_input_boolean(self):
        """Test heater switching input_boolean."""
        heater_switch = 'input_boolean.test'
        assert setup_component(self.hass, input_boolean.DOMAIN,
                               {'input_boolean': {'test': None}})

        assert setup_component(self.hass, climate.DOMAIN, {'climate': {
            'platform': 'generic_thermostat',
            'name': 'test',
            'heater': heater_switch,
            'target_sensor': ENT_SENSOR
        }})

        self.assertEqual(STATE_OFF,
                         self.hass.states.get(heater_switch).state)

        self._setup_sensor(18)
        self.hass.block_till_done()
        climate.set_temperature(self.hass, 23)
        self.hass.block_till_done()

        self.assertEqual(STATE_ON,
                         self.hass.states.get(heater_switch).state)
示例#48
0
    def test_set_target_temperature(self):
        """Test setting the target temperature."""
        assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)

        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(21, state.attributes.get('temperature'))
        climate.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual('heat', state.attributes.get('operation_mode'))
        self.mock_publish.async_publish.assert_called_once_with(
            'mode-topic', 'heat', 0, False)
        self.mock_publish.async_publish.reset_mock()
        climate.set_temperature(self.hass,
                                temperature=47,
                                entity_id=ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual(47, state.attributes.get('temperature'))
        self.mock_publish.async_publish.assert_called_once_with(
            'temperature-topic', 47, 0, False)

        # also test directly supplying the operation mode to set_temperature
        self.mock_publish.async_publish.reset_mock()
        climate.set_temperature(self.hass,
                                temperature=21,
                                operation_mode="cool",
                                entity_id=ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual('cool', state.attributes.get('operation_mode'))
        self.assertEqual(21, state.attributes.get('temperature'))
        self.mock_publish.async_publish.assert_has_calls([
            unittest.mock.call('mode-topic', 'cool', 0, False),
            unittest.mock.call('temperature-topic', 21, 0, False)
        ])
        self.mock_publish.async_publish.reset_mock()
示例#49
0
 def test_set_target_temp(self):
     """Test the setting of the target temperature."""
     climate.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     state = self.hass.states.get(ENTITY)
     self.assertEqual(30.0, state.attributes.get('temperature'))