Add various assertions to Bang & Olufsen testing (#125429)

Add various assertions
This commit is contained in:
Markus Jacobsen 2024-09-08 12:22:21 +02:00 committed by GitHub
parent 943b96e7a1
commit 31aef86c0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 22 deletions

View File

@ -104,7 +104,7 @@ async def test_initialization(
# Check state (The initial state in this test does not contain all that much.
# States are tested using simulated WebSocket events.)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert states.attributes[ATTR_INPUT_SOURCE_LIST] == TEST_SOURCES
assert states.attributes[ATTR_MEDIA_POSITION_UPDATED_AT]
@ -126,7 +126,7 @@ async def test_async_update_sources_audio_only(
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert states.attributes[ATTR_INPUT_SOURCE_LIST] == TEST_AUDIO_SOURCES
@ -141,7 +141,7 @@ async def test_async_update_sources_outdated_api(
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert (
states.attributes[ATTR_INPUT_SOURCE_LIST]
== TEST_FALLBACK_SOURCES + TEST_VIDEO_SOURCES
@ -187,7 +187,7 @@ async def test_async_update_playback_metadata(
mock_mozart_client.get_playback_metadata_notifications.call_args[0][0]
)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert ATTR_MEDIA_DURATION not in states.attributes
assert ATTR_MEDIA_TITLE not in states.attributes
assert ATTR_MEDIA_ALBUM_NAME not in states.attributes
@ -198,7 +198,7 @@ async def test_async_update_playback_metadata(
# Send the WebSocket event dispatch
playback_metadata_callback(TEST_PLAYBACK_METADATA)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert (
states.attributes[ATTR_MEDIA_DURATION]
== TEST_PLAYBACK_METADATA.total_duration_seconds
@ -250,14 +250,14 @@ async def test_async_update_playback_progress(
mock_mozart_client.get_playback_progress_notifications.call_args[0][0]
)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert ATTR_MEDIA_POSITION not in states.attributes
old_updated_at = states.attributes[ATTR_MEDIA_POSITION_UPDATED_AT]
assert old_updated_at
playback_progress_callback(TEST_PLAYBACK_PROGRESS)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert states.attributes[ATTR_MEDIA_POSITION] == TEST_PLAYBACK_PROGRESS.progress
new_updated_at = states.attributes[ATTR_MEDIA_POSITION_UPDATED_AT]
assert new_updated_at
@ -278,12 +278,12 @@ async def test_async_update_playback_state(
mock_mozart_client.get_playback_state_notifications.call_args[0][0]
)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert states.state == MediaPlayerState.PLAYING
playback_state_callback(TEST_PLAYBACK_STATE_PAUSED)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert states.state == TEST_PLAYBACK_STATE_PAUSED.value
@ -366,7 +366,7 @@ async def test_async_update_source_change(
mock_mozart_client.get_source_change_notifications.call_args[0][0]
)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert ATTR_INPUT_SOURCE not in states.attributes
assert states.attributes[ATTR_MEDIA_CONTENT_TYPE] == MediaType.MUSIC
@ -377,7 +377,7 @@ async def test_async_update_source_change(
playback_metadata_callback(metadata)
source_change_callback(reported_source)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert states.attributes[ATTR_INPUT_SOURCE] == real_source.name
assert states.attributes[ATTR_MEDIA_CONTENT_TYPE] == content_type
assert states.attributes[ATTR_MEDIA_POSITION] == progress
@ -406,7 +406,8 @@ async def test_async_turn_off(
playback_state_callback(TEST_PLAYBACK_STATE_TURN_OFF)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert TEST_PLAYBACK_STATE_TURN_OFF.value
assert states.state == BANG_OLUFSEN_STATES[TEST_PLAYBACK_STATE_TURN_OFF.value]
# Check API call
@ -425,7 +426,7 @@ async def test_async_set_volume_level(
volume_callback = mock_mozart_client.get_volume_notifications.call_args[0][0]
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert ATTR_MEDIA_VOLUME_LEVEL not in states.attributes
await hass.services.async_call(
@ -441,7 +442,7 @@ async def test_async_set_volume_level(
# The service call will trigger a WebSocket notification
volume_callback(TEST_VOLUME)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert (
states.attributes[ATTR_MEDIA_VOLUME_LEVEL] == TEST_VOLUME_HOME_ASSISTANT_FORMAT
)
@ -463,7 +464,7 @@ async def test_async_mute_volume(
volume_callback = mock_mozart_client.get_volume_notifications.call_args[0][0]
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert ATTR_MEDIA_VOLUME_MUTED not in states.attributes
await hass.services.async_call(
@ -479,7 +480,7 @@ async def test_async_mute_volume(
# The service call will trigger a WebSocket notification
volume_callback(TEST_VOLUME_MUTED)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert (
states.attributes[ATTR_MEDIA_VOLUME_MUTED]
== TEST_VOLUME_MUTED_HOME_ASSISTANT_FORMAT
@ -518,7 +519,8 @@ async def test_async_media_play_pause(
# Set the initial state
playback_state_callback(initial_state)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert initial_state.value
assert states.state == BANG_OLUFSEN_STATES[initial_state.value]
await hass.services.async_call(
@ -548,7 +550,8 @@ async def test_async_media_stop(
# Set the state to playing
playback_state_callback(TEST_PLAYBACK_STATE_PLAYING)
states = hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID)
assert (states := hass.states.get(TEST_MEDIA_PLAYER_ENTITY_ID))
assert TEST_PLAYBACK_STATE_PLAYING.value
assert states.state == BANG_OLUFSEN_STATES[TEST_PLAYBACK_STATE_PLAYING.value]
await hass.services.async_call(

View File

@ -101,8 +101,11 @@ async def test_on_software_update_state(
await hass.async_block_till_done()
device = device_registry.async_get_device(
identifiers={(DOMAIN, mock_config_entry.unique_id)}
assert mock_config_entry.unique_id
assert (
device := device_registry.async_get_device(
identifiers={(DOMAIN, mock_config_entry.unique_id)}
)
)
assert device.sw_version == "1.0.0"
@ -135,8 +138,11 @@ async def test_on_all_notifications_raw(
raw_notification_full = raw_notification
# Get device ID for the modified notification that is sent as an event and in the log
device = device_registry.async_get_device(
identifiers={(DOMAIN, mock_config_entry.unique_id)}
assert mock_config_entry.unique_id
assert (
device := device_registry.async_get_device(
identifiers={(DOMAIN, mock_config_entry.unique_id)}
)
)
raw_notification_full.update(
{