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:
+25
-14
@@ -180,23 +180,34 @@ def extract_doors(vehicle) -> dict | None:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
doors = vehicle.doors
|
doors = vehicle.doors
|
||||||
result["doors"] = {
|
if doors.lock_state.value is not None:
|
||||||
"overallState": _str(doors.lock_state),
|
result["lock_state"] = _str(doors.lock_state)
|
||||||
"doors": {
|
if doors.open_state.value is not None:
|
||||||
name: {
|
result["open_state"] = _str(doors.open_state)
|
||||||
"lockState": _str(door.lock_state),
|
door_entries = {}
|
||||||
"openState": _str(door.open_state),
|
for name, door in doors.doors.items():
|
||||||
}
|
entry = {}
|
||||||
for name, door in doors.doors.items()
|
if door.lock_state.value is not None:
|
||||||
},
|
entry["lock_state"] = _str(door.lock_state)
|
||||||
"windows": {
|
if door.open_state.value is not None:
|
||||||
name: {"openState": _str(win.open_state)}
|
entry["open_state"] = _str(door.open_state)
|
||||||
for name, win in vehicle.windows.windows.items()
|
if entry:
|
||||||
},
|
door_entries[name] = entry
|
||||||
}
|
if door_entries:
|
||||||
|
result["doors"] = door_entries
|
||||||
except Exception:
|
except Exception:
|
||||||
log.debug("vehicle.doors unavailable", exc_info=True)
|
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
|
return result or None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user