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() assert vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) common.turn_off(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() assert vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) common.stop(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() assert vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) self.hass.states.set(ENTITY_VACUUM_NONE, STATE_OFF) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) common.turn_on(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) common.toggle(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) # Non supported methods: common.start_pause(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) common.locate(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_NONE) assert state.attributes.get(ATTR_STATUS) is None common.return_to_base(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_NONE) assert state.attributes.get(ATTR_STATUS) is None common.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) assert FAN_SPEEDS[-1] != \ state.attributes.get(ATTR_FAN_SPEED) common.clean_spot(self.hass, entity_id=ENTITY_VACUUM_BASIC) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_BASIC) assert "spot" not in state.attributes.get(ATTR_STATUS) assert STATE_OFF == state.state # VacuumDevice should not support start and pause methods. self.hass.states.set(ENTITY_VACUUM_COMPLETE, STATE_ON) self.hass.block_till_done() assert vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) common.pause(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() assert vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.states.set(ENTITY_VACUUM_COMPLETE, STATE_OFF) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) common.start(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) # StateVacuumDevice does not support on/off common.turn_on(self.hass, entity_id=ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) assert STATE_CLEANING != state.state common.turn_off(self.hass, entity_id=ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) assert STATE_RETURNING != state.state common.toggle(self.hass, entity_id=ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) assert STATE_CLEANING != state.state
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() assert vacuum.is_on(self.hass, ENTITY_VACUUM_BASIC) self.hass.states.set(ENTITY_VACUUM_BASIC, STATE_OFF) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_BASIC) self.hass.states.set(ENTITY_ID_ALL_VACUUMS, STATE_ON) self.hass.block_till_done() assert vacuum.is_on(self.hass) self.hass.states.set(ENTITY_ID_ALL_VACUUMS, STATE_OFF) self.hass.block_till_done() assert not vacuum.is_on(self.hass) common.turn_on(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() assert vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) common.turn_off(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) common.toggle(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() assert vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) common.start_pause(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) common.start_pause(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() assert vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) common.stop(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) state = self.hass.states.get(ENTITY_VACUUM_COMPLETE) assert state.attributes.get(ATTR_BATTERY_LEVEL) < 100 assert "Charging" != state.attributes.get(ATTR_STATUS) common.locate(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_COMPLETE) assert "I'm over here" in state.attributes.get(ATTR_STATUS) common.return_to_base(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_COMPLETE) assert "Returning home" in state.attributes.get(ATTR_STATUS) common.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) assert FAN_SPEEDS[-1] == state.attributes.get(ATTR_FAN_SPEED) common.clean_spot(self.hass, entity_id=ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_COMPLETE) assert "spot" in state.attributes.get(ATTR_STATUS) assert STATE_ON == state.state common.start(self.hass, ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) assert STATE_CLEANING == state.state common.pause(self.hass, ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) assert STATE_PAUSED == state.state common.stop(self.hass, ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) assert STATE_IDLE == state.state state = self.hass.states.get(ENTITY_VACUUM_STATE) assert state.attributes.get(ATTR_BATTERY_LEVEL) < 100 assert STATE_DOCKED != state.state common.return_to_base(self.hass, ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) assert STATE_RETURNING == state.state common.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) assert FAN_SPEEDS[-1] == state.attributes.get(ATTR_FAN_SPEED) common.clean_spot(self.hass, entity_id=ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) assert STATE_CLEANING == state.state
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)) common.turn_on(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE)) common.turn_off(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE)) common.toggle(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE)) common.start_pause(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE)) common.start_pause(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE)) common.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)) common.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)) common.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)) common.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)) common.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) common.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) common.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) common.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) common.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) common.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)) common.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)
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, })) common.turn_on(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'turn_on', 0, False) self.mock_publish.async_publish.reset_mock() common.turn_off(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'turn_off', 0, False) self.mock_publish.async_publish.reset_mock() common.stop(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'stop', 0, False) self.mock_publish.async_publish.reset_mock() common.clean_spot(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'clean_spot', 0, False) self.mock_publish.async_publish.reset_mock() common.locate(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'locate', 0, False) self.mock_publish.async_publish.reset_mock() common.start_pause(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'start_pause', 0, False) self.mock_publish.async_publish.reset_mock() common.return_to_base(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'return_to_base', 0, False) self.mock_publish.async_publish.reset_mock() common.set_fan_speed(self.hass, 'high', 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/set_fan_speed', 'high', 0, False) self.mock_publish.async_publish.reset_mock() common.send_command(self.hass, '44 FE 93', entity_id='vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/send_command', '44 FE 93', 0, False)
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)) common.turn_off(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE)) common.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)) common.turn_on(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE)) common.toggle(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE)) # Non supported methods: common.start_pause(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE)) common.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)) common.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)) common.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)) common.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) # VacuumDevice should not support start and pause methods. self.hass.states.set(ENTITY_VACUUM_COMPLETE, STATE_ON) self.hass.block_till_done() self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE)) common.pause(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE)) self.hass.states.set(ENTITY_VACUUM_COMPLETE, STATE_OFF) self.hass.block_till_done() self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE)) common.start(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE)) # StateVacuumDevice does not support on/off common.turn_on(self.hass, entity_id=ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) self.assertNotEqual(STATE_CLEANING, state.state) common.turn_off(self.hass, entity_id=ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) self.assertNotEqual(STATE_RETURNING, state.state) common.toggle(self.hass, entity_id=ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) self.assertNotEqual(STATE_CLEANING, state.state)
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() assert vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) common.turn_off(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() assert vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) common.stop(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() assert vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) self.hass.states.set(ENTITY_VACUUM_NONE, STATE_OFF) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) common.turn_on(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) common.toggle(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) # Non supported methods: common.start_pause(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_NONE) common.locate(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_NONE) assert state.attributes.get(ATTR_STATUS) is None common.return_to_base(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_NONE) assert state.attributes.get(ATTR_STATUS) is None common.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) assert FAN_SPEEDS[-1] != state.attributes.get(ATTR_FAN_SPEED) common.clean_spot(self.hass, entity_id=ENTITY_VACUUM_BASIC) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_BASIC) assert "spot" not in state.attributes.get(ATTR_STATUS) assert STATE_OFF == state.state # VacuumDevice should not support start and pause methods. self.hass.states.set(ENTITY_VACUUM_COMPLETE, STATE_ON) self.hass.block_till_done() assert vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) common.pause(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() assert vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.states.set(ENTITY_VACUUM_COMPLETE, STATE_OFF) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) common.start(self.hass, ENTITY_VACUUM_COMPLETE) self.hass.block_till_done() assert not vacuum.is_on(self.hass, ENTITY_VACUUM_COMPLETE) # StateVacuumDevice does not support on/off common.turn_on(self.hass, entity_id=ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) assert STATE_CLEANING != state.state common.turn_off(self.hass, entity_id=ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) assert STATE_RETURNING != state.state common.toggle(self.hass, entity_id=ENTITY_VACUUM_STATE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_VACUUM_STATE) assert STATE_CLEANING != state.state
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, })) common.turn_on(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'turn_on', 0, False) self.mock_publish.async_publish.reset_mock() common.turn_off(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'turn_off', 0, False) self.mock_publish.async_publish.reset_mock() common.stop(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'stop', 0, False) self.mock_publish.async_publish.reset_mock() common.clean_spot(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'clean_spot', 0, False) self.mock_publish.async_publish.reset_mock() common.locate(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'locate', 0, False) self.mock_publish.async_publish.reset_mock() common.start_pause(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'start_pause', 0, False) self.mock_publish.async_publish.reset_mock() common.return_to_base(self.hass, 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/command', 'return_to_base', 0, False) self.mock_publish.async_publish.reset_mock() common.set_fan_speed(self.hass, 'high', 'vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/set_fan_speed', 'high', 0, False) self.mock_publish.async_publish.reset_mock() common.send_command(self.hass, '44 FE 93', entity_id='vacuum.mqtttest') self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'vacuum/send_command', '44 FE 93', 0, False)
async def test_all_commands(hass, mock_publish): """Test simple commands to the vacuum.""" default_config[mqttvacuum.CONF_SUPPORTED_FEATURES] = \ mqttvacuum.services_to_strings(mqttvacuum.ALL_SERVICES) assert await async_setup_component(hass, vacuum.DOMAIN, { vacuum.DOMAIN: default_config, }) common.turn_on(hass, 'vacuum.mqtttest') await hass.async_block_till_done() await hass.async_block_till_done() mock_publish.async_publish.assert_called_once_with('vacuum/command', 'turn_on', 0, False) mock_publish.async_publish.reset_mock() common.turn_off(hass, 'vacuum.mqtttest') await hass.async_block_till_done() await hass.async_block_till_done() mock_publish.async_publish.assert_called_once_with('vacuum/command', 'turn_off', 0, False) mock_publish.async_publish.reset_mock() common.stop(hass, 'vacuum.mqtttest') await hass.async_block_till_done() await hass.async_block_till_done() mock_publish.async_publish.assert_called_once_with('vacuum/command', 'stop', 0, False) mock_publish.async_publish.reset_mock() common.clean_spot(hass, 'vacuum.mqtttest') await hass.async_block_till_done() await hass.async_block_till_done() mock_publish.async_publish.assert_called_once_with('vacuum/command', 'clean_spot', 0, False) mock_publish.async_publish.reset_mock() common.locate(hass, 'vacuum.mqtttest') await hass.async_block_till_done() await hass.async_block_till_done() mock_publish.async_publish.assert_called_once_with('vacuum/command', 'locate', 0, False) mock_publish.async_publish.reset_mock() common.start_pause(hass, 'vacuum.mqtttest') await hass.async_block_till_done() await hass.async_block_till_done() mock_publish.async_publish.assert_called_once_with('vacuum/command', 'start_pause', 0, False) mock_publish.async_publish.reset_mock() common.return_to_base(hass, 'vacuum.mqtttest') await hass.async_block_till_done() await hass.async_block_till_done() mock_publish.async_publish.assert_called_once_with('vacuum/command', 'return_to_base', 0, False) mock_publish.async_publish.reset_mock() common.set_fan_speed(hass, 'high', 'vacuum.mqtttest') await hass.async_block_till_done() await hass.async_block_till_done() mock_publish.async_publish.assert_called_once_with('vacuum/set_fan_speed', 'high', 0, False) mock_publish.async_publish.reset_mock() common.send_command(hass, '44 FE 93', entity_id='vacuum.mqtttest') await hass.async_block_till_done() await hass.async_block_till_done() mock_publish.async_publish.assert_called_once_with('vacuum/send_command', '44 FE 93', 0, False) mock_publish.async_publish.reset_mock() common.send_command(hass, '44 FE 93', {"key": "value"}, entity_id='vacuum.mqtttest') await hass.async_block_till_done() await hass.async_block_till_done() assert json.loads(mock_publish.async_publish.mock_calls[-1][1][1]) == { "command": "44 FE 93", "key": "value" }