Refactor WLED select tests (#89219)

pull/90026/head^2
Franck Nijhof 2023-03-21 22:32:41 +01:00 committed by GitHub
parent 980425508a
commit f98d685154
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 522 additions and 370 deletions

View File

@ -0,0 +1,431 @@
# serializer version: 1
# name: test_color_palette_state[rgb-select.wled_rgb_light_live_override-2-live-called_with1]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'WLED RGB Light Live override',
'icon': 'mdi:theater',
'options': list([
'0',
'1',
'2',
]),
}),
'context': <ANY>,
'entity_id': 'select.wled_rgb_light_live_override',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '0',
})
# ---
# name: test_color_palette_state[rgb-select.wled_rgb_light_live_override-2-live-called_with1].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'options': list([
'0',
'1',
'2',
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'select',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'select.wled_rgb_light_live_override',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': 'mdi:theater',
'original_name': 'Live override',
'platform': 'wled',
'supported_features': 0,
'translation_key': 'live_override',
'unique_id': 'aabbccddeeff_live_override',
'unit_of_measurement': None,
})
# ---
# name: test_color_palette_state[rgb-select.wled_rgb_light_live_override-2-live-called_with1].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': 'http://127.0.0.1',
'connections': set({
tuple(
'mac',
'aa:bb:cc:dd:ee:ff',
),
}),
'disabled_by': None,
'entry_type': None,
'hw_version': 'esp8266',
'id': <ANY>,
'identifiers': set({
tuple(
'wled',
'aabbccddeeff',
),
}),
'is_new': False,
'manufacturer': 'WLED',
'model': 'DIY light',
'name': 'WLED RGB Light',
'name_by_user': None,
'suggested_area': None,
'sw_version': '0.8.5',
'via_device_id': None,
})
# ---
# name: test_color_palette_state[rgb-select.wled_rgb_light_segment_1_color_palette-Icefire-segment-called_with0]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'WLED RGB Light Segment 1 color palette',
'icon': 'mdi:palette-outline',
'options': list([
'Analogous',
'April Night',
'Autumn',
'Based on Primary',
'Based on Set',
'Beach',
'Beech',
'Breeze',
'C9',
'Cloud',
'Cyane',
'Default',
'Departure',
'Drywet',
'Fire',
'Forest',
'Grintage',
'Hult',
'Hult 64',
'Icefire',
'Jul',
'Landscape',
'Lava',
'Light Pink',
'Magenta',
'Magred',
'Ocean',
'Orange & Teal',
'Orangery',
'Party',
'Pastel',
'Primary Color',
'Rainbow',
'Rainbow Bands',
'Random Cycle',
'Red & Blue',
'Rewhi',
'Rivendell',
'Sakura',
'Set Colors',
'Sherbet',
'Splash',
'Sunset',
'Sunset 2',
'Tertiary',
'Tiamat',
'Vintage',
'Yelblu',
'Yellowout',
'Yelmag',
]),
}),
'context': <ANY>,
'entity_id': 'select.wled_rgb_light_segment_1_color_palette',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'Random Cycle',
})
# ---
# name: test_color_palette_state[rgb-select.wled_rgb_light_segment_1_color_palette-Icefire-segment-called_with0].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'options': list([
'Analogous',
'April Night',
'Autumn',
'Based on Primary',
'Based on Set',
'Beach',
'Beech',
'Breeze',
'C9',
'Cloud',
'Cyane',
'Default',
'Departure',
'Drywet',
'Fire',
'Forest',
'Grintage',
'Hult',
'Hult 64',
'Icefire',
'Jul',
'Landscape',
'Lava',
'Light Pink',
'Magenta',
'Magred',
'Ocean',
'Orange & Teal',
'Orangery',
'Party',
'Pastel',
'Primary Color',
'Rainbow',
'Rainbow Bands',
'Random Cycle',
'Red & Blue',
'Rewhi',
'Rivendell',
'Sakura',
'Set Colors',
'Sherbet',
'Splash',
'Sunset',
'Sunset 2',
'Tertiary',
'Tiamat',
'Vintage',
'Yelblu',
'Yellowout',
'Yelmag',
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'select',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'select.wled_rgb_light_segment_1_color_palette',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': 'mdi:palette-outline',
'original_name': 'Segment 1 color palette',
'platform': 'wled',
'supported_features': 0,
'translation_key': None,
'unique_id': 'aabbccddeeff_palette_1',
'unit_of_measurement': None,
})
# ---
# name: test_color_palette_state[rgb-select.wled_rgb_light_segment_1_color_palette-Icefire-segment-called_with0].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': 'http://127.0.0.1',
'connections': set({
tuple(
'mac',
'aa:bb:cc:dd:ee:ff',
),
}),
'disabled_by': None,
'entry_type': None,
'hw_version': 'esp8266',
'id': <ANY>,
'identifiers': set({
tuple(
'wled',
'aabbccddeeff',
),
}),
'is_new': False,
'manufacturer': 'WLED',
'model': 'DIY light',
'name': 'WLED RGB Light',
'name_by_user': None,
'suggested_area': None,
'sw_version': '0.8.5',
'via_device_id': None,
})
# ---
# name: test_color_palette_state[rgbw-select.wled_rgbw_light_playlist-Playlist 2-playlist-called_with2]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'WLED RGBW Light Playlist',
'icon': 'mdi:play-speed',
'options': list([
'Playlist 1',
'Playlist 2',
]),
}),
'context': <ANY>,
'entity_id': 'select.wled_rgbw_light_playlist',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'Playlist 1',
})
# ---
# name: test_color_palette_state[rgbw-select.wled_rgbw_light_playlist-Playlist 2-playlist-called_with2].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'options': list([
'Playlist 1',
'Playlist 2',
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'select',
'entity_category': None,
'entity_id': 'select.wled_rgbw_light_playlist',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': 'mdi:play-speed',
'original_name': 'Playlist',
'platform': 'wled',
'supported_features': 0,
'translation_key': None,
'unique_id': 'aabbccddee11_playlist',
'unit_of_measurement': None,
})
# ---
# name: test_color_palette_state[rgbw-select.wled_rgbw_light_playlist-Playlist 2-playlist-called_with2].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': 'http://127.0.0.1',
'connections': set({
tuple(
'mac',
'aa:bb:cc:dd:ee:11',
),
}),
'disabled_by': None,
'entry_type': None,
'hw_version': 'esp8266',
'id': <ANY>,
'identifiers': set({
tuple(
'wled',
'aabbccddee11',
),
}),
'is_new': False,
'manufacturer': 'WLED',
'model': 'DIY light',
'name': 'WLED RGBW Light',
'name_by_user': None,
'suggested_area': None,
'sw_version': '0.8.6b4',
'via_device_id': None,
})
# ---
# name: test_color_palette_state[rgbw-select.wled_rgbw_light_preset-Preset 2-preset-called_with3]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'WLED RGBW Light Preset',
'icon': 'mdi:playlist-play',
'options': list([
'Preset 1',
'Preset 2',
]),
}),
'context': <ANY>,
'entity_id': 'select.wled_rgbw_light_preset',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'Preset 1',
})
# ---
# name: test_color_palette_state[rgbw-select.wled_rgbw_light_preset-Preset 2-preset-called_with3].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'options': list([
'Preset 1',
'Preset 2',
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'select',
'entity_category': None,
'entity_id': 'select.wled_rgbw_light_preset',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': 'mdi:playlist-play',
'original_name': 'Preset',
'platform': 'wled',
'supported_features': 0,
'translation_key': None,
'unique_id': 'aabbccddee11_preset',
'unit_of_measurement': None,
})
# ---
# name: test_color_palette_state[rgbw-select.wled_rgbw_light_preset-Preset 2-preset-called_with3].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': 'http://127.0.0.1',
'connections': set({
tuple(
'mac',
'aa:bb:cc:dd:ee:11',
),
}),
'disabled_by': None,
'entry_type': None,
'hw_version': 'esp8266',
'id': <ANY>,
'identifiers': set({
tuple(
'wled',
'aabbccddee11',
),
}),
'is_new': False,
'manufacturer': 'WLED',
'model': 'DIY light',
'name': 'WLED RGBW Light',
'name_by_user': None,
'suggested_area': None,
'sw_version': '0.8.6b4',
'via_device_id': None,
})
# ---

View File

@ -3,25 +3,20 @@ import json
from unittest.mock import MagicMock
import pytest
from syrupy.assertion import SnapshotAssertion
from wled import Device as WLEDDevice, WLEDConnectionError, WLEDError
from homeassistant.components.select import (
ATTR_OPTION,
ATTR_OPTIONS,
DOMAIN as SELECT_DOMAIN,
)
from homeassistant.components.select import ATTR_OPTION, DOMAIN as SELECT_DOMAIN
from homeassistant.components.wled.const import SCAN_INTERVAL
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_ICON,
SERVICE_SELECT_OPTION,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
EntityCategory,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers import device_registry as dr, entity_registry as er
import homeassistant.util.dt as dt_util
from tests.common import async_fire_time_changed, load_fixture
@ -29,95 +24,102 @@ from tests.common import async_fire_time_changed, load_fixture
pytestmark = pytest.mark.usefixtures("init_integration")
@pytest.mark.parametrize(
("device_fixture", "entity_id", "option", "method", "called_with"),
[
(
"rgb",
"select.wled_rgb_light_segment_1_color_palette",
"Icefire",
"segment",
{"segment_id": 1, "palette": "Icefire"},
),
(
"rgb",
"select.wled_rgb_light_live_override",
"2",
"live",
{"live": 2},
),
(
"rgbw",
"select.wled_rgbw_light_playlist",
"Playlist 2",
"playlist",
{"playlist": "Playlist 2"},
),
(
"rgbw",
"select.wled_rgbw_light_preset",
"Preset 2",
"preset",
{"preset": "Preset 2"},
),
],
)
async def test_color_palette_state(
hass: HomeAssistant, entity_registry: er.EntityRegistry
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
mock_wled: MagicMock,
entity_id: str,
option: str,
method: str,
called_with: dict[str, int | str],
) -> None:
"""Test the creation and values of the WLED selects."""
# First segment of the strip
assert (state := hass.states.get("select.wled_rgb_light_segment_1_color_palette"))
assert state.attributes.get(ATTR_ICON) == "mdi:palette-outline"
assert state.attributes.get(ATTR_OPTIONS) == [
"Analogous",
"April Night",
"Autumn",
"Based on Primary",
"Based on Set",
"Beach",
"Beech",
"Breeze",
"C9",
"Cloud",
"Cyane",
"Default",
"Departure",
"Drywet",
"Fire",
"Forest",
"Grintage",
"Hult",
"Hult 64",
"Icefire",
"Jul",
"Landscape",
"Lava",
"Light Pink",
"Magenta",
"Magred",
"Ocean",
"Orange & Teal",
"Orangery",
"Party",
"Pastel",
"Primary Color",
"Rainbow",
"Rainbow Bands",
"Random Cycle",
"Red & Blue",
"Rewhi",
"Rivendell",
"Sakura",
"Set Colors",
"Sherbet",
"Splash",
"Sunset",
"Sunset 2",
"Tertiary",
"Tiamat",
"Vintage",
"Yelblu",
"Yellowout",
"Yelmag",
]
assert state.state == "Random Cycle"
assert (state := hass.states.get(entity_id))
assert state == snapshot
assert (
entry := entity_registry.async_get(
"select.wled_rgb_light_segment_1_color_palette"
)
)
assert entry.unique_id == "aabbccddeeff_palette_1"
assert entry.entity_category is EntityCategory.CONFIG
assert (entity_entry := entity_registry.async_get(state.entity_id))
assert entity_entry == snapshot
assert entity_entry.device_id
assert (device_entry := device_registry.async_get(entity_entry.device_id))
assert device_entry == snapshot
method_mock = getattr(mock_wled, method)
async def test_color_palette_segment_change_state(
hass: HomeAssistant,
mock_wled: MagicMock,
) -> None:
"""Test the option change of state of the WLED segments."""
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgb_light_segment_1_color_palette",
ATTR_OPTION: "Icefire",
},
{ATTR_ENTITY_ID: state.entity_id, ATTR_OPTION: option},
blocking=True,
)
assert mock_wled.segment.call_count == 1
mock_wled.segment.assert_called_with(
segment_id=1,
palette="Icefire",
)
assert method_mock.call_count == 1
method_mock.assert_called_with(**called_with)
# Test invalid response, not becoming unavailable
method_mock.side_effect = WLEDError
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: state.entity_id, ATTR_OPTION: option},
blocking=True,
)
assert (state := hass.states.get(state.entity_id))
assert state.state != STATE_UNAVAILABLE
assert method_mock.call_count == 2
method_mock.assert_called_with(**called_with)
# Test connection error, leading to becoming unavailable
method_mock.side_effect = WLEDConnectionError
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: state.entity_id, ATTR_OPTION: option},
blocking=True,
)
assert (state := hass.states.get(state.entity_id))
assert state.state == STATE_UNAVAILABLE
assert method_mock.call_count == 3
method_mock.assert_called_with(**called_with)
@pytest.mark.parametrize("device_fixture", ["rgb_single_segment"])
@ -158,86 +160,16 @@ async def test_color_palette_dynamically_handle_segments(
assert segment1.state == STATE_UNAVAILABLE
async def test_color_palette_select_error(
hass: HomeAssistant,
mock_wled: MagicMock,
) -> None:
"""Test error handling of the WLED selects."""
mock_wled.segment.side_effect = WLEDError
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgb_light_segment_1_color_palette",
ATTR_OPTION: "Icefire",
},
blocking=True,
)
assert (state := hass.states.get("select.wled_rgb_light_segment_1_color_palette"))
assert state.state == "Random Cycle"
assert mock_wled.segment.call_count == 1
mock_wled.segment.assert_called_with(segment_id=1, palette="Icefire")
async def test_color_palette_select_connection_error(
hass: HomeAssistant,
mock_wled: MagicMock,
) -> None:
"""Test error handling of the WLED selects."""
mock_wled.segment.side_effect = WLEDConnectionError
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgb_light_segment_1_color_palette",
ATTR_OPTION: "Icefire",
},
blocking=True,
)
assert (state := hass.states.get("select.wled_rgb_light_segment_1_color_palette"))
assert state.state == STATE_UNAVAILABLE
assert mock_wled.segment.call_count == 1
mock_wled.segment.assert_called_with(segment_id=1, palette="Icefire")
async def test_preset_unavailable_without_presets(hass: HomeAssistant) -> None:
"""Test WLED preset entity is unavailable when presets are not available."""
assert (state := hass.states.get("select.wled_rgb_light_preset"))
assert state.state == STATE_UNAVAILABLE
@pytest.mark.parametrize("device_fixture", ["rgbw"])
async def test_preset_state(
hass: HomeAssistant,
mock_wled: MagicMock,
entity_registry: er.EntityRegistry,
) -> None:
"""Test the creation and values of the WLED selects."""
assert (state := hass.states.get("select.wled_rgbw_light_preset"))
assert state.attributes.get(ATTR_ICON) == "mdi:playlist-play"
assert state.attributes.get(ATTR_OPTIONS) == ["Preset 1", "Preset 2"]
assert state.state == "Preset 1"
assert (entry := entity_registry.async_get("select.wled_rgbw_light_preset"))
assert entry.unique_id == "aabbccddee11_preset"
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgbw_light_preset",
ATTR_OPTION: "Preset 2",
},
blocking=True,
)
assert mock_wled.preset.call_count == 1
mock_wled.preset.assert_called_with(preset="Preset 2")
async def test_playlist_unavailable_without_playlists(hass: HomeAssistant) -> None:
"""Test WLED playlist entity is unavailable when playlists are not available."""
assert (state := hass.states.get("select.wled_rgb_light_playlist"))
assert state.state == STATE_UNAVAILABLE
@pytest.mark.parametrize("device_fixture", ["rgbw"])
@ -256,92 +188,6 @@ async def test_old_style_preset_active(
assert state.state == STATE_UNKNOWN
@pytest.mark.parametrize("device_fixture", ["rgbw"])
async def test_preset_select_error(
hass: HomeAssistant,
mock_wled: MagicMock,
) -> None:
"""Test error handling of the WLED selects."""
mock_wled.preset.side_effect = WLEDError
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgbw_light_preset",
ATTR_OPTION: "Preset 2",
},
blocking=True,
)
await hass.async_block_till_done()
assert (state := hass.states.get("select.wled_rgbw_light_preset"))
assert state.state == "Preset 1"
assert mock_wled.preset.call_count == 1
mock_wled.preset.assert_called_with(preset="Preset 2")
@pytest.mark.parametrize("device_fixture", ["rgbw"])
async def test_preset_select_connection_error(
hass: HomeAssistant,
mock_wled: MagicMock,
) -> None:
"""Test error handling of the WLED selects."""
mock_wled.preset.side_effect = WLEDConnectionError
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgbw_light_preset",
ATTR_OPTION: "Preset 2",
},
blocking=True,
)
assert (state := hass.states.get("select.wled_rgbw_light_preset"))
assert state.state == STATE_UNAVAILABLE
assert mock_wled.preset.call_count == 1
mock_wled.preset.assert_called_with(preset="Preset 2")
async def test_playlist_unavailable_without_playlists(hass: HomeAssistant) -> None:
"""Test WLED playlist entity is unavailable when playlists are not available."""
assert (state := hass.states.get("select.wled_rgb_light_playlist"))
assert state.state == STATE_UNAVAILABLE
@pytest.mark.parametrize("device_fixture", ["rgbw"])
async def test_playlist_state(
hass: HomeAssistant,
mock_wled: MagicMock,
entity_registry: er.EntityRegistry,
) -> None:
"""Test the creation and values of the WLED selects."""
assert (state := hass.states.get("select.wled_rgbw_light_playlist"))
assert state.attributes.get(ATTR_ICON) == "mdi:play-speed"
assert state.attributes.get(ATTR_OPTIONS) == ["Playlist 1", "Playlist 2"]
assert state.state == "Playlist 1"
assert (entry := entity_registry.async_get("select.wled_rgbw_light_playlist"))
assert entry.unique_id == "aabbccddee11_playlist"
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgbw_light_playlist",
ATTR_OPTION: "Playlist 2",
},
blocking=True,
)
assert mock_wled.playlist.call_count == 1
mock_wled.playlist.assert_called_with(playlist="Playlist 2")
@pytest.mark.parametrize("device_fixture", ["rgbw"])
async def test_old_style_playlist_active(
hass: HomeAssistant,
@ -356,128 +202,3 @@ async def test_old_style_playlist_active(
assert (state := hass.states.get("select.wled_rgbw_light_playlist"))
assert state.state == STATE_UNKNOWN
@pytest.mark.parametrize("device_fixture", ["rgbw"])
async def test_playlist_select_error(
hass: HomeAssistant,
mock_wled: MagicMock,
) -> None:
"""Test error handling of the WLED selects."""
mock_wled.playlist.side_effect = WLEDError
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgbw_light_playlist",
ATTR_OPTION: "Playlist 2",
},
blocking=True,
)
assert (state := hass.states.get("select.wled_rgbw_light_playlist"))
assert state.state == "Playlist 1"
assert mock_wled.playlist.call_count == 1
mock_wled.playlist.assert_called_with(playlist="Playlist 2")
@pytest.mark.parametrize("device_fixture", ["rgbw"])
async def test_playlist_select_connection_error(
hass: HomeAssistant,
mock_wled: MagicMock,
) -> None:
"""Test error handling of the WLED selects."""
mock_wled.playlist.side_effect = WLEDConnectionError
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgbw_light_playlist",
ATTR_OPTION: "Playlist 2",
},
blocking=True,
)
assert (state := hass.states.get("select.wled_rgbw_light_playlist"))
assert state.state == STATE_UNAVAILABLE
assert mock_wled.playlist.call_count == 1
mock_wled.playlist.assert_called_with(playlist="Playlist 2")
async def test_live_override(
hass: HomeAssistant,
mock_wled: MagicMock,
entity_registry: er.EntityRegistry,
) -> None:
"""Test the creation and values of the WLED selects."""
assert (state := hass.states.get("select.wled_rgb_light_live_override"))
assert state.attributes.get(ATTR_ICON) == "mdi:theater"
assert state.attributes.get(ATTR_OPTIONS) == ["0", "1", "2"]
assert state.state == "0"
assert (entry := entity_registry.async_get("select.wled_rgb_light_live_override"))
assert entry.unique_id == "aabbccddeeff_live_override"
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgb_light_live_override",
ATTR_OPTION: "2",
},
blocking=True,
)
assert mock_wled.live.call_count == 1
mock_wled.live.assert_called_with(live=2)
async def test_live_select_error(
hass: HomeAssistant,
mock_wled: MagicMock,
) -> None:
"""Test error handling of the WLED selects."""
mock_wled.live.side_effect = WLEDError
with pytest.raises(HomeAssistantError, match="Invalid response from WLED API"):
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgb_light_live_override",
ATTR_OPTION: "1",
},
blocking=True,
)
assert (state := hass.states.get("select.wled_rgb_light_live_override"))
assert state.state == "0"
assert mock_wled.live.call_count == 1
mock_wled.live.assert_called_with(live=1)
async def test_live_select_connection_error(
hass: HomeAssistant,
mock_wled: MagicMock,
) -> None:
"""Test error handling of the WLED selects."""
mock_wled.live.side_effect = WLEDConnectionError
with pytest.raises(HomeAssistantError, match="Error communicating with WLED API"):
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{
ATTR_ENTITY_ID: "select.wled_rgb_light_live_override",
ATTR_OPTION: "2",
},
blocking=True,
)
assert (state := hass.states.get("select.wled_rgb_light_live_override"))
assert state.state == STATE_UNAVAILABLE
assert mock_wled.live.call_count == 1
mock_wled.live.assert_called_with(live=2)