Skip to content

Commit d157ff5

Browse files
authored
Merge pull request #54 from tube0013/fix-50
Fix processing of incoming webhook location
2 parents 853c784 + 34d8892 commit d157ff5

File tree

5 files changed

+441
-15
lines changed

5 files changed

+441
-15
lines changed

custom_components/smartcar/coordinator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ def _is_v2_value_if_string(
157157
"range",
158158
),
159159
EntityDescriptionKey.LOCATION: DatapointConfig(
160-
"location-preciselocation", ["read_location"], "/location", None
160+
"location-preciselocation",
161+
["read_location"],
162+
"/location",
163+
None,
164+
lambda location: location,
161165
),
162166
EntityDescriptionKey.ODOMETER: DatapointConfig(
163167
"odometer-traveleddistance", ["read_odometer"], "/odometer", "distance"

custom_components/smartcar/device_tracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SmartcarTrackerDescription(TrackerEntityDescription, SmartcarEntityDescrip
2626
SmartcarTrackerDescription(
2727
key=EntityDescriptionKey.LOCATION,
2828
name="Location",
29-
value_key_path="location-preciselocation.value",
29+
value_key_path="location-preciselocation",
3030
value_cast=lambda location: location or {},
3131
icon="mdi:car",
3232
),

tests/snapshots/test_device_tracker.ambr

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,292 @@
99
}),
1010
])
1111
# ---
12+
# name: test_webhook_update[vehicle_state-vw_id_4][binary_sensor.vw_id_4_charging_cable_plugged_in]
13+
StateSnapshot({
14+
'attributes': ReadOnlyDict({
15+
'device_class': 'plug',
16+
'friendly_name': 'VW ID.4 Charging Cable Plugged In',
17+
}),
18+
'context': <ANY>,
19+
'entity_id': 'binary_sensor.vw_id_4_charging_cable_plugged_in',
20+
'last_changed': <ANY>,
21+
'last_reported': <ANY>,
22+
'last_updated': <ANY>,
23+
'state': 'unavailable',
24+
})
25+
# ---
26+
# name: test_webhook_update[vehicle_state-vw_id_4][device_tracker.vw_id_4_location]
27+
StateSnapshot({
28+
'attributes': ReadOnlyDict({
29+
'age': '2025-12-08T20:54:12+00:00',
30+
'fetched_at': '2025-12-08T21:34:15.488000+00:00',
31+
'friendly_name': 'VW ID.4 Location',
32+
'gps_accuracy': 0,
33+
'icon': 'mdi:car',
34+
'latitude': 52.238523055555554,
35+
'longitude': 0.15465555555555555,
36+
'source_type': <SourceType.GPS: 'gps'>,
37+
}),
38+
'context': <ANY>,
39+
'entity_id': 'device_tracker.vw_id_4_location',
40+
'last_changed': <ANY>,
41+
'last_reported': <ANY>,
42+
'last_updated': <ANY>,
43+
'state': 'not_home',
44+
})
45+
# ---
46+
# name: test_webhook_update[vehicle_state-vw_id_4][lock.vw_id_4_door_lock]
47+
StateSnapshot({
48+
'attributes': ReadOnlyDict({
49+
'friendly_name': 'VW ID.4 Door Lock',
50+
'supported_features': <LockEntityFeature: 0>,
51+
}),
52+
'context': <ANY>,
53+
'entity_id': 'lock.vw_id_4_door_lock',
54+
'last_changed': <ANY>,
55+
'last_reported': <ANY>,
56+
'last_updated': <ANY>,
57+
'state': 'unavailable',
58+
})
59+
# ---
60+
# name: test_webhook_update[vehicle_state-vw_id_4][number.vw_id_4_charge_limit]
61+
StateSnapshot({
62+
'attributes': ReadOnlyDict({
63+
'friendly_name': 'VW ID.4 Charge Limit',
64+
'icon': 'mdi:battery-charging-80',
65+
'max': 100.0,
66+
'min': 50.0,
67+
'mode': <NumberMode.BOX: 'box'>,
68+
'step': 1.0,
69+
'unit_of_measurement': '%',
70+
}),
71+
'context': <ANY>,
72+
'entity_id': 'number.vw_id_4_charge_limit',
73+
'last_changed': <ANY>,
74+
'last_reported': <ANY>,
75+
'last_updated': <ANY>,
76+
'state': 'unavailable',
77+
})
78+
# ---
79+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_battery]
80+
StateSnapshot({
81+
'attributes': ReadOnlyDict({
82+
'device_class': 'battery',
83+
'friendly_name': 'VW ID.4 Battery',
84+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
85+
'unit_of_measurement': '%',
86+
}),
87+
'context': <ANY>,
88+
'entity_id': 'sensor.vw_id_4_battery',
89+
'last_changed': <ANY>,
90+
'last_reported': <ANY>,
91+
'last_updated': <ANY>,
92+
'state': 'unavailable',
93+
})
94+
# ---
95+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_battery_capacity]
96+
StateSnapshot({
97+
'attributes': ReadOnlyDict({
98+
'device_class': 'energy_storage',
99+
'friendly_name': 'VW ID.4 Battery Capacity',
100+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
101+
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
102+
}),
103+
'context': <ANY>,
104+
'entity_id': 'sensor.vw_id_4_battery_capacity',
105+
'last_changed': <ANY>,
106+
'last_reported': <ANY>,
107+
'last_updated': <ANY>,
108+
'state': 'unavailable',
109+
})
110+
# ---
111+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_charging_status]
112+
StateSnapshot({
113+
'attributes': ReadOnlyDict({
114+
'friendly_name': 'VW ID.4 Charging Status',
115+
'icon': 'mdi:ev-station',
116+
}),
117+
'context': <ANY>,
118+
'entity_id': 'sensor.vw_id_4_charging_status',
119+
'last_changed': <ANY>,
120+
'last_reported': <ANY>,
121+
'last_updated': <ANY>,
122+
'state': 'unavailable',
123+
})
124+
# ---
125+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_engine_oil_life]
126+
StateSnapshot({
127+
'attributes': ReadOnlyDict({
128+
'friendly_name': 'VW ID.4 Engine Oil Life',
129+
'icon': 'mdi:oil-level',
130+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
131+
'unit_of_measurement': '%',
132+
}),
133+
'context': <ANY>,
134+
'entity_id': 'sensor.vw_id_4_engine_oil_life',
135+
'last_changed': <ANY>,
136+
'last_reported': <ANY>,
137+
'last_updated': <ANY>,
138+
'state': 'unavailable',
139+
})
140+
# ---
141+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_fuel]
142+
StateSnapshot({
143+
'attributes': ReadOnlyDict({
144+
'friendly_name': 'VW ID.4 Fuel',
145+
'icon': 'mdi:gas-station',
146+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
147+
'unit_of_measurement': <UnitOfVolume.LITERS: 'L'>,
148+
}),
149+
'context': <ANY>,
150+
'entity_id': 'sensor.vw_id_4_fuel',
151+
'last_changed': <ANY>,
152+
'last_reported': <ANY>,
153+
'last_updated': <ANY>,
154+
'state': 'unavailable',
155+
})
156+
# ---
157+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_fuel_percent]
158+
StateSnapshot({
159+
'attributes': ReadOnlyDict({
160+
'friendly_name': 'VW ID.4 Fuel Percent',
161+
'icon': 'mdi:gas-station',
162+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
163+
'unit_of_measurement': '%',
164+
}),
165+
'context': <ANY>,
166+
'entity_id': 'sensor.vw_id_4_fuel_percent',
167+
'last_changed': <ANY>,
168+
'last_reported': <ANY>,
169+
'last_updated': <ANY>,
170+
'state': 'unavailable',
171+
})
172+
# ---
173+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_fuel_range]
174+
StateSnapshot({
175+
'attributes': ReadOnlyDict({
176+
'device_class': 'distance',
177+
'friendly_name': 'VW ID.4 Fuel Range',
178+
'icon': 'mdi:map-marker-distance',
179+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
180+
'unit_of_measurement': <UnitOfLength.KILOMETERS: 'km'>,
181+
}),
182+
'context': <ANY>,
183+
'entity_id': 'sensor.vw_id_4_fuel_range',
184+
'last_changed': <ANY>,
185+
'last_reported': <ANY>,
186+
'last_updated': <ANY>,
187+
'state': 'unavailable',
188+
})
189+
# ---
190+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_odometer]
191+
StateSnapshot({
192+
'attributes': ReadOnlyDict({
193+
'device_class': 'distance',
194+
'friendly_name': 'VW ID.4 Odometer',
195+
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
196+
'unit_of_measurement': <UnitOfLength.KILOMETERS: 'km'>,
197+
}),
198+
'context': <ANY>,
199+
'entity_id': 'sensor.vw_id_4_odometer',
200+
'last_changed': <ANY>,
201+
'last_reported': <ANY>,
202+
'last_updated': <ANY>,
203+
'state': 'unavailable',
204+
})
205+
# ---
206+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_range]
207+
StateSnapshot({
208+
'attributes': ReadOnlyDict({
209+
'device_class': 'distance',
210+
'friendly_name': 'VW ID.4 Range',
211+
'icon': 'mdi:map-marker-distance',
212+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
213+
'unit_of_measurement': <UnitOfLength.KILOMETERS: 'km'>,
214+
}),
215+
'context': <ANY>,
216+
'entity_id': 'sensor.vw_id_4_range',
217+
'last_changed': <ANY>,
218+
'last_reported': <ANY>,
219+
'last_updated': <ANY>,
220+
'state': 'unavailable',
221+
})
222+
# ---
223+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_tire_pressure_back_left]
224+
StateSnapshot({
225+
'attributes': ReadOnlyDict({
226+
'device_class': 'pressure',
227+
'friendly_name': 'VW ID.4 Tire Pressure Back Left',
228+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
229+
'unit_of_measurement': <UnitOfPressure.KPA: 'kPa'>,
230+
}),
231+
'context': <ANY>,
232+
'entity_id': 'sensor.vw_id_4_tire_pressure_back_left',
233+
'last_changed': <ANY>,
234+
'last_reported': <ANY>,
235+
'last_updated': <ANY>,
236+
'state': 'unavailable',
237+
})
238+
# ---
239+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_tire_pressure_back_right]
240+
StateSnapshot({
241+
'attributes': ReadOnlyDict({
242+
'device_class': 'pressure',
243+
'friendly_name': 'VW ID.4 Tire Pressure Back Right',
244+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
245+
'unit_of_measurement': <UnitOfPressure.KPA: 'kPa'>,
246+
}),
247+
'context': <ANY>,
248+
'entity_id': 'sensor.vw_id_4_tire_pressure_back_right',
249+
'last_changed': <ANY>,
250+
'last_reported': <ANY>,
251+
'last_updated': <ANY>,
252+
'state': 'unavailable',
253+
})
254+
# ---
255+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_tire_pressure_front_left]
256+
StateSnapshot({
257+
'attributes': ReadOnlyDict({
258+
'device_class': 'pressure',
259+
'friendly_name': 'VW ID.4 Tire Pressure Front Left',
260+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
261+
'unit_of_measurement': <UnitOfPressure.KPA: 'kPa'>,
262+
}),
263+
'context': <ANY>,
264+
'entity_id': 'sensor.vw_id_4_tire_pressure_front_left',
265+
'last_changed': <ANY>,
266+
'last_reported': <ANY>,
267+
'last_updated': <ANY>,
268+
'state': 'unavailable',
269+
})
270+
# ---
271+
# name: test_webhook_update[vehicle_state-vw_id_4][sensor.vw_id_4_tire_pressure_front_right]
272+
StateSnapshot({
273+
'attributes': ReadOnlyDict({
274+
'device_class': 'pressure',
275+
'friendly_name': 'VW ID.4 Tire Pressure Front Right',
276+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
277+
'unit_of_measurement': <UnitOfPressure.KPA: 'kPa'>,
278+
}),
279+
'context': <ANY>,
280+
'entity_id': 'sensor.vw_id_4_tire_pressure_front_right',
281+
'last_changed': <ANY>,
282+
'last_reported': <ANY>,
283+
'last_updated': <ANY>,
284+
'state': 'unavailable',
285+
})
286+
# ---
287+
# name: test_webhook_update[vehicle_state-vw_id_4][switch.vw_id_4_charging]
288+
StateSnapshot({
289+
'attributes': ReadOnlyDict({
290+
'friendly_name': 'VW ID.4 Charging',
291+
'icon': 'mdi:ev-plug-type2',
292+
}),
293+
'context': <ANY>,
294+
'entity_id': 'switch.vw_id_4_charging',
295+
'last_changed': <ANY>,
296+
'last_reported': <ANY>,
297+
'last_updated': <ANY>,
298+
'state': 'unavailable',
299+
})
300+
# ---

tests/snapshots/test_diagnostics.ambr

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@
3434
'value': 40.5,
3535
}),
3636
'location-preciselocation': dict({
37-
'value': dict({
38-
'latitude': '**REDACTED**',
39-
'longitude': '**REDACTED**',
40-
}),
37+
'latitude': '**REDACTED**',
38+
'longitude': '**REDACTED**',
4139
}),
4240
'location-preciselocation:data_age': '2019-10-24T00:43:46+00:00',
4341
'odometer-traveleddistance': dict({
@@ -165,10 +163,8 @@
165163
'value': None,
166164
}),
167165
'location-preciselocation': dict({
168-
'value': dict({
169-
'latitude': '**REDACTED**',
170-
'longitude': '**REDACTED**',
171-
}),
166+
'latitude': '**REDACTED**',
167+
'longitude': '**REDACTED**',
172168
}),
173169
'location-preciselocation:data_age': '2025-05-09T15:40:52+00:00',
174170
'location-preciselocation:fetched_at': '2025-05-09T17:27:25.401000+00:00',

0 commit comments

Comments
 (0)