mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
adjust naming of velux light entities according to guidelines (#155850)
This commit is contained in:
@@ -35,6 +35,7 @@ class VeluxLight(VeluxEntity, LightEntity):
|
||||
|
||||
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
||||
_attr_color_mode = ColorMode.BRIGHTNESS
|
||||
_attr_name = None
|
||||
|
||||
node: LighteningDevice
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ import pytest
|
||||
|
||||
from homeassistant.components.velux import DOMAIN
|
||||
from homeassistant.components.velux.binary_sensor import Window
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PASSWORD
|
||||
from homeassistant.components.velux.light import LighteningDevice
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PASSWORD, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -79,10 +81,20 @@ def mock_window() -> AsyncMock:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_pyvlx(mock_window: MagicMock) -> Generator[MagicMock]:
|
||||
def mock_light() -> AsyncMock:
|
||||
"""Create a mock Velux light."""
|
||||
light = AsyncMock(spec=LighteningDevice, autospec=True)
|
||||
light.name = "Test Light"
|
||||
light.serial_number = "0815"
|
||||
light.intensity = MagicMock()
|
||||
return light
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_pyvlx(mock_window: MagicMock, mock_light: MagicMock) -> Generator[MagicMock]:
|
||||
"""Create the library mock and patch PyVLX."""
|
||||
pyvlx = MagicMock()
|
||||
pyvlx.nodes = [mock_window]
|
||||
pyvlx.nodes = [mock_window, mock_light]
|
||||
pyvlx.load_scenes = AsyncMock()
|
||||
pyvlx.load_nodes = AsyncMock()
|
||||
pyvlx.disconnect = AsyncMock()
|
||||
@@ -101,3 +113,18 @@ def mock_config_entry() -> MockConfigEntry:
|
||||
CONF_PASSWORD: "testpw",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def setup_integration(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_pyvlx: MagicMock,
|
||||
platform: Platform,
|
||||
) -> None:
|
||||
"""Set up the integration for testing."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
with patch("homeassistant.components.velux.PLATFORMS", [platform]):
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
43
tests/components/velux/test_light.py
Normal file
43
tests/components/velux/test_light.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""Test Velux light entities."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def platform() -> Platform:
|
||||
"""Fixture to specify platform to test."""
|
||||
return Platform.LIGHT
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_integration")
|
||||
async def test_light_setup(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mock_light: AsyncMock,
|
||||
) -> None:
|
||||
"""Test light entity setup and device association."""
|
||||
|
||||
test_entity_id = f"light.{mock_light.name.lower().replace(' ', '_')}"
|
||||
|
||||
# Check that the entity exists and its name matches the node name (the light is the main feature).
|
||||
state = hass.states.get(test_entity_id)
|
||||
assert state is not None
|
||||
assert state.attributes.get("friendly_name") == mock_light.name
|
||||
|
||||
# Get entity + device entry
|
||||
entity_entry = entity_registry.async_get(test_entity_id)
|
||||
assert entity_entry is not None
|
||||
assert entity_entry.device_id is not None
|
||||
device_entry = device_registry.async_get(entity_entry.device_id)
|
||||
assert device_entry is not None
|
||||
|
||||
# Verify device has correct identifiers + name
|
||||
assert ("velux", mock_light.serial_number) in device_entry.identifiers
|
||||
assert device_entry.name == mock_light.name
|
||||
Reference in New Issue
Block a user