"""Test Evil Genius Labs light."""
from unittest.mock import patch

import pytest

from homeassistant.components.light import (
    ATTR_COLOR_MODE,
    ATTR_SUPPORTED_COLOR_MODES,
    ColorMode,
    LightEntityFeature,
)
from homeassistant.const import ATTR_SUPPORTED_FEATURES


@pytest.mark.parametrize("platforms", [("light",)])
async def test_works(hass, setup_evil_genius_labs):
    """Test it works."""
    state = hass.states.get("light.fibonacci256_23d4")
    assert state is not None
    assert state.state == "on"
    assert state.attributes["brightness"] == 128
    assert state.attributes[ATTR_COLOR_MODE] == ColorMode.RGB
    assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.RGB]
    assert state.attributes[ATTR_SUPPORTED_FEATURES] == LightEntityFeature.EFFECT


@pytest.mark.parametrize("platforms", [("light",)])
async def test_turn_on_color(hass, setup_evil_genius_labs):
    """Test turning on with a color."""
    with patch(
        "pyevilgenius.EvilGeniusDevice.set_path_value"
    ) as mock_set_path_value, patch(
        "pyevilgenius.EvilGeniusDevice.set_rgb_color"
    ) as mock_set_rgb_color:
        await hass.services.async_call(
            "light",
            "turn_on",
            {
                "entity_id": "light.fibonacci256_23d4",
                "brightness": 100,
                "rgb_color": (10, 20, 30),
            },
            blocking=True,
        )

    assert len(mock_set_path_value.mock_calls) == 2
    mock_set_path_value.mock_calls[0][1] == ("brightness", 100)
    mock_set_path_value.mock_calls[1][1] == ("power", 1)

    assert len(mock_set_rgb_color.mock_calls) == 1
    mock_set_rgb_color.mock_calls[0][1] == (10, 20, 30)


@pytest.mark.parametrize("platforms", [("light",)])
async def test_turn_on_effect(hass, setup_evil_genius_labs):
    """Test turning on with an effect."""
    with patch("pyevilgenius.EvilGeniusDevice.set_path_value") as mock_set_path_value:
        await hass.services.async_call(
            "light",
            "turn_on",
            {
                "entity_id": "light.fibonacci256_23d4",
                "effect": "Pride Playground",
            },
            blocking=True,
        )

    assert len(mock_set_path_value.mock_calls) == 2
    mock_set_path_value.mock_calls[0][1] == ("pattern", 4)
    mock_set_path_value.mock_calls[1][1] == ("power", 1)


@pytest.mark.parametrize("platforms", [("light",)])
async def test_turn_off(hass, setup_evil_genius_labs):
    """Test turning off."""
    with patch("pyevilgenius.EvilGeniusDevice.set_path_value") as mock_set_path_value:
        await hass.services.async_call(
            "light",
            "turn_off",
            {
                "entity_id": "light.fibonacci256_23d4",
            },
            blocking=True,
        )

    assert len(mock_set_path_value.mock_calls) == 1
    mock_set_path_value.mock_calls[0][1] == ("power", 0)

[((15, 1, 15, 51), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(15, 25, 15, 36): '"""platforms"""', (15, 38, 15, 50): "[('light',)]"}, {}), "('platforms', [('light',)])", False, 'import pytest\n'), ((27, 1, 27, 51), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(27, 25, 27, 36): '"""platforms"""', (27, 38, 27, 50): "[('light',)]"}, {}), "('platforms', [('light',)])", False, 'import pytest\n'), ((54, 1, 54, 51), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(54, 25, 54, 36): '"""platforms"""', (54, 38, 54, 50): "[('light',)]"}, {}), "('platforms', [('light',)])", False, 'import pytest\n'), ((73, 1, 73, 51), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(73, 25, 73, 36): '"""platforms"""', (73, 38, 73, 50): "[('light',)]"}, {}), "('platforms', [('light',)])", False, 'import pytest\n'), ((30, 9, 32, 5), 'unittest.mock.patch', 'patch', ({(31, 8, 31, 54): '"""pyevilgenius.EvilGeniusDevice.set_path_value"""'}, {}), "('pyevilgenius.EvilGeniusDevice.set_path_value')", False, 'from unittest.mock import patch\n'), ((32, 30, 34, 5), 'unittest.mock.patch', 'patch', ({(33, 8, 33, 53): '"""pyevilgenius.EvilGeniusDevice.set_rgb_color"""'}, {}), "('pyevilgenius.EvilGeniusDevice.set_rgb_color')", False, 'from unittest.mock import patch\n'), ((57, 9, 57, 62), 'unittest.mock.patch', 'patch', ({(57, 15, 57, 61): '"""pyevilgenius.EvilGeniusDevice.set_path_value"""'}, {}), "('pyevilgenius.EvilGeniusDevice.set_path_value')", False, 'from unittest.mock import patch\n'), ((76, 9, 76, 62), 'unittest.mock.patch', 'patch', ({(76, 15, 76, 61): '"""pyevilgenius.EvilGeniusDevice.set_path_value"""'}, {}), "('pyevilgenius.EvilGeniusDevice.set_path_value')", False, 'from unittest.mock import patch\n')]