data_model: fix extract_doors — filter None values, fix structure

- Don't store attributes whose .value is None; avoids spurious "None"
  strings in the snapshot (lock_state, open_state were unset)
- Flatten the structure: overall lock_state/open_state now live directly
  under 'doors' instead of the double-nested 'doors.doors.overallState'
- Give vehicle.windows its own try/except, independent of vehicle.doors
- Capture doors.open_state (overall open state) which was missing before

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 21:40:47 +02:00
co-authored by Claude Sonnet 4.6
parent 0b68bcdef8
commit 4dcf2ee6aa
+25 -14
View File
@@ -180,23 +180,34 @@ def extract_doors(vehicle) -> dict | None:
try:
doors = vehicle.doors
result["doors"] = {
"overallState": _str(doors.lock_state),
"doors": {
name: {
"lockState": _str(door.lock_state),
"openState": _str(door.open_state),
}
for name, door in doors.doors.items()
},
"windows": {
name: {"openState": _str(win.open_state)}
for name, win in vehicle.windows.windows.items()
},
}
if doors.lock_state.value is not None:
result["lock_state"] = _str(doors.lock_state)
if doors.open_state.value is not None:
result["open_state"] = _str(doors.open_state)
door_entries = {}
for name, door in doors.doors.items():
entry = {}
if door.lock_state.value is not None:
entry["lock_state"] = _str(door.lock_state)
if door.open_state.value is not None:
entry["open_state"] = _str(door.open_state)
if entry:
door_entries[name] = entry
if door_entries:
result["doors"] = door_entries
except Exception:
log.debug("vehicle.doors unavailable", exc_info=True)
try:
window_entries = {}
for name, win in vehicle.windows.windows.items():
if win.open_state.value is not None:
window_entries[name] = {"open_state": _str(win.open_state)}
if window_entries:
result["windows"] = window_entries
except Exception:
log.debug("vehicle.windows unavailable", exc_info=True)
return result or None