Пример #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_unsupported_methods(self):
        """Test service calls for unsupported vacuums."""
        self.hass.states.set(ENTITY_VACUUM_NONE, STATE_ON)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE))

        vacuum.turn_off(self.hass, ENTITY_VACUUM_NONE)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE))

        vacuum.stop(self.hass, ENTITY_VACUUM_NONE)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE))

        self.hass.states.set(ENTITY_VACUUM_NONE, STATE_OFF)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE))

        vacuum.turn_on(self.hass, ENTITY_VACUUM_NONE)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE))

        vacuum.toggle(self.hass, ENTITY_VACUUM_NONE)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE))

        # Non supported methods:
        vacuum.start_pause(self.hass, ENTITY_VACUUM_NONE)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE))

        vacuum.locate(self.hass, ENTITY_VACUUM_NONE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_NONE)
        self.assertIsNone(state.attributes.get(ATTR_STATUS))

        vacuum.return_to_base(self.hass, ENTITY_VACUUM_NONE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_NONE)
        self.assertIsNone(state.attributes.get(ATTR_STATUS))

        vacuum.set_fan_speed(self.hass, FAN_SPEEDS[-1],
                             entity_id=ENTITY_VACUUM_NONE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_NONE)
        self.assertNotEqual(FAN_SPEEDS[-1],
                            state.attributes.get(ATTR_FAN_SPEED))

        vacuum.clean_spot(self.hass, entity_id=ENTITY_VACUUM_BASIC)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_BASIC)
        self.assertNotIn("spot", state.attributes.get(ATTR_STATUS))
        self.assertEqual(STATE_OFF, state.state)
Пример #4
0
    def test_methods(self):
        """Test if methods call the services as expected."""
        self.hass.states.set(ENTITY_VACUUM_BASIC, STATE_ON)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_BASIC))

        self.hass.states.set(ENTITY_VACUUM_BASIC, STATE_OFF)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_BASIC))

        self.hass.states.set(ENTITY_ID_ALL_VACUUMS, STATE_ON)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass))

        self.hass.states.set(ENTITY_ID_ALL_VACUUMS, STATE_OFF)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass))

        vacuum.turn_on(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        vacuum.turn_off(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        vacuum.toggle(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        vacuum.start_pause(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        vacuum.start_pause(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        vacuum.stop(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        state = self.hass.states.get(ENTITY_VACUUM_COMPLETE)
        self.assertLess(state.attributes.get(ATTR_BATTERY_LEVEL), 100)
        self.assertNotEqual("Charging", state.attributes.get(ATTR_STATUS))

        vacuum.locate(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_COMPLETE)
        self.assertIn("I'm over here", state.attributes.get(ATTR_STATUS))

        vacuum.return_to_base(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_COMPLETE)
        self.assertIn("Returning home", state.attributes.get(ATTR_STATUS))

        vacuum.set_fan_speed(self.hass, FAN_SPEEDS[-1],
                             entity_id=ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_COMPLETE)
        self.assertEqual(FAN_SPEEDS[-1], state.attributes.get(ATTR_FAN_SPEED))

        vacuum.clean_spot(self.hass, entity_id=ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_COMPLETE)
        self.assertIn("spot", state.attributes.get(ATTR_STATUS))
        self.assertEqual(STATE_ON, state.state)

        vacuum.start(self.hass, ENTITY_VACUUM_STATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_STATE)
        self.assertEqual(STATE_CLEANING, state.state)

        vacuum.pause(self.hass, ENTITY_VACUUM_STATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_STATE)
        self.assertEqual(STATE_PAUSED, state.state)

        vacuum.stop(self.hass, ENTITY_VACUUM_STATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_STATE)
        self.assertEqual(STATE_IDLE, state.state)

        state = self.hass.states.get(ENTITY_VACUUM_STATE)
        self.assertLess(state.attributes.get(ATTR_BATTERY_LEVEL), 100)
        self.assertNotEqual(STATE_DOCKED, state.state)

        vacuum.return_to_base(self.hass, ENTITY_VACUUM_STATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_STATE)
        self.assertEqual(STATE_RETURNING, state.state)

        vacuum.set_fan_speed(self.hass, FAN_SPEEDS[-1],
                             entity_id=ENTITY_VACUUM_STATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_STATE)
        self.assertEqual(FAN_SPEEDS[-1], state.attributes.get(ATTR_FAN_SPEED))

        vacuum.clean_spot(self.hass, entity_id=ENTITY_VACUUM_STATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_STATE)
        self.assertEqual(STATE_CLEANING, state.state)
Пример #5
0
    def test_methods(self):
        """Test if methods call the services as expected."""
        self.hass.states.set(ENTITY_VACUUM_BASIC, STATE_ON)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_BASIC))

        self.hass.states.set(ENTITY_VACUUM_BASIC, STATE_OFF)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_BASIC))

        self.hass.states.set(ENTITY_ID_ALL_VACUUMS, STATE_ON)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass))

        self.hass.states.set(ENTITY_ID_ALL_VACUUMS, STATE_OFF)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass))

        vacuum.turn_on(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        vacuum.turn_off(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        vacuum.toggle(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        vacuum.start_pause(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        vacuum.start_pause(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        vacuum.stop(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE))

        state = self.hass.states.get(ENTITY_VACUUM_COMPLETE)
        self.assertLess(state.attributes.get(ATTR_BATTERY_LEVEL), 100)
        self.assertNotEqual("Charging", state.attributes.get(ATTR_STATUS))

        vacuum.locate(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_COMPLETE)
        self.assertIn("I'm over here", state.attributes.get(ATTR_STATUS))

        vacuum.return_to_base(self.hass, ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_COMPLETE)
        self.assertIn("Returning home", state.attributes.get(ATTR_STATUS))

        vacuum.set_fan_speed(self.hass, FAN_SPEEDS[-1],
                             entity_id=ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_COMPLETE)
        self.assertEqual(FAN_SPEEDS[-1], state.attributes.get(ATTR_FAN_SPEED))

        vacuum.clean_spot(self.hass, entity_id=ENTITY_VACUUM_COMPLETE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_VACUUM_COMPLETE)
        self.assertIn("spot", state.attributes.get(ATTR_STATUS))
        self.assertEqual(STATE_ON, state.state)