def test_methods(self): """ Test if methods call the services as expected. """ # Test is_on self.hass.states.set('light.test', STATE_ON) self.assertTrue(light.is_on(self.hass, 'light.test')) self.hass.states.set('light.test', STATE_OFF) self.assertFalse(light.is_on(self.hass, 'light.test')) self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_ON) self.assertTrue(light.is_on(self.hass)) self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_OFF) self.assertFalse(light.is_on(self.hass)) # Test turn_on turn_on_calls = mock_service( self.hass, light.DOMAIN, SERVICE_TURN_ON) light.turn_on( self.hass, entity_id='entity_id_val', transition='transition_val', brightness='brightness_val', rgb_color='rgb_color_val', xy_color='xy_color_val', profile='profile_val') self.hass.pool.block_till_done() self.assertEqual(1, len(turn_on_calls)) call = turn_on_calls[-1] self.assertEqual(light.DOMAIN, call.domain) self.assertEqual(SERVICE_TURN_ON, call.service) self.assertEqual('entity_id_val', call.data.get(ATTR_ENTITY_ID)) self.assertEqual( 'transition_val', call.data.get(light.ATTR_TRANSITION)) self.assertEqual( 'brightness_val', call.data.get(light.ATTR_BRIGHTNESS)) self.assertEqual('rgb_color_val', call.data.get(light.ATTR_RGB_COLOR)) self.assertEqual('xy_color_val', call.data.get(light.ATTR_XY_COLOR)) self.assertEqual('profile_val', call.data.get(light.ATTR_PROFILE)) # Test turn_off turn_off_calls = mock_service( self.hass, light.DOMAIN, SERVICE_TURN_OFF) light.turn_off( self.hass, entity_id='entity_id_val', transition='transition_val') self.hass.pool.block_till_done() self.assertEqual(1, len(turn_off_calls)) call = turn_off_calls[-1] self.assertEqual(light.DOMAIN, call.domain) self.assertEqual(SERVICE_TURN_OFF, call.service) self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID]) self.assertEqual('transition_val', call.data[light.ATTR_TRANSITION])
def test_methods(self): """ Test if methods call the services as expected. """ # Test is_on self.hass.states.set('light.test', STATE_ON) self.assertTrue(light.is_on(self.hass, 'light.test')) self.hass.states.set('light.test', STATE_OFF) self.assertFalse(light.is_on(self.hass, 'light.test')) self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_ON) self.assertTrue(light.is_on(self.hass)) self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_OFF) self.assertFalse(light.is_on(self.hass)) # Test turn_on turn_on_calls = mock_service(self.hass, light.DOMAIN, SERVICE_TURN_ON) light.turn_on(self.hass, entity_id='entity_id_val', transition='transition_val', brightness='brightness_val', rgb_color='rgb_color_val', xy_color='xy_color_val', profile='profile_val') self.hass.pool.block_till_done() self.assertEqual(1, len(turn_on_calls)) call = turn_on_calls[-1] self.assertEqual(light.DOMAIN, call.domain) self.assertEqual(SERVICE_TURN_ON, call.service) self.assertEqual('entity_id_val', call.data.get(ATTR_ENTITY_ID)) self.assertEqual('transition_val', call.data.get(light.ATTR_TRANSITION)) self.assertEqual('brightness_val', call.data.get(light.ATTR_BRIGHTNESS)) self.assertEqual('rgb_color_val', call.data.get(light.ATTR_RGB_COLOR)) self.assertEqual('xy_color_val', call.data.get(light.ATTR_XY_COLOR)) self.assertEqual('profile_val', call.data.get(light.ATTR_PROFILE)) # Test turn_off turn_off_calls = mock_service(self.hass, light.DOMAIN, SERVICE_TURN_OFF) light.turn_off(self.hass, entity_id='entity_id_val', transition='transition_val') self.hass.pool.block_till_done() self.assertEqual(1, len(turn_off_calls)) call = turn_off_calls[-1] self.assertEqual(light.DOMAIN, call.domain) self.assertEqual(SERVICE_TURN_OFF, call.service) self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID]) self.assertEqual('transition_val', call.data[light.ATTR_TRANSITION])
def test_services(self): """ Test if the call service methods conver to correct service calls. """ services = { SERVICE_TURN_ON: media_player.turn_on, SERVICE_TURN_OFF: media_player.turn_off, SERVICE_VOLUME_UP: media_player.volume_up, SERVICE_VOLUME_DOWN: media_player.volume_down, SERVICE_MEDIA_PLAY_PAUSE: media_player.media_play_pause, SERVICE_MEDIA_PLAY: media_player.media_play, SERVICE_MEDIA_PAUSE: media_player.media_pause, SERVICE_MEDIA_NEXT_TRACK: media_player.media_next_track, SERVICE_MEDIA_PREVIOUS_TRACK: media_player.media_previous_track, } for service_name, service_method in services.items(): calls = mock_service(self.hass, media_player.DOMAIN, service_name) service_method(self.hass) self.hass.pool.block_till_done() self.assertEqual(1, len(calls)) call = calls[-1] self.assertEqual(media_player.DOMAIN, call.domain) self.assertEqual(service_name, call.service) service_method(self.hass, self.test_entity) self.hass.pool.block_till_done() self.assertEqual(2, len(calls)) call = calls[-1] self.assertEqual(media_player.DOMAIN, call.domain) self.assertEqual(service_name, call.service) self.assertEqual(self.test_entity, call.data.get(ATTR_ENTITY_ID))
def test_services(self): """ Test if the call service methods conver to correct service calls. """ services = { SERVICE_TURN_OFF: chromecast.turn_off, SERVICE_VOLUME_UP: chromecast.volume_up, SERVICE_VOLUME_DOWN: chromecast.volume_down, SERVICE_MEDIA_PLAY_PAUSE: chromecast.media_play_pause, SERVICE_MEDIA_PLAY: chromecast.media_play, SERVICE_MEDIA_PAUSE: chromecast.media_pause, SERVICE_MEDIA_NEXT_TRACK: chromecast.media_next_track, SERVICE_MEDIA_PREV_TRACK: chromecast.media_prev_track } for service_name, service_method in services.items(): calls = mock_service(self.hass, chromecast.DOMAIN, service_name) service_method(self.hass) self.hass.pool.block_till_done() self.assertEqual(1, len(calls)) call = calls[-1] self.assertEqual(chromecast.DOMAIN, call.domain) self.assertEqual(service_name, call.service) service_method(self.hass, self.test_entity) self.hass.pool.block_till_done() self.assertEqual(2, len(calls)) call = calls[-1] self.assertEqual(chromecast.DOMAIN, call.domain) self.assertEqual(service_name, call.service) self.assertEqual(self.test_entity, call.data.get(ATTR_ENTITY_ID))
def test_services(self): """ Test if the call service methods conver to correct service calls. """ services = { SERVICE_TURN_OFF: chromecast.turn_off, SERVICE_VOLUME_UP: chromecast.volume_up, SERVICE_VOLUME_DOWN: chromecast.volume_down, SERVICE_MEDIA_PLAY_PAUSE: chromecast.media_play_pause, SERVICE_MEDIA_PLAY: chromecast.media_play, SERVICE_MEDIA_PAUSE: chromecast.media_pause, SERVICE_MEDIA_NEXT_TRACK: chromecast.media_next_track, SERVICE_MEDIA_PREV_TRACK: chromecast.media_prev_track } for service_name, service_method in services.items(): calls = mock_service(self.hass, chromecast.DOMAIN, service_name) service_method(self.hass) self.hass._pool.block_till_done() self.assertEqual(1, len(calls)) call = calls[-1] self.assertEqual(call.domain, chromecast.DOMAIN) self.assertEqual(call.service, service_name) self.assertEqual(call.data, {}) service_method(self.hass, self.test_entity) self.hass._pool.block_till_done() self.assertEqual(2, len(calls)) call = calls[-1] self.assertEqual(call.domain, chromecast.DOMAIN) self.assertEqual(call.service, service_name) self.assertEqual(call.data, {ATTR_ENTITY_ID: self.test_entity})