Skip to content

Commit f8d3bc1

Browse files
authored
Volvo: Skip unsupported API fields (#150285)
1 parent fb64ff1 commit f8d3bc1

File tree

8 files changed

+1096
-114
lines changed

8 files changed

+1096
-114
lines changed

homeassistant/components/volvo/coordinator.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
VolvoAuthException,
1616
VolvoCarsApiBaseModel,
1717
VolvoCarsValue,
18+
VolvoCarsValueStatusField,
1819
VolvoCarsVehicle,
1920
)
2021

@@ -36,6 +37,16 @@
3637
type CoordinatorData = dict[str, VolvoCarsApiBaseModel | None]
3738

3839

40+
def _is_invalid_api_field(field: VolvoCarsApiBaseModel | None) -> bool:
41+
if not field:
42+
return True
43+
44+
if isinstance(field, VolvoCarsValueStatusField) and field.status == "ERROR":
45+
return True
46+
47+
return False
48+
49+
3950
class VolvoBaseCoordinator(DataUpdateCoordinator[CoordinatorData]):
4051
"""Volvo base coordinator."""
4152

@@ -121,7 +132,13 @@ async def _async_update_data(self) -> CoordinatorData:
121132
translation_key="update_failed",
122133
) from result
123134

124-
data |= cast(CoordinatorData, result)
135+
api_data = cast(CoordinatorData, result)
136+
data |= {
137+
key: field
138+
for key, field in api_data.items()
139+
if not _is_invalid_api_field(field)
140+
}
141+
125142
valid = True
126143

127144
# Raise an error if not a single API call succeeded

tests/components/volvo/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
"statistics",
2121
"vehicle",
2222
],
23+
"xc60_phev_2020": [
24+
"energy_capabilities",
25+
"energy_state",
26+
"statistics",
27+
"vehicle",
28+
],
2329
"xc90_petrol_2019": ["commands", "statistics", "vehicle"],
2430
}
2531

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"isSupported": true,
3+
"batteryChargeLevel": {
4+
"isSupported": false
5+
},
6+
"electricRange": {
7+
"isSupported": false
8+
},
9+
"chargerConnectionStatus": {
10+
"isSupported": true
11+
},
12+
"chargingSystemStatus": {
13+
"isSupported": true
14+
},
15+
"chargingType": {
16+
"isSupported": false
17+
},
18+
"chargerPowerStatus": {
19+
"isSupported": false
20+
},
21+
"estimatedChargingTimeToTargetBatteryChargeLevel": {
22+
"isSupported": false
23+
},
24+
"targetBatteryChargeLevel": {
25+
"isSupported": true
26+
},
27+
"chargingCurrentLimit": {
28+
"isSupported": false
29+
},
30+
"chargingPower": {
31+
"isSupported": false
32+
}
33+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"batteryChargeLevel": {
3+
"status": "ERROR",
4+
"code": "NOT_SUPPORTED",
5+
"message": "Resource is not supported for this vehicle"
6+
},
7+
"electricRange": {
8+
"status": "ERROR",
9+
"code": "NOT_SUPPORTED",
10+
"message": "Resource is not supported for this vehicle"
11+
},
12+
"chargerConnectionStatus": {
13+
"status": "OK",
14+
"value": "DISCONNECTED",
15+
"updatedAt": "2025-08-07T20:29:18Z"
16+
},
17+
"chargingStatus": {
18+
"status": "OK",
19+
"value": "IDLE",
20+
"updatedAt": "2025-08-07T20:29:18Z"
21+
},
22+
"chargingType": {
23+
"status": "ERROR",
24+
"code": "NOT_SUPPORTED",
25+
"message": "Resource is not supported for this vehicle"
26+
},
27+
"chargerPowerStatus": {
28+
"status": "ERROR",
29+
"code": "NOT_SUPPORTED",
30+
"message": "Resource is not supported for this vehicle"
31+
},
32+
"estimatedChargingTimeToTargetBatteryChargeLevel": {
33+
"status": "ERROR",
34+
"code": "NOT_SUPPORTED",
35+
"message": "Resource is not supported for this vehicle"
36+
},
37+
"chargingCurrentLimit": {
38+
"status": "ERROR",
39+
"code": "NOT_SUPPORTED",
40+
"message": "Resource is not supported for this vehicle"
41+
},
42+
"targetBatteryChargeLevel": {
43+
"status": "ERROR",
44+
"code": "NOT_SUPPORTED",
45+
"message": "Resource is not supported for this vehicle"
46+
},
47+
"chargingPower": {
48+
"status": "ERROR",
49+
"code": "NOT_SUPPORTED",
50+
"message": "Resource is not supported for this vehicle"
51+
}
52+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"averageFuelConsumption": {
3+
"value": 4.0,
4+
"unit": "l/100km",
5+
"timestamp": "2025-08-07T20:29:18.343Z"
6+
},
7+
"averageSpeed": {
8+
"value": 65,
9+
"unit": "km/h",
10+
"timestamp": "2025-08-07T20:29:18.343Z"
11+
},
12+
"tripMeterManual": {
13+
"value": 219.7,
14+
"unit": "km",
15+
"timestamp": "2025-08-07T20:29:18.343Z"
16+
},
17+
"tripMeterAutomatic": {
18+
"value": 0.0,
19+
"unit": "km",
20+
"timestamp": "2025-08-07T20:29:18.343Z"
21+
},
22+
"distanceToEmptyTank": {
23+
"value": 920,
24+
"unit": "km",
25+
"timestamp": "2025-08-07T20:29:18.343Z"
26+
},
27+
"distanceToEmptyBattery": {
28+
"value": 29,
29+
"unit": "km",
30+
"timestamp": "2025-08-07T20:29:18.343Z"
31+
}
32+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"vin": "YV1ABCDEFG1234567",
3+
"modelYear": 2020,
4+
"gearbox": "AUTOMATIC",
5+
"fuelType": "PETROL/ELECTRIC",
6+
"externalColour": "Bright Silver",
7+
"batteryCapacityKWH": 11.832,
8+
"images": {
9+
"exteriorImageUrl": "https://cas.volvocars.com/image/dynamic/MY20_0000/123/exterior-v1/_/default.png?market=se&client=public-api-engineering&angle=1&bg=00000000&w=1920",
10+
"internalImageUrl": "https://cas.volvocars.com/image/dynamic/MY20_0000/123/interior-v1/_/default.jpg?market=se&client=public-api-engineering&angle=0&w=1920"
11+
},
12+
"descriptions": {
13+
"model": "XC60",
14+
"upholstery": "CHARCOAL/LEABR3/CHARC/SPO",
15+
"steering": "LEFT"
16+
}
17+
}

0 commit comments

Comments
 (0)