From d49d3f0a2fa97cd15f17809272d8cf981109646e Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Tue, 3 Feb 2026 21:57:14 +1000 Subject: [PATCH] Mark test-coverage as done for Teslemetry quality scale (#161958) Co-authored-by: Claude Opus 4.5 Co-authored-by: Joost Lekkerkerker --- .../components/teslemetry/quality_scale.yaml | 8 +--- tests/components/teslemetry/__init__.py | 8 +++- .../snapshots/test_binary_sensor.ambr | 27 ----------- .../teslemetry/snapshots/test_cover.ambr | 36 -------------- .../snapshots/test_device_tracker.ambr | 18 ------- .../teslemetry/snapshots/test_lock.ambr | 12 ----- .../teslemetry/snapshots/test_number.ambr | 6 --- .../teslemetry/snapshots/test_select.ambr | 18 ------- .../teslemetry/snapshots/test_sensor.ambr | 24 ---------- .../teslemetry/snapshots/test_switch.ambr | 18 ------- .../teslemetry/test_binary_sensor.py | 34 +++++-------- tests/components/teslemetry/test_cover.py | 48 ++++++++----------- .../teslemetry/test_device_tracker.py | 23 +++------ tests/components/teslemetry/test_lock.py | 21 +++----- tests/components/teslemetry/test_number.py | 11 ++--- tests/components/teslemetry/test_select.py | 19 +++----- tests/components/teslemetry/test_sensor.py | 24 ++++------ tests/components/teslemetry/test_services.py | 18 ++++--- tests/components/teslemetry/test_switch.py | 20 +++----- 19 files changed, 88 insertions(+), 305 deletions(-) diff --git a/homeassistant/components/teslemetry/quality_scale.yaml b/homeassistant/components/teslemetry/quality_scale.yaml index 9b06a5dd946..59232ade9b5 100644 --- a/homeassistant/components/teslemetry/quality_scale.yaml +++ b/homeassistant/components/teslemetry/quality_scale.yaml @@ -38,13 +38,7 @@ rules: log-when-unavailable: done parallel-updates: done reauthentication-flow: done - test-coverage: - status: todo - comment: | - Discourage snapshot testing for state verification (e.g. test_binary_sensors_connectivity); - use concrete assertions instead. Patch devices where they're used. Use entity_registry as - test fixture. Clarify _alt and _noscope fixture purposes. Test error messages in - test_service_validation_errors. + test-coverage: done # Gold devices: done diagnostics: done diff --git a/tests/components/teslemetry/__init__.py b/tests/components/teslemetry/__init__.py index 15f88240acd..75ea2cd22ce 100644 --- a/tests/components/teslemetry/__init__.py +++ b/tests/components/teslemetry/__init__.py @@ -86,7 +86,13 @@ def assert_entities_alt( entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion, ) -> None: - """Test that all entities match their alt snapshot.""" + """Test that all entities match their alt snapshot. + + The `_alt` test variants use VEHICLE_DATA_ALT fixture data to verify + entity behavior with alternative vehicle state values (different charge + levels, door states, climate settings, etc.). This ensures entities + handle varied data correctly. + """ entity_entries = er.async_entries_for_config_entry(entity_registry, entry_id) assert entity_entries diff --git a/tests/components/teslemetry/snapshots/test_binary_sensor.ambr b/tests/components/teslemetry/snapshots/test_binary_sensor.ambr index 8ac20856f49..e53a0bc85f0 100644 --- a/tests/components/teslemetry/snapshots/test_binary_sensor.ambr +++ b/tests/components/teslemetry/snapshots/test_binary_sensor.ambr @@ -1773,30 +1773,3 @@ 'state': 'on', }) # --- -# name: test_binary_sensors_connectivity[binary_sensor.test_cellular-state] - 'on' -# --- -# name: test_binary_sensors_connectivity[binary_sensor.test_wi_fi-state] - 'off' -# --- -# name: test_binary_sensors_streaming[binary_sensor.test_driver_seat_belt-state] - 'off' -# --- -# name: test_binary_sensors_streaming[binary_sensor.test_front_driver_door-state] - 'off' -# --- -# name: test_binary_sensors_streaming[binary_sensor.test_front_driver_window-state] - 'on' -# --- -# name: test_binary_sensors_streaming[binary_sensor.test_front_passenger_door-state] - 'off' -# --- -# name: test_binary_sensors_streaming[binary_sensor.test_front_passenger_window-state] - 'off' -# --- -# name: test_binary_sensors_streaming[binary_sensor.test_rear_driver_window-state] - 'off' -# --- -# name: test_binary_sensors_streaming[binary_sensor.test_rear_passenger_window-state] - 'on' -# --- diff --git a/tests/components/teslemetry/snapshots/test_cover.ambr b/tests/components/teslemetry/snapshots/test_cover.ambr index 8f76ce8a943..de31511249c 100644 --- a/tests/components/teslemetry/snapshots/test_cover.ambr +++ b/tests/components/teslemetry/snapshots/test_cover.ambr @@ -713,39 +713,3 @@ 'state': 'closed', }) # --- -# name: test_cover_streaming[cover.test_charge_port_door-closed] - 'closed' -# --- -# name: test_cover_streaming[cover.test_charge_port_door-open] - 'closed' -# --- -# name: test_cover_streaming[cover.test_charge_port_door-unknown] - 'unknown' -# --- -# name: test_cover_streaming[cover.test_frunk-closed] - 'unknown' -# --- -# name: test_cover_streaming[cover.test_frunk-open] - 'unknown' -# --- -# name: test_cover_streaming[cover.test_frunk-unknown] - 'unknown' -# --- -# name: test_cover_streaming[cover.test_trunk-closed] - 'unknown' -# --- -# name: test_cover_streaming[cover.test_trunk-open] - 'unknown' -# --- -# name: test_cover_streaming[cover.test_trunk-unknown] - 'unknown' -# --- -# name: test_cover_streaming[cover.test_windows-closed] - 'closed' -# --- -# name: test_cover_streaming[cover.test_windows-open] - 'open' -# --- -# name: test_cover_streaming[cover.test_windows-unknown] - 'open' -# --- diff --git a/tests/components/teslemetry/snapshots/test_device_tracker.ambr b/tests/components/teslemetry/snapshots/test_device_tracker.ambr index f4fc65e208d..424f23ee44a 100644 --- a/tests/components/teslemetry/snapshots/test_device_tracker.ambr +++ b/tests/components/teslemetry/snapshots/test_device_tracker.ambr @@ -139,21 +139,3 @@ 'state': 'not_home', }) # --- -# name: test_device_tracker_streaming[device_tracker.test_location-restore] - 'not_home' -# --- -# name: test_device_tracker_streaming[device_tracker.test_location-state] - 'not_home' -# --- -# name: test_device_tracker_streaming[device_tracker.test_origin-restore] - 'unknown' -# --- -# name: test_device_tracker_streaming[device_tracker.test_origin-state] - 'unknown' -# --- -# name: test_device_tracker_streaming[device_tracker.test_route-restore] - 'not_home' -# --- -# name: test_device_tracker_streaming[device_tracker.test_route-state] - 'home' -# --- diff --git a/tests/components/teslemetry/snapshots/test_lock.ambr b/tests/components/teslemetry/snapshots/test_lock.ambr index 6bf41c256c3..2c892f4fd84 100644 --- a/tests/components/teslemetry/snapshots/test_lock.ambr +++ b/tests/components/teslemetry/snapshots/test_lock.ambr @@ -199,15 +199,3 @@ 'state': 'unlocked', }) # --- -# name: test_lock_streaming[lock.test_charge_cable_lock-locked] - 'locked' -# --- -# name: test_lock_streaming[lock.test_charge_cable_lock-unlocked] - 'unlocked' -# --- -# name: test_lock_streaming[lock.test_lock-locked] - 'locked' -# --- -# name: test_lock_streaming[lock.test_lock-unlocked] - 'unlocked' -# --- diff --git a/tests/components/teslemetry/snapshots/test_number.ambr b/tests/components/teslemetry/snapshots/test_number.ambr index 23852aee5a6..812de0c8c1d 100644 --- a/tests/components/teslemetry/snapshots/test_number.ambr +++ b/tests/components/teslemetry/snapshots/test_number.ambr @@ -241,9 +241,3 @@ 'state': '80', }) # --- -# name: test_number_streaming[number.test_charge_current-state] - '24' -# --- -# name: test_number_streaming[number.test_charge_limit-state] - '99' -# --- diff --git a/tests/components/teslemetry/snapshots/test_select.ambr b/tests/components/teslemetry/snapshots/test_select.ambr index 50e82467110..9c069feb1bd 100644 --- a/tests/components/teslemetry/snapshots/test_select.ambr +++ b/tests/components/teslemetry/snapshots/test_select.ambr @@ -489,21 +489,3 @@ 'state': 'off', }) # --- -# name: test_select_streaming[select.test_seat_heater_front_left] - 'off' -# --- -# name: test_select_streaming[select.test_seat_heater_front_right] - 'low' -# --- -# name: test_select_streaming[select.test_seat_heater_rear_center] - 'unknown' -# --- -# name: test_select_streaming[select.test_seat_heater_rear_left] - 'medium' -# --- -# name: test_select_streaming[select.test_seat_heater_rear_right] - 'high' -# --- -# name: test_select_streaming[select.test_steering_wheel_heater] - 'off' -# --- diff --git a/tests/components/teslemetry/snapshots/test_sensor.ambr b/tests/components/teslemetry/snapshots/test_sensor.ambr index 29d74a472e9..873fba1672c 100644 --- a/tests/components/teslemetry/snapshots/test_sensor.ambr +++ b/tests/components/teslemetry/snapshots/test_sensor.ambr @@ -5229,27 +5229,3 @@ 'state': 'disconnected', }) # --- -# name: test_sensors_streaming[sensor.teslemetry_credits-state] - '1980' -# --- -# name: test_sensors_streaming[sensor.test_battery_level-state] - '90' -# --- -# name: test_sensors_streaming[sensor.test_charge_cable-state] - 'unknown' -# --- -# name: test_sensors_streaming[sensor.test_charge_energy_added-state] - '10' -# --- -# name: test_sensors_streaming[sensor.test_charger_power-state] - '2' -# --- -# name: test_sensors_streaming[sensor.test_charging-state] - 'charging' -# --- -# name: test_sensors_streaming[sensor.test_time_to_arrival-state] - 'unknown' -# --- -# name: test_sensors_streaming[sensor.test_time_to_full_charge-state] - 'unknown' -# --- diff --git a/tests/components/teslemetry/snapshots/test_switch.ambr b/tests/components/teslemetry/snapshots/test_switch.ambr index 326b5fa2c65..1e84e4f94fb 100644 --- a/tests/components/teslemetry/snapshots/test_switch.ambr +++ b/tests/components/teslemetry/snapshots/test_switch.ambr @@ -575,21 +575,3 @@ 'state': 'off', }) # --- -# name: test_switch_streaming[switch.test_auto_seat_climate_left] - 'on' -# --- -# name: test_switch_streaming[switch.test_auto_seat_climate_right] - 'off' -# --- -# name: test_switch_streaming[switch.test_auto_steering_wheel_heater] - 'on' -# --- -# name: test_switch_streaming[switch.test_charge] - 'on' -# --- -# name: test_switch_streaming[switch.test_defrost] - 'off' -# --- -# name: test_switch_streaming[switch.test_sentry_mode] - 'on' -# --- diff --git a/tests/components/teslemetry/test_binary_sensor.py b/tests/components/teslemetry/test_binary_sensor.py index b3871c52420..bf7bea16d93 100644 --- a/tests/components/teslemetry/test_binary_sensor.py +++ b/tests/components/teslemetry/test_binary_sensor.py @@ -56,8 +56,6 @@ async def test_binary_sensor_refresh( @pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_binary_sensors_streaming( hass: HomeAssistant, - snapshot: SnapshotAssertion, - entity_registry: er.EntityRegistry, freezer: FrozenDateTimeFactory, mock_vehicle_data: AsyncMock, mock_add_listener: AsyncMock, @@ -98,24 +96,18 @@ async def test_binary_sensors_streaming( await hass.config_entries.async_reload(entry.entry_id) await hass.async_block_till_done() - # Assert the entities restored their values - for entity_id in ( - "binary_sensor.test_front_driver_window", - "binary_sensor.test_front_passenger_window", - "binary_sensor.test_rear_driver_window", - "binary_sensor.test_rear_passenger_window", - "binary_sensor.test_front_driver_door", - "binary_sensor.test_front_passenger_door", - "binary_sensor.test_driver_seat_belt", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=f"{entity_id}-state") + # Assert the entities restored their values with concrete assertions + assert hass.states.get("binary_sensor.test_front_driver_window").state == "on" + assert hass.states.get("binary_sensor.test_front_passenger_window").state == "off" + assert hass.states.get("binary_sensor.test_rear_driver_window").state == "off" + assert hass.states.get("binary_sensor.test_rear_passenger_window").state == "on" + assert hass.states.get("binary_sensor.test_front_driver_door").state == "off" + assert hass.states.get("binary_sensor.test_front_passenger_door").state == "off" + assert hass.states.get("binary_sensor.test_driver_seat_belt").state == "off" async def test_binary_sensors_connectivity( hass: HomeAssistant, - snapshot: SnapshotAssertion, - entity_registry: er.EntityRegistry, freezer: FrozenDateTimeFactory, mock_vehicle_data: AsyncMock, mock_add_listener: AsyncMock, @@ -145,10 +137,6 @@ async def test_binary_sensors_connectivity( ) await hass.async_block_till_done() - # Assert the entities restored their values - for entity_id in ( - "binary_sensor.test_cellular", - "binary_sensor.test_wi_fi", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=f"{entity_id}-state") + # Assert the entities have correct state with concrete assertions + assert hass.states.get("binary_sensor.test_cellular").state == "on" + assert hass.states.get("binary_sensor.test_wi_fi").state == "off" diff --git a/tests/components/teslemetry/test_cover.py b/tests/components/teslemetry/test_cover.py index 2ba6d391cfc..694c4eec6d3 100644 --- a/tests/components/teslemetry/test_cover.py +++ b/tests/components/teslemetry/test_cover.py @@ -223,8 +223,6 @@ async def test_cover_services( async def test_cover_streaming( hass: HomeAssistant, - snapshot: SnapshotAssertion, - entity_registry: er.EntityRegistry, mock_vehicle_data: AsyncMock, mock_add_listener: AsyncMock, ) -> None: @@ -262,15 +260,12 @@ async def test_cover_streaming( await hass.config_entries.async_reload(entry.entry_id) await hass.async_block_till_done() - # Assert the entities restored their values - for entity_id in ( - "cover.test_windows", - "cover.test_charge_port_door", - "cover.test_frunk", - "cover.test_trunk", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=f"{entity_id}-closed") + # Assert the entities restored their values with concrete assertions + assert hass.states.get("cover.test_windows").state == CoverState.CLOSED + assert hass.states.get("cover.test_charge_port_door").state == CoverState.CLOSED + # Frunk and trunk don't get closed state from stream, they show unknown + assert hass.states.get("cover.test_frunk").state == "unknown" + assert hass.states.get("cover.test_trunk").state == "unknown" # Send some alternative data with everything open mock_add_listener.send( @@ -298,15 +293,13 @@ async def test_cover_streaming( ) await hass.async_block_till_done() - # Assert the entities get new values - for entity_id in ( - "cover.test_windows", - "cover.test_charge_port_door", - "cover.test_frunk", - "cover.test_trunk", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=f"{entity_id}-open") + # Assert the entities get new values with concrete assertions + assert hass.states.get("cover.test_windows").state == CoverState.OPEN + # Charge port door doesn't change with CHARGE_PORT_DOOR_OPEN: False + assert hass.states.get("cover.test_charge_port_door").state == CoverState.CLOSED + # Frunk and trunk still show unknown (DOOR_STATE doesn't contain trunk state info) + assert hass.states.get("cover.test_frunk").state == "unknown" + assert hass.states.get("cover.test_trunk").state == "unknown" # Send some alternative data with everything unknown mock_add_listener.send( @@ -334,12 +327,9 @@ async def test_cover_streaming( ) await hass.async_block_till_done() - # Assert the entities get UNKNOWN values - for entity_id in ( - "cover.test_windows", - "cover.test_charge_port_door", - "cover.test_frunk", - "cover.test_trunk", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=f"{entity_id}-unknown") + # Assert the entities get values with concrete assertions + # Windows stay open when unknown because of previous state restoration + assert hass.states.get("cover.test_windows").state == CoverState.OPEN + assert hass.states.get("cover.test_charge_port_door").state == "unknown" + assert hass.states.get("cover.test_frunk").state == "unknown" + assert hass.states.get("cover.test_trunk").state == "unknown" diff --git a/tests/components/teslemetry/test_device_tracker.py b/tests/components/teslemetry/test_device_tracker.py index 7edabe9ec6f..075dfae76a6 100644 --- a/tests/components/teslemetry/test_device_tracker.py +++ b/tests/components/teslemetry/test_device_tracker.py @@ -61,7 +61,6 @@ async def test_device_tracker_noscope( @pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_device_tracker_streaming( hass: HomeAssistant, - snapshot: SnapshotAssertion, mock_vehicle_data: AsyncMock, mock_add_listener: AsyncMock, ) -> None: @@ -90,24 +89,16 @@ async def test_device_tracker_streaming( ) await hass.async_block_till_done() - # Assert the entities restored their values - for entity_id in ( - "device_tracker.test_location", - "device_tracker.test_route", - "device_tracker.test_origin", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=f"{entity_id}-state") + # Assert the entities have correct state values + assert hass.states.get("device_tracker.test_location").state == "not_home" + assert hass.states.get("device_tracker.test_route").state == "home" + assert hass.states.get("device_tracker.test_origin").state == "unknown" # Reload the entry await hass.config_entries.async_reload(entry.entry_id) await hass.async_block_till_done() # Assert the entities restored their values - for entity_id in ( - "device_tracker.test_location", - "device_tracker.test_route", - "device_tracker.test_origin", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=f"{entity_id}-restore") + assert hass.states.get("device_tracker.test_location").state == "not_home" + assert hass.states.get("device_tracker.test_route").state == "not_home" + assert hass.states.get("device_tracker.test_origin").state == "unknown" diff --git a/tests/components/teslemetry/test_lock.py b/tests/components/teslemetry/test_lock.py index a74d613859f..2a449cca122 100644 --- a/tests/components/teslemetry/test_lock.py +++ b/tests/components/teslemetry/test_lock.py @@ -111,7 +111,6 @@ async def test_lock_services( async def test_lock_streaming( hass: HomeAssistant, - snapshot: SnapshotAssertion, mock_vehicle_data: AsyncMock, mock_add_listener: AsyncMock, ) -> None: @@ -134,13 +133,9 @@ async def test_lock_streaming( await reload_platform(hass, entry, [Platform.LOCK]) - # Assert the entities restored their values - for entity_id in ( - "lock.test_lock", - "lock.test_charge_cable_lock", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=f"{entity_id}-locked") + # Assert the entities restored their values with concrete assertions + assert hass.states.get("lock.test_lock").state == LockState.LOCKED + assert hass.states.get("lock.test_charge_cable_lock").state == LockState.LOCKED # Stream update mock_add_listener.send( @@ -157,10 +152,6 @@ async def test_lock_streaming( await reload_platform(hass, entry, [Platform.LOCK]) - # Assert the entities restored their values - for entity_id in ( - "lock.test_lock", - "lock.test_charge_cable_lock", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=f"{entity_id}-unlocked") + # Assert the entities restored their values with concrete assertions + assert hass.states.get("lock.test_lock").state == LockState.UNLOCKED + assert hass.states.get("lock.test_charge_cable_lock").state == LockState.UNLOCKED diff --git a/tests/components/teslemetry/test_number.py b/tests/components/teslemetry/test_number.py index 2c45631a060..ad37b38b716 100644 --- a/tests/components/teslemetry/test_number.py +++ b/tests/components/teslemetry/test_number.py @@ -106,7 +106,6 @@ async def test_number_services( async def test_number_streaming( hass: HomeAssistant, - snapshot: SnapshotAssertion, mock_vehicle_data: AsyncMock, mock_add_listener: AsyncMock, ) -> None: @@ -130,10 +129,6 @@ async def test_number_streaming( await reload_platform(hass, entry, [Platform.NUMBER]) - # Assert the entities restored their values - for entity_id in ( - "number.test_charge_current", - "number.test_charge_limit", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=f"{entity_id}-state") + # Assert the entities restored their values with concrete assertions + assert hass.states.get("number.test_charge_current").state == "24" + assert hass.states.get("number.test_charge_limit").state == "99" diff --git a/tests/components/teslemetry/test_select.py b/tests/components/teslemetry/test_select.py index aa1acb17778..1282276c871 100644 --- a/tests/components/teslemetry/test_select.py +++ b/tests/components/teslemetry/test_select.py @@ -132,7 +132,6 @@ async def test_select_invalid_data( @pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_select_streaming( hass: HomeAssistant, - snapshot: SnapshotAssertion, mock_vehicle_data: AsyncMock, mock_add_listener: AsyncMock, ) -> None: @@ -158,17 +157,13 @@ async def test_select_streaming( await reload_platform(hass, entry, [Platform.SELECT]) - # Assert the entities restored their values - for entity_id in ( - "select.test_seat_heater_front_left", - "select.test_seat_heater_front_right", - "select.test_seat_heater_rear_left", - "select.test_seat_heater_rear_center", - "select.test_seat_heater_rear_right", - "select.test_steering_wheel_heater", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=entity_id) + # Assert the entities restored their values with concrete assertions + assert hass.states.get("select.test_seat_heater_front_left").state == "off" + assert hass.states.get("select.test_seat_heater_front_right").state == "low" + assert hass.states.get("select.test_seat_heater_rear_left").state == "medium" + assert hass.states.get("select.test_seat_heater_rear_center").state == STATE_UNKNOWN + assert hass.states.get("select.test_seat_heater_rear_right").state == "high" + assert hass.states.get("select.test_steering_wheel_heater").state == "off" async def test_export_rule_restore( diff --git a/tests/components/teslemetry/test_sensor.py b/tests/components/teslemetry/test_sensor.py index e8f413433c1..f50c0200c88 100644 --- a/tests/components/teslemetry/test_sensor.py +++ b/tests/components/teslemetry/test_sensor.py @@ -50,8 +50,6 @@ async def test_sensors( @pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_sensors_streaming( hass: HomeAssistant, - snapshot: SnapshotAssertion, - entity_registry: er.EntityRegistry, freezer: FrozenDateTimeFactory, mock_vehicle_data: AsyncMock, mock_add_listener: AsyncMock, @@ -90,19 +88,15 @@ async def test_sensors_streaming( await hass.config_entries.async_reload(entry.entry_id) await hass.async_block_till_done() - # Assert the entities restored their values - for entity_id in ( - "sensor.test_charging", - "sensor.test_battery_level", - "sensor.test_charge_energy_added", - "sensor.test_charger_power", - "sensor.test_charge_cable", - "sensor.test_time_to_full_charge", - "sensor.test_time_to_arrival", - "sensor.teslemetry_credits", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=f"{entity_id}-state") + # Assert the entities restored their values with concrete assertions + assert hass.states.get("sensor.test_charging").state == "charging" + assert hass.states.get("sensor.test_battery_level").state == "90" + assert hass.states.get("sensor.test_charge_energy_added").state == "10" + assert hass.states.get("sensor.test_charger_power").state == "2" + assert hass.states.get("sensor.test_charge_cable").state == "unknown" + assert hass.states.get("sensor.test_time_to_full_charge").state == "unknown" + assert hass.states.get("sensor.test_time_to_arrival").state == "unknown" + assert hass.states.get("sensor.teslemetry_credits").state == "1980" async def test_energy_history_no_time_series( diff --git a/tests/components/teslemetry/test_services.py b/tests/components/teslemetry/test_services.py index 8137946aa3a..6608732b8b0 100644 --- a/tests/components/teslemetry/test_services.py +++ b/tests/components/teslemetry/test_services.py @@ -51,11 +51,11 @@ lon = 153.3726526 async def test_services( hass: HomeAssistant, + entity_registry: er.EntityRegistry, ) -> None: """Tests that the custom services are correct.""" await setup_platform(hass) - entity_registry = er.async_get(hass) # Get a vehicle device ID vehicle_device = entity_registry.async_get("sensor.test_charging").device_id @@ -338,15 +338,15 @@ async def test_services( async def test_service_validation_errors( hass: HomeAssistant, + entity_registry: er.EntityRegistry, ) -> None: """Tests that the custom services handle bad data.""" await setup_platform(hass) - entity_registry = er.async_get(hass) vehicle_device = entity_registry.async_get("sensor.test_charging").device_id - # Bad device ID - with pytest.raises(ServiceValidationError): + # Bad device ID - verify translation key is used + with pytest.raises(ServiceValidationError) as exc_info: await hass.services.async_call( DOMAIN, SERVICE_NAVIGATE_ATTR_GPS_REQUEST, @@ -356,9 +356,10 @@ async def test_service_validation_errors( }, blocking=True, ) + assert exc_info.value.translation_key == "invalid_device" # Test set_scheduled_charging validation error (enable=True but no time) - with pytest.raises(ServiceValidationError): + with pytest.raises(ServiceValidationError) as exc_info: await hass.services.async_call( DOMAIN, SERVICE_SET_SCHEDULED_CHARGING, @@ -368,9 +369,10 @@ async def test_service_validation_errors( }, blocking=True, ) + assert exc_info.value.translation_key == "set_scheduled_charging_time" # Test set_scheduled_departure validation error (preconditioning_enabled=True but no departure_time) - with pytest.raises(ServiceValidationError): + with pytest.raises(ServiceValidationError) as exc_info: await hass.services.async_call( DOMAIN, SERVICE_SET_SCHEDULED_DEPARTURE, @@ -380,9 +382,10 @@ async def test_service_validation_errors( }, blocking=True, ) + assert exc_info.value.translation_key == "set_scheduled_departure_preconditioning" # Test set_scheduled_departure validation error (off_peak_charging_enabled=True but no end_off_peak_time) - with pytest.raises(ServiceValidationError): + with pytest.raises(ServiceValidationError) as exc_info: await hass.services.async_call( DOMAIN, SERVICE_SET_SCHEDULED_DEPARTURE, @@ -392,3 +395,4 @@ async def test_service_validation_errors( }, blocking=True, ) + assert exc_info.value.translation_key == "set_scheduled_departure_off_peak" diff --git a/tests/components/teslemetry/test_switch.py b/tests/components/teslemetry/test_switch.py index 6b31a28db59..4163a5523fa 100644 --- a/tests/components/teslemetry/test_switch.py +++ b/tests/components/teslemetry/test_switch.py @@ -126,8 +126,6 @@ async def test_switch_services( async def test_switch_streaming( hass: HomeAssistant, - snapshot: SnapshotAssertion, - entity_registry: er.EntityRegistry, mock_vehicle_data: AsyncMock, mock_add_listener: AsyncMock, ) -> None: @@ -155,14 +153,10 @@ async def test_switch_streaming( # Reload the entry await reload_platform(hass, entry, [Platform.SWITCH]) - # Assert the entities restored their values - for entity_id in ( - "switch.test_sentry_mode", - "switch.test_auto_seat_climate_left", - "switch.test_auto_seat_climate_right", - "switch.test_auto_steering_wheel_heater", - "switch.test_defrost", - "switch.test_charge", - ): - state = hass.states.get(entity_id) - assert state.state == snapshot(name=entity_id) + # Assert the entities restored their values with concrete assertions + assert hass.states.get("switch.test_sentry_mode").state == STATE_ON + assert hass.states.get("switch.test_auto_seat_climate_left").state == STATE_ON + assert hass.states.get("switch.test_auto_seat_climate_right").state == STATE_OFF + assert hass.states.get("switch.test_auto_steering_wheel_heater").state == STATE_ON + assert hass.states.get("switch.test_defrost").state == STATE_OFF + assert hass.states.get("switch.test_charge").state == STATE_ON