Auto select first active wake word (#152562)
parent
ff47839c61
commit
a0be737925
|
@ -194,6 +194,21 @@ class EsphomeAssistSatelliteWakeWordSelect(
|
|||
self._attr_options = [NO_WAKE_WORD, *sorted(self._wake_words)]
|
||||
|
||||
option = self._attr_current_option
|
||||
|
||||
if (
|
||||
(self._wake_word_index == 0)
|
||||
and (len(config.active_wake_words) == 1)
|
||||
and (option in (None, NO_WAKE_WORD))
|
||||
):
|
||||
option = next(
|
||||
(
|
||||
wake_word
|
||||
for wake_word, wake_word_id in self._wake_words.items()
|
||||
if wake_word_id == config.active_wake_words[0]
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
if (
|
||||
(option is None)
|
||||
or ((wake_word_id := self._wake_words.get(option)) is None)
|
||||
|
|
|
@ -1887,10 +1887,10 @@ async def test_wake_word_select(
|
|||
assert satellite is not None
|
||||
assert satellite.async_get_configuration().active_wake_words == ["hey_jarvis"]
|
||||
|
||||
# No wake word should be selected by default
|
||||
# First wake word should be selected by default
|
||||
state = hass.states.get("select.test_wake_word")
|
||||
assert state is not None
|
||||
assert state.state == NO_WAKE_WORD
|
||||
assert state.state == "Hey Jarvis"
|
||||
|
||||
# Changing the select should set the active wake word
|
||||
await hass.services.async_call(
|
||||
|
@ -1955,6 +1955,21 @@ async def test_wake_word_select(
|
|||
# Only primary wake word remains
|
||||
assert satellite.async_get_configuration().active_wake_words == ["okay_nabu"]
|
||||
|
||||
# Remove the primary wake word
|
||||
await hass.services.async_call(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
{ATTR_ENTITY_ID: "select.test_wake_word", "option": NO_WAKE_WORD},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
async with asyncio.timeout(1):
|
||||
await configuration_set.wait()
|
||||
|
||||
# No active wake word remain
|
||||
assert not satellite.async_get_configuration().active_wake_words
|
||||
|
||||
|
||||
async def test_secondary_pipeline(
|
||||
hass: HomeAssistant,
|
||||
|
|
|
@ -186,7 +186,7 @@ async def test_wake_word_select_no_active_wake_words(
|
|||
mock_client: APIClient,
|
||||
mock_esphome_device: MockESPHomeDeviceType,
|
||||
) -> None:
|
||||
"""Test wake word select uses first available wake word if none are active."""
|
||||
"""Test wake word select has no wake word selected if none are active."""
|
||||
device_config = AssistSatelliteConfiguration(
|
||||
available_wake_words=[
|
||||
AssistSatelliteWakeWord("okay_nabu", "Okay Nabu", ["en"]),
|
||||
|
@ -215,3 +215,42 @@ async def test_wake_word_select_no_active_wake_words(
|
|||
state = hass.states.get(entity_id)
|
||||
assert state is not None
|
||||
assert state.state == NO_WAKE_WORD
|
||||
|
||||
|
||||
async def test_wake_word_select_first_active_wake_word(
|
||||
hass: HomeAssistant,
|
||||
mock_client: APIClient,
|
||||
mock_esphome_device: MockESPHomeDeviceType,
|
||||
) -> None:
|
||||
"""Test wake word select uses first available wake word if one is active."""
|
||||
device_config = AssistSatelliteConfiguration(
|
||||
available_wake_words=[
|
||||
AssistSatelliteWakeWord("okay_nabu", "Okay Nabu", ["en"]),
|
||||
AssistSatelliteWakeWord("hey_jarvis", "Hey Jarvis", ["en"]),
|
||||
],
|
||||
active_wake_words=["okay_nabu"],
|
||||
max_active_wake_words=1,
|
||||
)
|
||||
mock_client.get_voice_assistant_configuration.return_value = device_config
|
||||
|
||||
mock_device = await mock_esphome_device(
|
||||
mock_client=mock_client,
|
||||
device_info={
|
||||
"voice_assistant_feature_flags": VoiceAssistantFeature.VOICE_ASSISTANT
|
||||
| VoiceAssistantFeature.ANNOUNCE
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
satellite = get_satellite_entity(hass, mock_device.device_info.mac_address)
|
||||
assert satellite is not None
|
||||
|
||||
# First wake word should be selected
|
||||
state = hass.states.get("select.test_wake_word")
|
||||
assert state is not None
|
||||
assert state.state == "Okay Nabu"
|
||||
|
||||
# Second wake word should not be selected
|
||||
state_2 = hass.states.get("select.test_wake_word_2")
|
||||
assert state_2 is not None
|
||||
assert state_2.state == NO_WAKE_WORD
|
||||
|
|
Loading…
Reference in New Issue