示例#1
0
    def test_all_commands(self):
        """Test simple commands to the vacuum."""
        self.default_config[mqtt.CONF_SUPPORTED_FEATURES] = \
            mqtt.services_to_strings(mqtt.ALL_SERVICES)

        self.assertTrue(setup_component(self.hass, vacuum.DOMAIN, {
            vacuum.DOMAIN: self.default_config,
        }))

        vacuum.turn_on(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'turn_on', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.turn_off(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'turn_off', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.stop(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'stop', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.clean_spot(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'clean_spot', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.locate(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'locate', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.start_pause(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'start_pause', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.return_to_base(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'return_to_base', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.set_fan_speed(self.hass, 'high', 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(
            ('vacuum/set_fan_speed', 'high', 0, False),
            self.mock_publish.mock_calls[-2][1]
        )

        vacuum.send_command(self.hass, '44 FE 93', entity_id='vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(
            ('vacuum/send_command', '44 FE 93', 0, False),
            self.mock_publish.mock_calls[-2][1]
        )
示例#2
0
    def test_all_commands(self):
        """Test simple commands to the vacuum."""
        self.default_config[mqtt.CONF_SUPPORTED_FEATURES] = \
            mqtt.services_to_strings(mqtt.ALL_SERVICES)

        self.assertTrue(setup_component(self.hass, vacuum.DOMAIN, {
            vacuum.DOMAIN: self.default_config,
        }))

        vacuum.turn_on(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'turn_on', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.turn_off(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'turn_off', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.stop(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'stop', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.clean_spot(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'clean_spot', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.locate(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'locate', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.start_pause(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'start_pause', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.return_to_base(self.hass, 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(('vacuum/command', 'return_to_base', 0, False),
                         self.mock_publish.mock_calls[-2][1])

        vacuum.set_fan_speed(self.hass, 'high', 'vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(
            ('vacuum/set_fan_speed', 'high', 0, False),
            self.mock_publish.mock_calls[-2][1]
        )

        vacuum.send_command(self.hass, '44 FE 93', entity_id='vacuum.mqtttest')
        self.hass.block_till_done()
        self.assertEqual(
            ('vacuum/send_command', '44 FE 93', 0, False),
            self.mock_publish.mock_calls[-2][1]
        )
示例#3
0
    def test_send_command(self):
        """Test vacuum service to send a command."""
        group_vacuums = ','.join([ENTITY_VACUUM_BASIC,
                                  ENTITY_VACUUM_COMPLETE])
        old_state_basic = self.hass.states.get(ENTITY_VACUUM_BASIC)
        old_state_complete = self.hass.states.get(ENTITY_VACUUM_COMPLETE)

        vacuum.send_command(
            self.hass, 'test_command', params={"p1": 3},
            entity_id=group_vacuums)

        self.hass.block_till_done()
        new_state_basic = self.hass.states.get(ENTITY_VACUUM_BASIC)
        new_state_complete = self.hass.states.get(ENTITY_VACUUM_COMPLETE)

        self.assertEqual(old_state_basic, new_state_basic)
        self.assertNotEqual(old_state_complete, new_state_complete)
        self.assertEqual(STATE_ON, new_state_complete.state)
        self.assertEqual("Executing test_command({'p1': 3})",
                         new_state_complete.attributes[ATTR_STATUS])
示例#4
0
    def test_send_command(self):
        """Test vacuum service to send a command."""
        group_vacuums = ','.join([ENTITY_VACUUM_BASIC,
                                  ENTITY_VACUUM_COMPLETE])
        old_state_basic = self.hass.states.get(ENTITY_VACUUM_BASIC)
        old_state_complete = self.hass.states.get(ENTITY_VACUUM_COMPLETE)

        vacuum.send_command(
            self.hass, 'test_command', params={"p1": 3},
            entity_id=group_vacuums)

        self.hass.block_till_done()
        new_state_basic = self.hass.states.get(ENTITY_VACUUM_BASIC)
        new_state_complete = self.hass.states.get(ENTITY_VACUUM_COMPLETE)

        self.assertEqual(old_state_basic, new_state_basic)
        self.assertNotEqual(old_state_complete, new_state_complete)
        self.assertEqual(STATE_ON, new_state_complete.state)
        self.assertEqual("Executing test_command({'p1': 3})",
                         new_state_complete.attributes[ATTR_STATUS])
示例#5
0
    def test_services(self):
        """Test vacuum services."""
        # Test send_command
        send_command_calls = mock_service(self.hass, DOMAIN,
                                          SERVICE_SEND_COMMAND)

        params = {"rotate": 150, "speed": 20}
        vacuum.send_command(self.hass,
                            'test_command',
                            entity_id=ENTITY_VACUUM_BASIC,
                            params=params)

        self.hass.block_till_done()
        self.assertEqual(1, len(send_command_calls))
        call = send_command_calls[-1]

        self.assertEqual(DOMAIN, call.domain)
        self.assertEqual(SERVICE_SEND_COMMAND, call.service)
        self.assertEqual(ENTITY_VACUUM_BASIC, call.data[ATTR_ENTITY_ID])
        self.assertEqual('test_command', call.data[ATTR_COMMAND])
        self.assertEqual(params, call.data[ATTR_PARAMS])

        # Test set fan speed
        set_fan_speed_calls = mock_service(self.hass, DOMAIN,
                                           SERVICE_SET_FAN_SPEED)

        vacuum.set_fan_speed(self.hass,
                             FAN_SPEEDS[0],
                             entity_id=ENTITY_VACUUM_COMPLETE)

        self.hass.block_till_done()
        self.assertEqual(1, len(set_fan_speed_calls))
        call = set_fan_speed_calls[-1]

        self.assertEqual(DOMAIN, call.domain)
        self.assertEqual(SERVICE_SET_FAN_SPEED, call.service)
        self.assertEqual(ENTITY_VACUUM_COMPLETE, call.data[ATTR_ENTITY_ID])
        self.assertEqual(FAN_SPEEDS[0], call.data[ATTR_FAN_SPEED])
示例#6
0
    def test_services(self):
        """Test vacuum services."""
        # Test send_command
        send_command_calls = mock_service(
            self.hass, DOMAIN, SERVICE_SEND_COMMAND)

        params = {"rotate": 150, "speed": 20}
        vacuum.send_command(
            self.hass, 'test_command', entity_id=ENTITY_VACUUM_BASIC,
            params=params)

        self.hass.block_till_done()
        self.assertEqual(1, len(send_command_calls))
        call = send_command_calls[-1]

        self.assertEqual(DOMAIN, call.domain)
        self.assertEqual(SERVICE_SEND_COMMAND, call.service)
        self.assertEqual(ENTITY_VACUUM_BASIC, call.data[ATTR_ENTITY_ID])
        self.assertEqual('test_command', call.data[ATTR_COMMAND])
        self.assertEqual(params, call.data[ATTR_PARAMS])

        # Test set fan speed
        set_fan_speed_calls = mock_service(
            self.hass, DOMAIN, SERVICE_SET_FAN_SPEED)

        vacuum.set_fan_speed(
            self.hass, FAN_SPEEDS[0], entity_id=ENTITY_VACUUM_COMPLETE)

        self.hass.block_till_done()
        self.assertEqual(1, len(set_fan_speed_calls))
        call = set_fan_speed_calls[-1]

        self.assertEqual(DOMAIN, call.domain)
        self.assertEqual(SERVICE_SET_FAN_SPEED, call.service)
        self.assertEqual(ENTITY_VACUUM_COMPLETE, call.data[ATTR_ENTITY_ID])
        self.assertEqual(FAN_SPEEDS[0], call.data[ATTR_FAN_SPEED])