Mark test-coverage as done for Teslemetry quality scale (#161958)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Brett Adams
2026-02-03 21:57:14 +10:00
committed by GitHub
parent 8466dd4c2b
commit d49d3f0a2f
19 changed files with 88 additions and 305 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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'
# ---

View File

@@ -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'
# ---

View File

@@ -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'
# ---

View File

@@ -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'
# ---

View File

@@ -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'
# ---

View File

@@ -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'
# ---

View File

@@ -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'
# ---

View File

@@ -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'
# ---

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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

View File

@@ -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"

View File

@@ -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(

View File

@@ -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(

View File

@@ -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"

View File

@@ -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