Repository: home-assistant/core
File: homeassistant/components/homematicip_cloud/light.py (Python)

Code before:

    hue = int(color[0])
    saturation = int(color[1])
    if saturation < 5:
        return RGBColorState.WHITE
    if 30 < hue <= 90:
        return RGBColorState.YELLOW
    if 90 < hue <= 160:
        return RGBColorState.GREEN
    if 150 < hue <= 210:
        return RGBColorState.TURQUOISE
    if 210 < hue <= 270:
        return RGBColorState.BLUE
    if 270 < hue <= 330:
        return RGBColorState.PURPLE
    return RGBColorState.RED


class HomematicipOpticalSignalLight(HomematicipGenericEntity, LightEntity):
    """Representation of HomematicIP WiredPushButton LED light."""

    _attr_color_mode = ColorMode.HS
    _attr_supported_color_modes = {ColorMode.HS}
    _attr_supported_features = LightEntityFeature.EFFECT

    _effect_list = [
        OpticalSignalBehaviour.BILLOW_MIDDLE,
        OpticalSignalBehaviour.BLINKING_MIDDLE,
        OpticalSignalBehaviour.FLASH_MIDDLE,
        OpticalSignalBehaviour.OFF,
        OpticalSignalBehaviour.ON,
    ]

    _color_switcher: dict[str, tuple[float, float]] = {
        RGBColorState.WHITE: (0.0, 0.0),
        RGBColorState.RED: (0.0, 100.0),
        RGBColorState.YELLOW: (60.0, 100.0),
        RGBColorState.GREEN: (120.0, 100.0),
        RGBColorState.TURQUOISE: (180.0, 100.0),
        RGBColorState.BLUE: (240.0, 100.0),
        RGBColorState.PURPLE: (300.0, 100.0),
    }

    def __init__(
        self,
        hap: HomematicipHAP,
        device: WiredPushButton,
        channel_index: int,
        led_number: int,
    ) -> None:
        """Initialize the optical signal light entity."""

Review comment (suggestion):
I am not sure if you have a default implementation of `effect_list` property in the entities, but you could just set this to `_attr_effect_list` instead

Code after:

    hue = int(color[0])
    saturation = int(color[1])
    if saturation < 5:
        return RGBColorState.WHITE
    if 30 < hue <= 90:
        return RGBColorState.YELLOW
    if 90 < hue <= 160:
        return RGBColorState.GREEN
    if 150 < hue <= 210:
        return RGBColorState.TURQUOISE
    if 210 < hue <= 270:
        return RGBColorState.BLUE
    if 270 < hue <= 330:
        return RGBColorState.PURPLE
    return RGBColorState.RED


class HomematicipOpticalSignalLight(HomematicipGenericEntity, LightEntity):
    """Representation of HomematicIP WiredPushButton LED light."""

    _attr_color_mode = ColorMode.HS
    _attr_supported_color_modes = {ColorMode.HS}
    _attr_supported_features = LightEntityFeature.EFFECT
    _attr_translation_key = "optical_signal_light"

    _effect_to_behaviour: dict[str, OpticalSignalBehaviour] = {
        "on": OpticalSignalBehaviour.ON,
        "blinking": OpticalSignalBehaviour.BLINKING_MIDDLE,
        "flash": OpticalSignalBehaviour.FLASH_MIDDLE,
        "billow": OpticalSignalBehaviour.BILLOW_MIDDLE,
    }
    _behaviour_to_effect: dict[OpticalSignalBehaviour, str] = {
        v: k for k, v in _effect_to_behaviour.items()
    }

    _attr_effect_list = list(_effect_to_behaviour)

    _color_switcher: dict[str, tuple[float, float]] = {
        RGBColorState.WHITE: (0.0, 0.0),
        RGBColorState.RED: (0.0, 100.0),
        RGBColorState.YELLOW: (60.0, 100.0),
        RGBColorState.GREEN: (120.0, 100.0),
        RGBColorState.TURQUOISE: (180.0, 100.0),
        RGBColorState.BLUE: (240.0, 100.0),
        RGBColorState.PURPLE: (300.0, 100.0),
    }

    def __init__(
        self,
        hap: HomematicipHAP,