Skip to content

Commit 4e247a6

Browse files
thomasddnfrenck
authored andcommitted
Prevent duplicate entities for Volvo integration (home-assistant#151779)
1 parent 77f897a commit 4e247a6

File tree

9 files changed

+1533
-6
lines changed

9 files changed

+1533
-6
lines changed

homeassistant/components/volvo/sensor.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,19 @@ async def async_setup_entry(
354354
async_add_entities: AddConfigEntryEntitiesCallback,
355355
) -> None:
356356
"""Set up sensors."""
357+
358+
entities: dict[str, VolvoSensor] = {}
357359
coordinators = entry.runtime_data.interval_coordinators
358-
async_add_entities(
359-
VolvoSensor(coordinator, description)
360-
for coordinator in coordinators
361-
for description in _DESCRIPTIONS
362-
if description.api_field in coordinator.data
363-
)
360+
361+
for coordinator in coordinators:
362+
for description in _DESCRIPTIONS:
363+
if description.key in entities:
364+
continue
365+
366+
if description.api_field in coordinator.data:
367+
entities[description.key] = VolvoSensor(coordinator, description)
368+
369+
async_add_entities(entities.values())
364370

365371

366372
class VolvoSensor(VolvoEntity, SensorEntity):

tests/components/volvo/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
"vehicle",
2828
],
2929
"xc90_petrol_2019": ["commands", "statistics", "vehicle"],
30+
"xc90_phev_2024": [
31+
"energy_capabilities",
32+
"energy_state",
33+
"statistics",
34+
"vehicle",
35+
],
3036
}
3137

3238

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": true
5+
},
6+
"electricRange": {
7+
"isSupported": true
8+
},
9+
"chargerConnectionStatus": {
10+
"isSupported": true
11+
},
12+
"chargingSystemStatus": {
13+
"isSupported": true
14+
},
15+
"chargingType": {
16+
"isSupported": true
17+
},
18+
"chargerPowerStatus": {
19+
"isSupported": true
20+
},
21+
"estimatedChargingTimeToTargetBatteryChargeLevel": {
22+
"isSupported": true
23+
},
24+
"targetBatteryChargeLevel": {
25+
"isSupported": true
26+
},
27+
"chargingCurrentLimit": {
28+
"isSupported": false
29+
},
30+
"chargingPower": {
31+
"isSupported": false
32+
}
33+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"batteryChargeLevel": {
3+
"status": "OK",
4+
"value": 87.3,
5+
"unit": "percentage",
6+
"updatedAt": "2025-09-05T07:58:14Z"
7+
},
8+
"electricRange": {
9+
"status": "OK",
10+
"value": 26,
11+
"unit": "miles",
12+
"updatedAt": "2025-09-05T07:58:14Z"
13+
},
14+
"chargerConnectionStatus": {
15+
"status": "OK",
16+
"value": "DISCONNECTED",
17+
"updatedAt": "2025-09-05T07:58:14Z"
18+
},
19+
"chargingStatus": {
20+
"status": "OK",
21+
"value": "IDLE",
22+
"updatedAt": "2025-09-05T07:58:14Z"
23+
},
24+
"chargingType": {
25+
"status": "OK",
26+
"value": "NONE",
27+
"updatedAt": "2025-09-05T07:58:14Z"
28+
},
29+
"chargerPowerStatus": {
30+
"status": "OK",
31+
"value": "NO_POWER_AVAILABLE",
32+
"updatedAt": "2025-09-05T07:58:14Z"
33+
},
34+
"estimatedChargingTimeToTargetBatteryChargeLevel": {
35+
"status": "OK",
36+
"value": 0,
37+
"unit": "minutes",
38+
"updatedAt": "2025-09-05T07:58:14Z"
39+
},
40+
"chargingCurrentLimit": {
41+
"status": "ERROR",
42+
"code": "NOT_SUPPORTED",
43+
"message": "Resource is not supported for this vehicle"
44+
},
45+
"targetBatteryChargeLevel": {
46+
"status": "ERROR",
47+
"code": "ERROR_READING_PROPERTY",
48+
"message": "Failed to retrieve property."
49+
},
50+
"chargingPower": {
51+
"status": "ERROR",
52+
"code": "NOT_SUPPORTED",
53+
"message": "Resource is not supported for this vehicle"
54+
}
55+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"averageFuelConsumption": {
3+
"value": 2.0,
4+
"unit": "l/100km",
5+
"timestamp": "2025-09-04T18:03:57.437Z"
6+
},
7+
"averageEnergyConsumption": {
8+
"value": 19.9,
9+
"unit": "kWh/100km",
10+
"timestamp": "2025-09-04T18:03:57.437Z"
11+
},
12+
"averageFuelConsumptionAutomatic": {
13+
"value": 0.0,
14+
"unit": "l/100km",
15+
"timestamp": "2025-09-04T18:03:57.437Z"
16+
},
17+
"averageSpeed": {
18+
"value": 47,
19+
"unit": "km/h",
20+
"timestamp": "2025-09-04T18:03:57.437Z"
21+
},
22+
"averageSpeedAutomatic": {
23+
"value": 37,
24+
"unit": "km/h",
25+
"timestamp": "2025-09-04T18:03:57.437Z"
26+
},
27+
"tripMeterManual": {
28+
"value": 5935.8,
29+
"unit": "km",
30+
"timestamp": "2025-09-04T18:03:57.437Z"
31+
},
32+
"tripMeterAutomatic": {
33+
"value": 23.7,
34+
"unit": "km",
35+
"timestamp": "2025-09-04T18:03:57.437Z"
36+
},
37+
"distanceToEmptyTank": {
38+
"value": 804,
39+
"unit": "km",
40+
"timestamp": "2025-09-04T18:03:57.437Z"
41+
},
42+
"distanceToEmptyBattery": {
43+
"value": 43,
44+
"unit": "km",
45+
"timestamp": "2025-09-05T07:58:14.760Z"
46+
}
47+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"vin": "YV1ABCDEFG1234567",
3+
"modelYear": 2024,
4+
"gearbox": "AUTOMATIC",
5+
"fuelType": "PETROL/ELECTRIC",
6+
"externalColour": "Crystal White Pearl",
7+
"batteryCapacityKWH": 18.819,
8+
"images": {
9+
"exteriorImageUrl": "https://cas.volvocars.com/image/dynamic/MY24_0000/123/_/default.png?market=se&client=public-api-engineering&angle=1&bg=00000000&w=1920",
10+
"internalImageUrl": "https://cas.volvocars.com/image/dynamic/MY24_0000/123/_/default.jpg?market=se&client=public-api-engineering&angle=0&w=1920"
11+
},
12+
"descriptions": {
13+
"model": "XC90",
14+
"upholstery": "null",
15+
"steering": "LEFT"
16+
}
17+
}

0 commit comments

Comments
 (0)