Add full test coverage for Comelit light platform (#141736)

* Add full test coverage for Comelit light platform

* cleanup
This commit is contained in:
Simone Chemelli 2025-03-30 14:59:56 +02:00 committed by GitHub
parent 89df6a82b0
commit d3257d96d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,57 @@
# serializer version: 1
# name: test_all_entities[light.light0-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'supported_color_modes': list([
<ColorMode.ONOFF: 'onoff'>,
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'light',
'entity_category': None,
'entity_id': 'light.light0',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': None,
'platform': 'comelit',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': 'serial_bridge_config_entry_id-0',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[light.light0-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'color_mode': None,
'friendly_name': 'Light0',
'supported_color_modes': list([
<ColorMode.ONOFF: 'onoff'>,
]),
'supported_features': <LightEntityFeature: 0>,
}),
'context': <ANY>,
'entity_id': 'light.light0',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---

View File

@ -0,0 +1,76 @@
"""Tests for Comelit SimpleHome light platform."""
from unittest.mock import AsyncMock, patch
import pytest
from syrupy import SnapshotAssertion
from homeassistant.components.light import (
DOMAIN as LIGHT_DOMAIN,
SERVICE_TOGGLE,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
)
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import setup_integration
from tests.common import MockConfigEntry, snapshot_platform
ENTITY_ID = "light.light0"
async def test_all_entities(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
mock_serial_bridge: AsyncMock,
mock_serial_bridge_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test all entities."""
with patch("homeassistant.components.comelit.BRIDGE_PLATFORMS", [Platform.LIGHT]):
await setup_integration(hass, mock_serial_bridge_config_entry)
await snapshot_platform(
hass,
entity_registry,
snapshot(),
mock_serial_bridge_config_entry.entry_id,
)
@pytest.mark.parametrize(
("service", "status"),
[
(SERVICE_TURN_OFF, STATE_OFF),
(SERVICE_TURN_ON, STATE_ON),
(SERVICE_TOGGLE, STATE_ON),
],
)
async def test_light_set_state(
hass: HomeAssistant,
mock_serial_bridge: AsyncMock,
mock_serial_bridge_config_entry: MockConfigEntry,
service: str,
status: str,
) -> None:
"""Test light set state service."""
await setup_integration(hass, mock_serial_bridge_config_entry)
assert (state := hass.states.get(ENTITY_ID))
assert state.state == STATE_OFF
# Test set temperature
await hass.services.async_call(
LIGHT_DOMAIN,
service,
{ATTR_ENTITY_ID: ENTITY_ID},
blocking=True,
)
mock_serial_bridge.set_device_status.assert_called()
assert (state := hass.states.get(ENTITY_ID))
assert state.state == status