示例#1
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'))
示例#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()
示例#3
0
    def test_set_operation_pessimistic(self):
        """Test setting operation mode in pessimistic mode."""
        config = copy.deepcopy(DEFAULT_CONFIG)
        config['climate']['mode_state_topic'] = 'mode-state'
        assert setup_component(self.hass, climate.DOMAIN, config)

        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("off", state.attributes.get('operation_mode'))
        self.assertEqual("off", state.state)

        climate.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("off", state.attributes.get('operation_mode'))
        self.assertEqual("off", state.state)

        fire_mqtt_message(self.hass, 'mode-state', 'cool')
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("cool", state.attributes.get('operation_mode'))
        self.assertEqual("cool", state.state)

        fire_mqtt_message(self.hass, 'mode-state', 'bogus mode')
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("cool", state.attributes.get('operation_mode'))
        self.assertEqual("cool", state.state)
示例#4
0
    def test_set_operation_with_power_command(self):
        """Test setting of new operation mode with power command enabled."""
        config = copy.deepcopy(DEFAULT_CONFIG)
        config['climate']['power_command_topic'] = 'power-command'
        assert setup_component(self.hass, climate.DOMAIN, config)

        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("off", state.attributes.get('operation_mode'))
        self.assertEqual("off", state.state)
        climate.set_operation_mode(self.hass, "on", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("on", state.attributes.get('operation_mode'))
        self.assertEqual("on", state.state)
        self.mock_publish.async_publish.assert_has_calls([
            unittest.mock.call('power-command', 'ON', 0, False),
            unittest.mock.call('mode-topic', 'on', 0, False)
        ])
        self.mock_publish.async_publish.reset_mock()

        climate.set_operation_mode(self.hass, "off", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("off", state.attributes.get('operation_mode'))
        self.assertEqual("off", state.state)
        self.mock_publish.async_publish.assert_has_calls([
            unittest.mock.call('power-command', 'OFF', 0, False),
            unittest.mock.call('mode-topic', 'off', 0, False)
        ])
        self.mock_publish.async_publish.reset_mock()
示例#5
0
 def test_set_operation_bad_attr(self):
     """Test setting operation mode without required attribute."""
     state = self.hass.states.get(ENTITY_CLIMATE)
     self.assertEqual("Cool", state.attributes.get('operation_mode'))
     climate.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
     self.hass.pool.block_till_done()
     state = self.hass.states.get(ENTITY_CLIMATE)
     self.assertEqual("Cool", state.attributes.get('operation_mode'))
示例#6
0
 def test_set_operation(self):
     """Test setting of new operation mode."""
     state = self.hass.states.get(ENTITY_CLIMATE)
     self.assertEqual("cool", state.attributes.get('operation_mode'))
     self.assertEqual("cool", state.state)
     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.assertEqual("heat", state.state)
 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_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_turn_off_when_off(self):
     """Test if climate.turn_off does nothing to a turned off device."""
     climate.set_operation_mode(self.hass, STATE_OFF)
     self.hass.block_till_done()
     self.hass.services.call('climate', SERVICE_TURN_OFF)
     self.hass.block_till_done()
     state_heat = self.hass.states.get(self.HEAT_ENTITY)
     state_cool = self.hass.states.get(self.COOL_ENTITY)
     self.assertEqual(STATE_OFF,
                      state_heat.attributes.get('operation_mode'))
     self.assertEqual(STATE_OFF,
                      state_cool.attributes.get('operation_mode'))
示例#10
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'])
示例#11
0
 def test_turn_off_when_off(self):
     """Test if climate.turn_off does nothing to a turned off device."""
     climate.set_operation_mode(self.hass, STATE_OFF)
     self.hass.block_till_done()
     self.hass.services.call('climate', SERVICE_TURN_OFF)
     self.hass.block_till_done()
     state_heat = self.hass.states.get(self.HEAT_ENTITY)
     state_cool = self.hass.states.get(self.COOL_ENTITY)
     self.assertEqual(STATE_OFF,
                      state_heat.attributes.get('operation_mode'))
     self.assertEqual(STATE_OFF,
                      state_cool.attributes.get('operation_mode'))
示例#12
0
    def test_set_operation_bad_attr_and_state(self):
        """Test setting operation mode without required attribute.

        Also check the state.
        """
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("cool", state.attributes.get('operation_mode'))
        self.assertEqual("cool", state.state)
        climate.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("cool", state.attributes.get('operation_mode'))
        self.assertEqual("cool", state.state)
示例#13
0
    def test_set_operation_bad_attr_and_state(self):
        """Test setting operation mode without required attribute.

        Also check the state.
        """
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("cool", state.attributes.get("operation_mode"))
        self.assertEqual("cool", state.state)
        climate.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("cool", state.attributes.get("operation_mode"))
        self.assertEqual("cool", state.state)
示例#14
0
    def test_set_operation(self):
        """Test setting of new operation mode."""
        assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)

        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("off", state.attributes.get('operation_mode'))
        self.assertEqual("off", state.state)
        climate.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("cool", state.attributes.get('operation_mode'))
        self.assertEqual("cool", state.state)
        self.mock_publish.async_publish.assert_called_once_with(
            'mode-topic', 'cool', 0, False)
示例#15
0
    def test_set_operation(self):
        """Test setting of new operation mode."""
        assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)

        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("off", state.attributes.get('operation_mode'))
        self.assertEqual("off", state.state)
        climate.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("cool", state.attributes.get('operation_mode'))
        self.assertEqual("cool", state.state)
        self.mock_publish.async_publish.assert_called_once_with(
            'mode-topic', 'cool', 0, False)
示例#16
0
    def test_set_operation_bad_attr_and_state(self):
        """Test setting operation mode without required attribute.

        Also check the state.
        """
        assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)

        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("off", state.attributes.get('operation_mode'))
        self.assertEqual("off", state.state)
        climate.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("off", state.attributes.get('operation_mode'))
        self.assertEqual("off", state.state)
示例#17
0
    def test_set_operation_bad_attr_and_state(self):
        """Test setting operation mode without required attribute.

        Also check the state.
        """
        assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)

        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("off", state.attributes.get('operation_mode'))
        self.assertEqual("off", state.state)
        climate.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        self.assertEqual("off", state.attributes.get('operation_mode'))
        self.assertEqual("off", state.state)
    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'])
示例#19
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])
示例#20
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])
示例#21
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'])
示例#22
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_invalid_operating_mode(self, log_mock):
     """Test error handling for invalid operation mode."""
     climate.set_operation_mode(self.hass, 'invalid mode')
     self.hass.block_till_done()
     self.assertEqual(log_mock.call_count, 1)
示例#24
0
 def test_invalid_operating_mode(self, log_mock):
     """Test error handling for invalid operation mode."""
     climate.set_operation_mode(self.hass, 'invalid mode')
     self.hass.block_till_done()
     self.assertEqual(log_mock.call_count, 1)
示例#25
0
 def test_set_operation(self):
     """Test setting of new operation mode."""
     climate.set_operation_mode(self.hass, "Heat", ENTITY_CLIMATE)
     self.hass.pool.block_till_done()
     self.assertEqual("Heat", self.hass.states.get(ENTITY_CLIMATE).state)
示例#26
0
 def test_set_operation(self):
     """Test setting of new operation mode."""
     climate.set_operation_mode(self.hass, "Heat", ENTITY_CLIMATE)
     self.hass.pool.block_till_done()
     state = self.hass.states.get(ENTITY_CLIMATE)
     self.assertEqual("Heat", state.attributes.get('operation_mode'))