mirror of
https://github.com/home-assistant/core.git
synced 2026-09-17 05:58:41 +01:00
150 lines
4.9 KiB
Python
150 lines
4.9 KiB
Python
"""Test the Fibaro light platform."""
|
|
|
|
from unittest.mock import Mock, patch
|
|
|
|
from homeassistant.components.light import (
|
|
ATTR_BRIGHTNESS,
|
|
DOMAIN as LIGHT_DOMAIN,
|
|
ColorMode,
|
|
)
|
|
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import entity_registry as er
|
|
|
|
from .conftest import init_integration
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
async def test_light_setup(
|
|
hass: HomeAssistant,
|
|
entity_registry: er.EntityRegistry,
|
|
mock_fibaro_client: Mock,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_light: Mock,
|
|
mock_room: Mock,
|
|
) -> None:
|
|
"""Test that the light creates an entity."""
|
|
|
|
# Arrange
|
|
mock_fibaro_client.read_rooms.return_value = [mock_room]
|
|
mock_fibaro_client.read_devices.return_value = [mock_light]
|
|
|
|
with patch("homeassistant.components.fibaro.PLATFORMS", [Platform.LIGHT]):
|
|
# Act
|
|
await init_integration(hass, mock_config_entry)
|
|
# Assert
|
|
entry = entity_registry.async_get("light.room_1_test_light_3")
|
|
assert entry
|
|
assert entry.unique_id == "hc2_111111.3"
|
|
assert entry.original_name == "Room 1 Test light"
|
|
|
|
|
|
async def test_light_brightness(
|
|
hass: HomeAssistant,
|
|
mock_fibaro_client: Mock,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_light: Mock,
|
|
mock_room: Mock,
|
|
) -> None:
|
|
"""Test that the light brightness value is translated."""
|
|
|
|
# Arrange
|
|
mock_fibaro_client.read_rooms.return_value = [mock_room]
|
|
mock_fibaro_client.read_devices.return_value = [mock_light]
|
|
|
|
with patch("homeassistant.components.fibaro.PLATFORMS", [Platform.LIGHT]):
|
|
# Act
|
|
await init_integration(hass, mock_config_entry)
|
|
# Assert
|
|
state = hass.states.get("light.room_1_test_light_3")
|
|
assert state.attributes["brightness"] == 51
|
|
assert state.state == "on"
|
|
|
|
|
|
async def test_fgd212_light_brightness_without_setvalue_action(
|
|
hass: HomeAssistant,
|
|
mock_fibaro_client: Mock,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_fgd212_light: Mock,
|
|
mock_room: Mock,
|
|
) -> None:
|
|
"""Test FGD212 dimmers with levelChange but no setValue action."""
|
|
|
|
mock_fibaro_client.read_rooms.return_value = [mock_room]
|
|
mock_fibaro_client.read_devices.return_value = [mock_fgd212_light]
|
|
|
|
with patch("homeassistant.components.fibaro.PLATFORMS", [Platform.LIGHT]):
|
|
await init_integration(hass, mock_config_entry)
|
|
state = hass.states.get("light.room_1_8_spots_116")
|
|
assert state.attributes[ATTR_BRIGHTNESS] == 127
|
|
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
|
assert state.state == "on"
|
|
|
|
|
|
async def test_dimming_via_multilevel_base_type_without_level_change(
|
|
hass: HomeAssistant,
|
|
mock_fibaro_client: Mock,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_multilevel_base_type_light: Mock,
|
|
mock_room: Mock,
|
|
) -> None:
|
|
"""Test dimming via multilevelSwitch base_type when levelChange is absent."""
|
|
|
|
mock_fibaro_client.read_rooms.return_value = [mock_room]
|
|
mock_fibaro_client.read_devices.return_value = [mock_multilevel_base_type_light]
|
|
|
|
with patch("homeassistant.components.fibaro.PLATFORMS", [Platform.LIGHT]):
|
|
await init_integration(hass, mock_config_entry)
|
|
state = hass.states.get("light.room_1_base_type_dimmer_42")
|
|
assert state.attributes[ATTR_BRIGHTNESS] == 51
|
|
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
|
assert state.state == "on"
|
|
|
|
|
|
async def test_zigbee_light_brightness(
|
|
hass: HomeAssistant,
|
|
mock_fibaro_client: Mock,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_zigbee_light: Mock,
|
|
mock_room: Mock,
|
|
) -> None:
|
|
"""Test that the zigbee dimmable light is detected."""
|
|
|
|
# Arrange
|
|
mock_fibaro_client.read_rooms.return_value = [mock_room]
|
|
mock_fibaro_client.read_devices.return_value = [mock_zigbee_light]
|
|
|
|
with patch("homeassistant.components.fibaro.PLATFORMS", [Platform.LIGHT]):
|
|
# Act
|
|
await init_integration(hass, mock_config_entry)
|
|
# Assert
|
|
state = hass.states.get("light.room_1_test_light_12")
|
|
assert state.attributes["brightness"] == 51
|
|
assert state.state == "on"
|
|
|
|
|
|
async def test_light_turn_off(
|
|
hass: HomeAssistant,
|
|
mock_fibaro_client: Mock,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_light: Mock,
|
|
mock_room: Mock,
|
|
) -> None:
|
|
"""Test activate scene is called."""
|
|
# Arrange
|
|
mock_fibaro_client.read_rooms.return_value = [mock_room]
|
|
mock_fibaro_client.read_devices.return_value = [mock_light]
|
|
|
|
with patch("homeassistant.components.fibaro.PLATFORMS", [Platform.LIGHT]):
|
|
await init_integration(hass, mock_config_entry)
|
|
# Act
|
|
await hass.services.async_call(
|
|
LIGHT_DOMAIN,
|
|
SERVICE_TURN_OFF,
|
|
{ATTR_ENTITY_ID: "light.room_1_test_light_3"},
|
|
blocking=True,
|
|
)
|
|
# Assert
|
|
assert mock_light.execute_action.call_count == 1
|