def test_set_fan_speed(self): """Test vacuum service to set the fan speed.""" group_vacuums = ','.join([ENTITY_VACUUM_BASIC, ENTITY_VACUUM_COMPLETE, ENTITY_VACUUM_STATE]) old_state_basic = self.hass.states.get(ENTITY_VACUUM_BASIC) old_state_complete = self.hass.states.get(ENTITY_VACUUM_COMPLETE) old_state_state = self.hass.states.get(ENTITY_VACUUM_STATE) vacuum.set_fan_speed( self.hass, FAN_SPEEDS[0], 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) new_state_state = self.hass.states.get(ENTITY_VACUUM_STATE) self.assertEqual(old_state_basic, new_state_basic) self.assertNotIn(ATTR_FAN_SPEED, new_state_basic.attributes) self.assertNotEqual(old_state_complete, new_state_complete) self.assertEqual(FAN_SPEEDS[1], old_state_complete.attributes[ATTR_FAN_SPEED]) self.assertEqual(FAN_SPEEDS[0], new_state_complete.attributes[ATTR_FAN_SPEED]) self.assertNotEqual(old_state_state, new_state_state) self.assertEqual(FAN_SPEEDS[1], old_state_state.attributes[ATTR_FAN_SPEED]) self.assertEqual(FAN_SPEEDS[0], new_state_state.attributes[ATTR_FAN_SPEED])
def test_set_fan_speed(self): """Test vacuum service to set the fan speed.""" group_vacuums = ','.join( [ENTITY_VACUUM_BASIC, ENTITY_VACUUM_COMPLETE, ENTITY_VACUUM_STATE]) old_state_basic = self.hass.states.get(ENTITY_VACUUM_BASIC) old_state_complete = self.hass.states.get(ENTITY_VACUUM_COMPLETE) old_state_state = self.hass.states.get(ENTITY_VACUUM_STATE) vacuum.set_fan_speed(self.hass, FAN_SPEEDS[0], 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) new_state_state = self.hass.states.get(ENTITY_VACUUM_STATE) self.assertEqual(old_state_basic, new_state_basic) self.assertNotIn(ATTR_FAN_SPEED, new_state_basic.attributes) self.assertNotEqual(old_state_complete, new_state_complete) self.assertEqual(FAN_SPEEDS[1], old_state_complete.attributes[ATTR_FAN_SPEED]) self.assertEqual(FAN_SPEEDS[0], new_state_complete.attributes[ATTR_FAN_SPEED]) self.assertNotEqual(old_state_state, new_state_state) self.assertEqual(FAN_SPEEDS[1], old_state_state.attributes[ATTR_FAN_SPEED]) self.assertEqual(FAN_SPEEDS[0], new_state_state.attributes[ATTR_FAN_SPEED])
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] )
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)
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])
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])
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)
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)