mirror of
https://github.com/home-assistant/core.git
synced 2026-10-07 06:50:41 -04:00
Fix Teslemetry cruise follow distance on unknown values (#183472)
This commit is contained in:
@@ -632,7 +632,11 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryVehicleSensorEntityDescription, ...] = (
|
||||
TeslemetryVehicleSensorEntityDescription(
|
||||
key="cruise_follow_distance",
|
||||
streaming_listener=lambda vehicle, callback: (
|
||||
vehicle.listen_CruiseFollowDistance(callback)
|
||||
vehicle.listen_CruiseFollowDistance(
|
||||
lambda value: callback(
|
||||
int(value) if value and value.isdigit() else None
|
||||
)
|
||||
)
|
||||
),
|
||||
device_class=SensorDeviceClass.DURATION,
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
|
||||
@@ -460,6 +460,46 @@ async def test_sensors_streaming_tpms_none_clears_state(
|
||||
assert hass.states.get(entity_id).state == STATE_UNKNOWN
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"raw_value",
|
||||
[
|
||||
pytest.param("FollowDistanceUnknown", id="unknown"),
|
||||
pytest.param(None, id="none"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_cruise_follow_distance_unknown(
|
||||
hass: HomeAssistant,
|
||||
mock_vehicle_data: AsyncMock,
|
||||
mock_add_listener: AsyncMock,
|
||||
raw_value: str | None,
|
||||
) -> None:
|
||||
"""An unknown streamed follow distance must clear the numeric sensor."""
|
||||
entity_id = "sensor.test_cruise_follow_distance"
|
||||
await setup_platform(hass, [Platform.SENSOR])
|
||||
vin = VEHICLE_DATA_ALT["response"]["vin"]
|
||||
|
||||
mock_add_listener.send(
|
||||
{
|
||||
"vin": vin,
|
||||
"data": {Signal.CRUISE_FOLLOW_DISTANCE: "FollowDistance3"},
|
||||
"createdAt": "2024-10-04T10:45:17.537Z",
|
||||
}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(entity_id).state == "3"
|
||||
|
||||
mock_add_listener.send(
|
||||
{
|
||||
"vin": vin,
|
||||
"data": {Signal.CRUISE_FOLLOW_DISTANCE: raw_value},
|
||||
"createdAt": "2024-10-04T10:45:18.537Z",
|
||||
}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(entity_id).state == STATE_UNKNOWN
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("key", "signal", "raw_value", "state"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user