<commit_before>"""Support for lights under the iGlo brand."""
from __future__ import annotations

import math

from iglo import Lamp
import voluptuous as vol

from homeassistant.components.light import (
    ATTR_BRIGHTNESS,
    ATTR_COLOR_TEMP,
    ATTR_EFFECT,
    ATTR_HS_COLOR,
    PLATFORM_SCHEMA,
    SUPPORT_BRIGHTNESS,
    SUPPORT_COLOR,
    SUPPORT_COLOR_TEMP,
    SUPPORT_EFFECT,
    LightEntity,
)
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
import homeassistant.util.color as color_util

DEFAULT_NAME = "iGlo Light"
DEFAULT_PORT = 8080

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_HOST): cv.string,
        vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
        vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
    }
)


def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the iGlo lights."""
    host = config.get(CONF_HOST)
    name = config.get(CONF_NAME)
    port = config.get(CONF_PORT)
    add_entities([IGloLamp(name, host, port)], True)


class IGloLamp(LightEntity):
    """Representation of an iGlo light."""

    def __init__(self, name, host, port):
        """Initialize the light."""

        self._name = name
        self._lamp = Lamp(0, host, port)

    @property
    def name(self):
        """Return the name of the light."""
        return self._name

    @property
    def brightness(self):
        """Return the brightness of this light between 0..255."""
        return int((self._lamp.state()["brightness"] / 200.0) * 255)

    @property
    def color_temp(self):
        """Return the color temperature."""
        return color_util.color_temperature_kelvin_to_mired(self._lamp.state()["white"])

    @property
    def min_mireds(self):
        """Return the coldest color_temp that this light supports."""
        return math.ceil(
            color_util.color_temperature_kelvin_to_mired(self._lamp.max_kelvin)
        )

    @property
    def max_mireds(self):
        """Return the warmest color_temp that this light supports."""
        return math.ceil(
            color_util.color_temperature_kelvin_to_mired(self._lamp.min_kelvin)
        )

    @property
    def hs_color(self):
        """Return the hs value."""
        return color_util.color_RGB_to_hs(*self._lamp.state()["rgb"])

    @property
    def effect(self):
        """Return the current effect."""
        return self._lamp.state()["effect"]

    @property
    def effect_list(self):
        """Return the list of supported effects."""
        return self._lamp.effect_list()

    @property
    def supported_features(self):
        """Flag supported features."""
        return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_COLOR | SUPPORT_EFFECT

    @property
    def is_on(self):
        """Return true if light is on."""
        return self._lamp.state()["on"]

    def turn_on(self, **kwargs):
        """Turn the light on."""
        if not self.is_on:<commit_msg>Migrate iglo light to color_mode (#69278)<commit_after>"""Support for lights under the iGlo brand."""
from __future__ import annotations

import math

from iglo import Lamp
from iglo.lamp import MODE_WHITE
import voluptuous as vol

from homeassistant.components.light import (
    ATTR_BRIGHTNESS,
    ATTR_COLOR_TEMP,
    ATTR_EFFECT,
    ATTR_HS_COLOR,
    COLOR_MODE_COLOR_TEMP,
    COLOR_MODE_HS,
    PLATFORM_SCHEMA,
    SUPPORT_EFFECT,
    LightEntity,
)
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
import homeassistant.util.color as color_util

DEFAULT_NAME = "iGlo Light"
DEFAULT_PORT = 8080

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_HOST): cv.string,
        vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
        vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
    }
)


def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the iGlo lights."""
    host = config.get(CONF_HOST)
    name = config.get(CONF_NAME)
    port = config.get(CONF_PORT)
    add_entities([IGloLamp(name, host, port)], True)


class IGloLamp(LightEntity):
    """Representation of an iGlo light."""

    _attr_supported_color_modes = {COLOR_MODE_COLOR_TEMP, COLOR_MODE_HS}
    _attr_supported_features = SUPPORT_EFFECT

    def __init__(self, name, host, port):
        """Initialize the light."""

        self._name = name
        self._lamp = Lamp(0, host, port)

    @property
    def name(self):
        """Return the name of the light."""
        return self._name

    @property
    def brightness(self):
        """Return the brightness of this light between 0..255."""
        return int((self._lamp.state()["brightness"] / 200.0) * 255)

    @property
    def color_mode(self) -> str | None:
        """Return the color mode of the light."""
        if self._lamp.state()["mode"] == MODE_WHITE:
            return COLOR_MODE_COLOR_TEMP
        # The iglo library reports MODE_WHITE when an effect is active, this is not
        # supported by Home Assistant, just report COLOR_MODE_HS
        return COLOR_MODE_HS

    @property
    def color_temp(self):
        """Return the color temperature."""
        return color_util.color_temperature_kelvin_to_mired(self._lamp.state()["white"])

    @property
    def min_mireds(self):
        """Return the coldest color_temp that this light supports."""
        return math.ceil(
            color_util.color_temperature_kelvin_to_mired(self._lamp.max_kelvin)
        )

    @property
    def max_mireds(self):
        """Return the warmest color_temp that this light supports."""
        return math.ceil(
            color_util.color_temperature_kelvin_to_mired(self._lamp.min_kelvin)
        )

    @property
    def hs_color(self):
        """Return the hs value."""
        return color_util.color_RGB_to_hs(*self._lamp.state()["rgb"])

    @property
    def effect(self):
        """Return the current effect."""
        return self._lamp.state()["effect"]

    @property
    def effect_list(self):
        """Return the list of supported effects."""
        return self._lamp.effect_list()

    @property
    def is_on(self):
        """Return true if light is on."""
        return self._lamp.state()["on"]

    def turn_on(self, **kwargs):
        """Turn the light on."""
        if not self.is_on:
{'fraction_non_alphanumeric': 0.10249465431218817, 'fraction_numerical': 0.005274411974340698, 'mean_word_length': 3.1392330383480824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3417535', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2149, 'n_words': 538}