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)
        assert state.attributes.get('operation_mode') is None
        assert "unknown" == state.state

        common.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert state.attributes.get('operation_mode') is None
        assert "unknown" == state.state

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

        fire_mqtt_message(self.hass, 'mode-state', 'bogus mode')
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert "cool" == state.attributes.get('operation_mode')
        assert "cool" == state.state
    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)
        assert state.attributes.get('temperature') is None
        common.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
        self.hass.block_till_done()
        common.set_temperature(self.hass,
                               temperature=47,
                               entity_id=ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert state.attributes.get('temperature') is None

        fire_mqtt_message(self.hass, 'temperature-state', '1701')
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert 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)
        assert 1701 == state.attributes.get('temperature')
Exemple #3
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)
        assert 21 == state.attributes.get('temperature')
        common.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert '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()
        common.set_temperature(self.hass, temperature=47,
                               entity_id=ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert 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()
        common.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)
        assert 'cool' == state.attributes.get('operation_mode')
        assert 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_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)
        assert "off" == state.attributes.get('operation_mode')
        assert "off" == state.state
        common.set_operation_mode(self.hass, "on", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert "on" == state.attributes.get('operation_mode')
        assert "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()

        common.set_operation_mode(self.hass, "off", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert "off" == state.attributes.get('operation_mode')
        assert "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()
    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)
        assert state.attributes.get('operation_mode') is None
        assert "unknown" == state.state

        common.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert state.attributes.get('operation_mode') is None
        assert "unknown" == state.state

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

        fire_mqtt_message(self.hass, 'mode-state', 'bogus mode')
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert "cool" == state.attributes.get('operation_mode')
        assert "cool" == state.state
    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)
        assert state.attributes.get('temperature') is None
        common.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
        self.hass.block_till_done()
        common.set_temperature(self.hass, temperature=47,
                               entity_id=ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert state.attributes.get('temperature') is None

        fire_mqtt_message(self.hass, 'temperature-state', '1701')
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert 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)
        assert 1701 == state.attributes.get('temperature')
    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)
        assert "off" == state.attributes.get('operation_mode')
        assert "off" == state.state
        common.set_operation_mode(self.hass, "on", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert "on" == state.attributes.get('operation_mode')
        assert "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()

        common.set_operation_mode(self.hass, "off", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert "off" == state.attributes.get('operation_mode')
        assert "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()
 def test_set_operation(self):
     """Test setting of new operation mode."""
     state = self.hass.states.get(ENTITY_CLIMATE)
     assert "cool" == state.attributes.get('operation_mode')
     assert "cool" == state.state
     common.set_operation_mode(self.hass, "heat", ENTITY_CLIMATE)
     self.hass.block_till_done()
     state = self.hass.states.get(ENTITY_CLIMATE)
     assert "heat" == state.attributes.get('operation_mode')
     assert "heat" == state.state
Exemple #9
0
 def test_set_operation(self):
     """Test setting of new operation mode."""
     state = self.hass.states.get(ENTITY_CLIMATE)
     assert "cool" == state.attributes.get('operation_mode')
     assert "cool" == state.state
     common.set_operation_mode(self.hass, "heat", ENTITY_CLIMATE)
     self.hass.block_till_done()
     state = self.hass.states.get(ENTITY_CLIMATE)
     assert "heat" == state.attributes.get('operation_mode')
     assert "heat" == state.state
Exemple #10
0
 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)
     common.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     common.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))
Exemple #11
0
 def test_turn_off_when_off(self):
     """Test if climate.turn_off does nothing to a turned off device."""
     common.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'))
Exemple #12
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)
     common.set_temperature(self.hass, 30)
     self.hass.block_till_done()
     common.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'])
Exemple #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)
        assert "cool" == state.attributes.get('operation_mode')
        assert "cool" == state.state
        common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert "cool" == state.attributes.get('operation_mode')
        assert "cool" == state.state
Exemple #14
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)
        assert "cool" == state.attributes.get('operation_mode')
        assert "cool" == state.state
        common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert "cool" == state.attributes.get('operation_mode')
        assert "cool" == state.state
Exemple #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)
        assert "off" == state.attributes.get('operation_mode')
        assert "off" == state.state
        common.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert "cool" == state.attributes.get('operation_mode')
        assert "cool" == state.state
        self.mock_publish.async_publish.assert_called_once_with(
            'mode-topic', 'cool', 0, False)
Exemple #16
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)
        assert "off" == state.attributes.get('operation_mode')
        assert "off" == state.state
        common.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert "cool" == state.attributes.get('operation_mode')
        assert "cool" == state.state
        self.mock_publish.async_publish.assert_called_once_with(
            'mode-topic', 'cool', 0, False)
Exemple #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)
        assert "off" == state.attributes.get('operation_mode')
        assert "off" == state.state
        common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert "off" == state.attributes.get('operation_mode')
        assert "off" == state.state
Exemple #18
0
    def test_operating_mode_cool(self):
        """Test change mode from OFF to COOL.

        Switch turns on when temp below setpoint and mode changes.
        """
        common.set_operation_mode(self.hass, STATE_OFF)
        common.set_temperature(self.hass, 25)
        self._setup_sensor(30)
        self.hass.block_till_done()
        self._setup_switch(False)
        common.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'])
Exemple #19
0
 def test_invalid_operating_mode(self, log_mock):
     """Test error handling for invalid operation mode."""
     common.set_operation_mode(self.hass, 'invalid mode')
     self.hass.block_till_done()
     self.assertEqual(log_mock.call_count, 1)