async def _service_interceptor_turn_on_handler(
        self,
        call: ServiceCall,
        service_data: ServiceData,
    ) -> None:
        """Intercept `light.turn_on` and `light.toggle` service calls and adapt them.

        It is possible that the calls are made for multiple lights at once,
        which in turn might be in different switches or no switches at all.
        If there are lights that are not all in a single switch, we need to
        make multiple calls to `light.turn_on` with the correct entity IDs.
        One of these calls can be intercepted and adapted, the others need to
        be adapted by calling `_adapt_light` with the correct entity IDs or
        by calling `light.turn_on` directly.

        We create a mapping from switch to entity IDs and keep a list
        of skipped lights which are lights in no switches or in switches that
        are off or lights that are already on.

        If there is only one switch and 0 skipped lights, we just intercept the
        call directly.

        If there are multiple switches and skipped lights, we can adapt the call
        for one of the switches to include only the lights in that switch and
        need to call `_adapt_light` for the other switches with their
        entity_ids. For skipped lights, we call light.turn_on directly with the
        entity_ids and original service data.

        If there are only skipped lights, we can use the intercepted call
        directly.
        """
        is_skipped_hash = is_our_context(call.context, "skipped")
        _LOGGER.debug(
            "(0) _service_interceptor_turn_on_handler: call.context.id='%s', is_skipped_hash='%s'",
            call.context.id,
            is_skipped_hash,
        )
        if is_our_context(call.context) and not is_skipped_hash:
            # Don't adapt our own service calls, but do re-adapt calls that
            # were skipped by us
            return

        if (
            ATTR_EFFECT in service_data[CONF_PARAMS]
            or ATTR_FLASH in service_data[CONF_PARAMS]
        ):
            return

        _LOGGER.debug(
            "(1) _service_interceptor_turn_on_handler: call='%s', service_data='%s'",
            call,
            service_data,
        )

        # Because `_service_interceptor_turn_on_single_light_handler` modifies the
        # original service data, we need to make a copy of it to use in the `skipped` call
        service_data_copy = deepcopy(service_data)

        entity_ids = self._get_entity_list(service_data)
        # Note: we do not expand light groups anywhere in this method, instead
        # we skip them and rely on the followup call that HA will make
        # with the expanded entity IDs.

        switch_to_eids, switch_name_mapping, skipped = self._separate_entity_ids(
            entity_ids,
            service_data,
        )

        (
            switch_to_eids,
            switch_name_mapping,
            skipped,
        ) = self._correct_for_multi_light_intercept(
            entity_ids,
            switch_to_eids,
            switch_name_mapping,
            skipped,
        )
        _LOGGER.debug(
            "(2) _service_interceptor_turn_on_handler: switch_to_eids='%s', skipped='%s'",
            switch_to_eids,
            skipped,
        )

        def modify_service_data(service_data, entity_ids):
            """Modify the service data to contain the entity IDs."""
            service_data.pop(ATTR_ENTITY_ID, None)
            service_data.pop(ATTR_AREA_ID, None)
            service_data[ATTR_ENTITY_ID] = entity_ids
            return service_data

        # Intercept the call for first switch and call _adapt_light for the rest
        has_intercepted = False  # Can only intercept a turn_on call once
        for adaptive_switch_name, _entity_ids in switch_to_eids.items():
            switch = switch_name_mapping[adaptive_switch_name]
            transition = service_data[CONF_PARAMS].get(
                ATTR_TRANSITION,
                switch.initial_transition,
            )
            if not has_intercepted:
                _LOGGER.debug(
                    "(3) _service_interceptor_turn_on_handler: intercepting entity_ids='%s'",
                    _entity_ids,
                )
                await self._service_interceptor_turn_on_single_light_handler(
                    entity_ids=_entity_ids,
                    switch=switch,
                    transition=transition,
                    call=call,
                    data=modify_service_data(service_data, _entity_ids),
                )
                has_intercepted = True
                continue

            for eid in _entity_ids:
                # Must add a new context otherwise _adapt_light will bail out
                context = switch.create_context("intercept")
                self.clear_proactively_adapting(eid)
                self.set_proactively_adapting(context.id, eid)
                _LOGGER.debug(
                    "(4) _service_interceptor_turn_on_handler: calling `_adapt_light` with eid='%s', context='%s', transition='%s'",
                    eid,
                    context,
                    transition,
                )
                await switch._adapt_light(
                    light=eid,
                    context=context,
                    transition=transition,
                )

        # Call light.turn_on service for skipped entities
        if skipped:
            if not has_intercepted:
                assert set(skipped) == set(entity_ids)
                return  # The call will be intercepted with the original data
            # Call light turn_on service for skipped entities
            context = switch.create_context("skipped")
            _LOGGER.debug(
                "(5) _service_interceptor_turn_on_handler: calling `light.turn_on` with skipped='%s', service_data: '%s', context='%s'",
                skipped,
                service_data_copy,  # This is the original service data
                context.id,
            )
            service_data = {ATTR_ENTITY_ID: skipped, **service_data_copy[CONF_PARAMS]}
            if (
                ATTR_COLOR_TEMP in service_data
                and ATTR_COLOR_TEMP_KELVIN in service_data
            ):
                # ATTR_COLOR_TEMP and ATTR_COLOR_TEMP_KELVIN are mutually exclusive
                del service_data[ATTR_COLOR_TEMP]
            await self.hass.services.async_call(
                LIGHT_DOMAIN,
                SERVICE_TURN_ON,
                service_data,
                blocking=True,
                context=context,
            )
Intercept `light.turn_on` and `light.toggle` service calls and adapt them.

        It is possible that the calls are made for multiple lights at once,
        which in turn might be in different switches or no switches at all.
        If there are lights that are not all in a single switch, we need to
        make multiple calls to `light.turn_on` with the correct entity IDs.
        One of these calls can be intercepted and adapted, the others need to
        be adapted by calling `_adapt_light` with the correct entity IDs or
        by calling `light.turn_on` directly.

        We create a mapping from switch to entity IDs and keep a list
        of skipped lights which are lights in no switches or in switches that
        are off or lights that are already on.

        If there is only one switch and 0 skipped lights, we just intercept the
        call directly.

        If there are multiple switches and skipped lights, we can adapt the call
        for one of the switches to include only the lights in that switch and
        need to call `_adapt_light` for the other switches with their
        entity_ids. For skipped lights, we call light.turn_on directly with the
        entity_ids and original service data.

        If there are only skipped lights, we can use the intercepted call
        directly.
        
custom_components/adaptive_lighting/switch.py