Beispiel #1
0
    def test_services(self):
        """Test the provided services."""
        platform = getattr(self.hass.components, "test.light")

        platform.init()
        assert setup_component(self.hass, light.DOMAIN,
                               {light.DOMAIN: {
                                   CONF_PLATFORM: "test"
                               }})

        ent1, ent2, ent3 = platform.ENTITIES

        # Test init
        assert light.is_on(self.hass, ent1.entity_id)
        assert not light.is_on(self.hass, ent2.entity_id)
        assert not light.is_on(self.hass, ent3.entity_id)

        # Test basic turn_on, turn_off, toggle services
        common.turn_off(self.hass, entity_id=ent1.entity_id)
        common.turn_on(self.hass, entity_id=ent2.entity_id)

        self.hass.block_till_done()

        assert not light.is_on(self.hass, ent1.entity_id)
        assert light.is_on(self.hass, ent2.entity_id)

        # turn on all lights
        common.turn_on(self.hass)

        self.hass.block_till_done()

        assert light.is_on(self.hass, ent1.entity_id)
        assert light.is_on(self.hass, ent2.entity_id)
        assert light.is_on(self.hass, ent3.entity_id)

        # turn off all lights
        common.turn_off(self.hass)

        self.hass.block_till_done()

        assert not light.is_on(self.hass, ent1.entity_id)
        assert not light.is_on(self.hass, ent2.entity_id)
        assert not light.is_on(self.hass, ent3.entity_id)

        # turn off all lights by setting brightness to 0
        common.turn_on(self.hass)

        self.hass.block_till_done()

        common.turn_on(self.hass, brightness=0)

        self.hass.block_till_done()

        assert not light.is_on(self.hass, ent1.entity_id)
        assert not light.is_on(self.hass, ent2.entity_id)
        assert not light.is_on(self.hass, ent3.entity_id)

        # toggle all lights
        common.toggle(self.hass)

        self.hass.block_till_done()

        assert light.is_on(self.hass, ent1.entity_id)
        assert light.is_on(self.hass, ent2.entity_id)
        assert light.is_on(self.hass, ent3.entity_id)

        # toggle all lights
        common.toggle(self.hass)

        self.hass.block_till_done()

        assert not light.is_on(self.hass, ent1.entity_id)
        assert not light.is_on(self.hass, ent2.entity_id)
        assert not light.is_on(self.hass, ent3.entity_id)

        # Ensure all attributes process correctly
        common.turn_on(self.hass,
                       ent1.entity_id,
                       transition=10,
                       brightness=20,
                       color_name="blue")
        common.turn_on(self.hass,
                       ent2.entity_id,
                       rgb_color=(255, 255, 255),
                       white_value=255)
        common.turn_on(self.hass, ent3.entity_id, xy_color=(0.4, 0.6))

        self.hass.block_till_done()

        _, data = ent1.last_call("turn_on")
        assert {
            light.ATTR_TRANSITION: 10,
            light.ATTR_BRIGHTNESS: 20,
            light.ATTR_HS_COLOR: (240, 100),
        } == data

        _, data = ent2.last_call("turn_on")
        assert {
            light.ATTR_HS_COLOR: (0, 0),
            light.ATTR_WHITE_VALUE: 255
        } == data

        _, data = ent3.last_call("turn_on")
        assert {light.ATTR_HS_COLOR: (71.059, 100)} == data

        # Ensure attributes are filtered when light is turned off
        common.turn_on(self.hass,
                       ent1.entity_id,
                       transition=10,
                       brightness=0,
                       color_name="blue")
        common.turn_on(
            self.hass,
            ent2.entity_id,
            brightness=0,
            rgb_color=(255, 255, 255),
            white_value=0,
        )
        common.turn_on(self.hass,
                       ent3.entity_id,
                       brightness=0,
                       xy_color=(0.4, 0.6))

        self.hass.block_till_done()

        assert not light.is_on(self.hass, ent1.entity_id)
        assert not light.is_on(self.hass, ent2.entity_id)
        assert not light.is_on(self.hass, ent3.entity_id)

        _, data = ent1.last_call("turn_off")
        assert {light.ATTR_TRANSITION: 10} == data

        _, data = ent2.last_call("turn_off")
        assert {} == data

        _, data = ent3.last_call("turn_off")
        assert {} == data

        # One of the light profiles
        prof_name, prof_h, prof_s, prof_bri = "relax", 35.932, 69.412, 144

        # Test light profiles
        common.turn_on(self.hass, ent1.entity_id, profile=prof_name)
        # Specify a profile and a brightness attribute to overwrite it
        common.turn_on(self.hass,
                       ent2.entity_id,
                       profile=prof_name,
                       brightness=100)

        self.hass.block_till_done()

        _, data = ent1.last_call("turn_on")
        assert {
            light.ATTR_BRIGHTNESS: prof_bri,
            light.ATTR_HS_COLOR: (prof_h, prof_s),
        } == data

        _, data = ent2.last_call("turn_on")
        assert {
            light.ATTR_BRIGHTNESS: 100,
            light.ATTR_HS_COLOR: (prof_h, prof_s),
        } == data

        # Test bad data
        common.turn_on(self.hass)
        common.turn_on(self.hass, ent1.entity_id, profile="nonexisting")
        common.turn_on(self.hass, ent2.entity_id, xy_color=["bla-di-bla", 5])
        common.turn_on(self.hass, ent3.entity_id, rgb_color=[255, None, 2])

        self.hass.block_till_done()

        _, data = ent1.last_call("turn_on")
        assert {} == data

        _, data = ent2.last_call("turn_on")
        assert {} == data

        _, data = ent3.last_call("turn_on")
        assert {} == data

        # faulty attributes will not trigger a service call
        common.turn_on(self.hass,
                       ent1.entity_id,
                       profile=prof_name,
                       brightness="bright")
        common.turn_on(self.hass, ent1.entity_id, rgb_color="yellowish")
        common.turn_on(self.hass, ent2.entity_id, white_value="high")

        self.hass.block_till_done()

        _, data = ent1.last_call("turn_on")
        assert {} == data

        _, data = ent2.last_call("turn_on")
        assert {} == data
Beispiel #2
0
    def test_methods(self):
        """Test if methods call the services as expected."""
        # Test is_on
        self.hass.states.set("light.test", STATE_ON)
        assert light.is_on(self.hass, "light.test")

        self.hass.states.set("light.test", STATE_OFF)
        assert not light.is_on(self.hass, "light.test")

        self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_ON)
        assert light.is_on(self.hass)

        self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_OFF)
        assert not light.is_on(self.hass)

        # Test turn_on
        turn_on_calls = mock_service(self.hass, light.DOMAIN, SERVICE_TURN_ON)

        common.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",
            color_name="color_name_val",
            white_value="white_val",
        )

        self.hass.block_till_done()

        assert 1 == len(turn_on_calls)
        call = turn_on_calls[-1]

        assert light.DOMAIN == call.domain
        assert SERVICE_TURN_ON == call.service
        assert "entity_id_val" == call.data.get(ATTR_ENTITY_ID)
        assert "transition_val" == call.data.get(light.ATTR_TRANSITION)
        assert "brightness_val" == call.data.get(light.ATTR_BRIGHTNESS)
        assert "rgb_color_val" == call.data.get(light.ATTR_RGB_COLOR)
        assert "xy_color_val" == call.data.get(light.ATTR_XY_COLOR)
        assert "profile_val" == call.data.get(light.ATTR_PROFILE)
        assert "color_name_val" == call.data.get(light.ATTR_COLOR_NAME)
        assert "white_val" == call.data.get(light.ATTR_WHITE_VALUE)

        # Test turn_off
        turn_off_calls = mock_service(self.hass, light.DOMAIN,
                                      SERVICE_TURN_OFF)

        common.turn_off(self.hass,
                        entity_id="entity_id_val",
                        transition="transition_val")

        self.hass.block_till_done()

        assert 1 == len(turn_off_calls)
        call = turn_off_calls[-1]

        assert light.DOMAIN == call.domain
        assert SERVICE_TURN_OFF == call.service
        assert "entity_id_val" == call.data[ATTR_ENTITY_ID]
        assert "transition_val" == call.data[light.ATTR_TRANSITION]

        # Test toggle
        toggle_calls = mock_service(self.hass, light.DOMAIN, SERVICE_TOGGLE)

        common.toggle(self.hass,
                      entity_id="entity_id_val",
                      transition="transition_val")

        self.hass.block_till_done()

        assert 1 == len(toggle_calls)
        call = toggle_calls[-1]

        assert light.DOMAIN == call.domain
        assert SERVICE_TOGGLE == call.service
        assert "entity_id_val" == call.data[ATTR_ENTITY_ID]
        assert "transition_val" == call.data[light.ATTR_TRANSITION]
Beispiel #3
0
    def test_methods(self):
        """Test if methods call the services as expected."""
        # Test is_on
        self.hass.states.set('light.test', STATE_ON)
        assert light.is_on(self.hass, 'light.test')

        self.hass.states.set('light.test', STATE_OFF)
        assert not light.is_on(self.hass, 'light.test')

        self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_ON)
        assert light.is_on(self.hass)

        self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_OFF)
        assert not light.is_on(self.hass)

        # Test turn_on
        turn_on_calls = mock_service(
            self.hass, light.DOMAIN, SERVICE_TURN_ON)

        common.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',
            color_name='color_name_val',
            white_value='white_val')

        self.hass.block_till_done()

        assert 1 == len(turn_on_calls)
        call = turn_on_calls[-1]

        assert light.DOMAIN == call.domain
        assert SERVICE_TURN_ON == call.service
        assert 'entity_id_val' == call.data.get(ATTR_ENTITY_ID)
        assert 'transition_val' == call.data.get(light.ATTR_TRANSITION)
        assert 'brightness_val' == call.data.get(light.ATTR_BRIGHTNESS)
        assert 'rgb_color_val' == call.data.get(light.ATTR_RGB_COLOR)
        assert 'xy_color_val' == call.data.get(light.ATTR_XY_COLOR)
        assert 'profile_val' == call.data.get(light.ATTR_PROFILE)
        assert 'color_name_val' == call.data.get(light.ATTR_COLOR_NAME)
        assert 'white_val' == call.data.get(light.ATTR_WHITE_VALUE)

        # Test turn_off
        turn_off_calls = mock_service(
            self.hass, light.DOMAIN, SERVICE_TURN_OFF)

        common.turn_off(
            self.hass, entity_id='entity_id_val', transition='transition_val')

        self.hass.block_till_done()

        assert 1 == len(turn_off_calls)
        call = turn_off_calls[-1]

        assert light.DOMAIN == call.domain
        assert SERVICE_TURN_OFF == call.service
        assert 'entity_id_val' == call.data[ATTR_ENTITY_ID]
        assert 'transition_val' == call.data[light.ATTR_TRANSITION]

        # Test toggle
        toggle_calls = mock_service(
            self.hass, light.DOMAIN, SERVICE_TOGGLE)

        common.toggle(
            self.hass, entity_id='entity_id_val', transition='transition_val')

        self.hass.block_till_done()

        assert 1 == len(toggle_calls)
        call = toggle_calls[-1]

        assert light.DOMAIN == call.domain
        assert SERVICE_TOGGLE == call.service
        assert 'entity_id_val' == call.data[ATTR_ENTITY_ID]
        assert 'transition_val' == call.data[light.ATTR_TRANSITION]
Beispiel #4
0
    def test_services(self):
        """Test the provided services."""
        platform = loader.get_component(self.hass, 'light.test')

        platform.init()
        assert setup_component(self.hass, light.DOMAIN,
                               {light.DOMAIN: {CONF_PLATFORM: 'test'}})

        dev1, dev2, dev3 = platform.DEVICES

        # Test init
        assert light.is_on(self.hass, dev1.entity_id)
        assert not light.is_on(self.hass, dev2.entity_id)
        assert not light.is_on(self.hass, dev3.entity_id)

        # Test basic turn_on, turn_off, toggle services
        common.turn_off(self.hass, entity_id=dev1.entity_id)
        common.turn_on(self.hass, entity_id=dev2.entity_id)

        self.hass.block_till_done()

        assert not light.is_on(self.hass, dev1.entity_id)
        assert light.is_on(self.hass, dev2.entity_id)

        # turn on all lights
        common.turn_on(self.hass)

        self.hass.block_till_done()

        assert light.is_on(self.hass, dev1.entity_id)
        assert light.is_on(self.hass, dev2.entity_id)
        assert light.is_on(self.hass, dev3.entity_id)

        # turn off all lights
        common.turn_off(self.hass)

        self.hass.block_till_done()

        assert not light.is_on(self.hass, dev1.entity_id)
        assert not light.is_on(self.hass, dev2.entity_id)
        assert not light.is_on(self.hass, dev3.entity_id)

        # toggle all lights
        common.toggle(self.hass)

        self.hass.block_till_done()

        assert light.is_on(self.hass, dev1.entity_id)
        assert light.is_on(self.hass, dev2.entity_id)
        assert light.is_on(self.hass, dev3.entity_id)

        # toggle all lights
        common.toggle(self.hass)

        self.hass.block_till_done()

        assert not light.is_on(self.hass, dev1.entity_id)
        assert not light.is_on(self.hass, dev2.entity_id)
        assert not light.is_on(self.hass, dev3.entity_id)

        # Ensure all attributes process correctly
        common.turn_on(self.hass, dev1.entity_id,
                       transition=10, brightness=20, color_name='blue')
        common.turn_on(
            self.hass, dev2.entity_id, rgb_color=(255, 255, 255),
            white_value=255)
        common.turn_on(self.hass, dev3.entity_id, xy_color=(.4, .6))

        self.hass.block_till_done()

        _, data = dev1.last_call('turn_on')
        assert {
            light.ATTR_TRANSITION: 10,
            light.ATTR_BRIGHTNESS: 20,
            light.ATTR_HS_COLOR: (240, 100),
        } == data

        _, data = dev2.last_call('turn_on')
        assert {
            light.ATTR_HS_COLOR: (0, 0),
            light.ATTR_WHITE_VALUE: 255,
        } == data

        _, data = dev3.last_call('turn_on')
        assert {
            light.ATTR_HS_COLOR: (71.059, 100),
        } == data

        # One of the light profiles
        prof_name, prof_h, prof_s, prof_bri = 'relax', 35.932, 69.412, 144

        # Test light profiles
        common.turn_on(self.hass, dev1.entity_id, profile=prof_name)
        # Specify a profile and a brightness attribute to overwrite it
        common.turn_on(
            self.hass, dev2.entity_id,
            profile=prof_name, brightness=100)

        self.hass.block_till_done()

        _, data = dev1.last_call('turn_on')
        assert {
            light.ATTR_BRIGHTNESS: prof_bri,
            light.ATTR_HS_COLOR: (prof_h, prof_s),
        } == data

        _, data = dev2.last_call('turn_on')
        assert {
            light.ATTR_BRIGHTNESS: 100,
            light.ATTR_HS_COLOR: (prof_h, prof_s),
        } == data

        # Test bad data
        common.turn_on(self.hass)
        common.turn_on(self.hass, dev1.entity_id, profile="nonexisting")
        common.turn_on(self.hass, dev2.entity_id, xy_color=["bla-di-bla", 5])
        common.turn_on(self.hass, dev3.entity_id, rgb_color=[255, None, 2])

        self.hass.block_till_done()

        _, data = dev1.last_call('turn_on')
        assert {} == data

        _, data = dev2.last_call('turn_on')
        assert {} == data

        _, data = dev3.last_call('turn_on')
        assert {} == data

        # faulty attributes will not trigger a service call
        common.turn_on(
            self.hass, dev1.entity_id,
            profile=prof_name, brightness='bright')
        common.turn_on(
            self.hass, dev1.entity_id,
            rgb_color='yellowish')
        common.turn_on(
            self.hass, dev2.entity_id,
            white_value='high')

        self.hass.block_till_done()

        _, data = dev1.last_call('turn_on')
        assert {} == data

        _, data = dev2.last_call('turn_on')
        assert {} == data
Beispiel #5
0
    def test_services(self):
        """Test the provided services."""
        platform = loader.get_component(self.hass, 'light.test')

        platform.init()
        assert setup_component(self.hass, light.DOMAIN,
                               {light.DOMAIN: {CONF_PLATFORM: 'test'}})

        dev1, dev2, dev3 = platform.DEVICES

        # Test init
        assert light.is_on(self.hass, dev1.entity_id)
        assert not light.is_on(self.hass, dev2.entity_id)
        assert not light.is_on(self.hass, dev3.entity_id)

        # Test basic turn_on, turn_off, toggle services
        common.turn_off(self.hass, entity_id=dev1.entity_id)
        common.turn_on(self.hass, entity_id=dev2.entity_id)

        self.hass.block_till_done()

        assert not light.is_on(self.hass, dev1.entity_id)
        assert light.is_on(self.hass, dev2.entity_id)

        # turn on all lights
        common.turn_on(self.hass)

        self.hass.block_till_done()

        assert light.is_on(self.hass, dev1.entity_id)
        assert light.is_on(self.hass, dev2.entity_id)
        assert light.is_on(self.hass, dev3.entity_id)

        # turn off all lights
        common.turn_off(self.hass)

        self.hass.block_till_done()

        assert not light.is_on(self.hass, dev1.entity_id)
        assert not light.is_on(self.hass, dev2.entity_id)
        assert not light.is_on(self.hass, dev3.entity_id)

        # toggle all lights
        common.toggle(self.hass)

        self.hass.block_till_done()

        assert light.is_on(self.hass, dev1.entity_id)
        assert light.is_on(self.hass, dev2.entity_id)
        assert light.is_on(self.hass, dev3.entity_id)

        # toggle all lights
        common.toggle(self.hass)

        self.hass.block_till_done()

        assert not light.is_on(self.hass, dev1.entity_id)
        assert not light.is_on(self.hass, dev2.entity_id)
        assert not light.is_on(self.hass, dev3.entity_id)

        # Ensure all attributes process correctly
        common.turn_on(self.hass, dev1.entity_id,
                       transition=10, brightness=20, color_name='blue')
        common.turn_on(
            self.hass, dev2.entity_id, rgb_color=(255, 255, 255),
            white_value=255)
        common.turn_on(self.hass, dev3.entity_id, xy_color=(.4, .6))

        self.hass.block_till_done()

        _, data = dev1.last_call('turn_on')
        assert {
            light.ATTR_TRANSITION: 10,
            light.ATTR_BRIGHTNESS: 20,
            light.ATTR_HS_COLOR: (240, 100),
        } == data

        _, data = dev2.last_call('turn_on')
        assert {
            light.ATTR_HS_COLOR: (0, 0),
            light.ATTR_WHITE_VALUE: 255,
        } == data

        _, data = dev3.last_call('turn_on')
        assert {
            light.ATTR_HS_COLOR: (71.059, 100),
        } == data

        # One of the light profiles
        prof_name, prof_h, prof_s, prof_bri = 'relax', 35.932, 69.412, 144

        # Test light profiles
        common.turn_on(self.hass, dev1.entity_id, profile=prof_name)
        # Specify a profile and a brightness attribute to overwrite it
        common.turn_on(
            self.hass, dev2.entity_id,
            profile=prof_name, brightness=100)

        self.hass.block_till_done()

        _, data = dev1.last_call('turn_on')
        assert {
            light.ATTR_BRIGHTNESS: prof_bri,
            light.ATTR_HS_COLOR: (prof_h, prof_s),
        } == data

        _, data = dev2.last_call('turn_on')
        assert {
            light.ATTR_BRIGHTNESS: 100,
            light.ATTR_HS_COLOR: (prof_h, prof_s),
        } == data

        # Test bad data
        common.turn_on(self.hass)
        common.turn_on(self.hass, dev1.entity_id, profile="nonexisting")
        common.turn_on(self.hass, dev2.entity_id, xy_color=["bla-di-bla", 5])
        common.turn_on(self.hass, dev3.entity_id, rgb_color=[255, None, 2])

        self.hass.block_till_done()

        _, data = dev1.last_call('turn_on')
        assert {} == data

        _, data = dev2.last_call('turn_on')
        assert {} == data

        _, data = dev3.last_call('turn_on')
        assert {} == data

        # faulty attributes will not trigger a service call
        common.turn_on(
            self.hass, dev1.entity_id,
            profile=prof_name, brightness='bright')
        common.turn_on(
            self.hass, dev1.entity_id,
            rgb_color='yellowish')
        common.turn_on(
            self.hass, dev2.entity_id,
            white_value='high')

        self.hass.block_till_done()

        _, data = dev1.last_call('turn_on')
        assert {} == data

        _, data = dev2.last_call('turn_on')
        assert {} == data
Beispiel #6
0
    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)

        common.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',
            color_name='color_name_val',
            white_value='white_val')

        self.hass.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))
        self.assertEqual(
            'color_name_val', call.data.get(light.ATTR_COLOR_NAME))
        self.assertEqual('white_val', call.data.get(light.ATTR_WHITE_VALUE))

        # Test turn_off
        turn_off_calls = mock_service(
            self.hass, light.DOMAIN, SERVICE_TURN_OFF)

        common.turn_off(
            self.hass, entity_id='entity_id_val', transition='transition_val')

        self.hass.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])

        # Test toggle
        toggle_calls = mock_service(
            self.hass, light.DOMAIN, SERVICE_TOGGLE)

        common.toggle(
            self.hass, entity_id='entity_id_val', transition='transition_val')

        self.hass.block_till_done()

        self.assertEqual(1, len(toggle_calls))
        call = toggle_calls[-1]

        self.assertEqual(light.DOMAIN, call.domain)
        self.assertEqual(SERVICE_TOGGLE, call.service)
        self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])
        self.assertEqual('transition_val', call.data[light.ATTR_TRANSITION])
Beispiel #7
0
    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)

        common.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',
                       color_name='color_name_val',
                       white_value='white_val')

        self.hass.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))
        self.assertEqual('color_name_val',
                         call.data.get(light.ATTR_COLOR_NAME))
        self.assertEqual('white_val', call.data.get(light.ATTR_WHITE_VALUE))

        # Test turn_off
        turn_off_calls = mock_service(self.hass, light.DOMAIN,
                                      SERVICE_TURN_OFF)

        common.turn_off(self.hass,
                        entity_id='entity_id_val',
                        transition='transition_val')

        self.hass.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])

        # Test toggle
        toggle_calls = mock_service(self.hass, light.DOMAIN, SERVICE_TOGGLE)

        common.toggle(self.hass,
                      entity_id='entity_id_val',
                      transition='transition_val')

        self.hass.block_till_done()

        self.assertEqual(1, len(toggle_calls))
        call = toggle_calls[-1]

        self.assertEqual(light.DOMAIN, call.domain)
        self.assertEqual(SERVICE_TOGGLE, call.service)
        self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])
        self.assertEqual('transition_val', call.data[light.ATTR_TRANSITION])