Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion custom_components/ninebot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,14 @@ def _normalize_status(status: dict[str, Any]) -> dict[str, Any]:
locked = loc.get("lock")
lat = _coerce_float(loc.get("lat"))
lon = _coerce_float(loc.get("lon"))
accuracy = _coerce_float(loc.get("acc"))
if locked is not None:
state["lock"] = _coerce_int(locked)
if lat is not None and lon is not None:
state["location"] = {"latitude": lat, "longitude": lon}
location = {"latitude": lat, "longitude": lon}
if accuracy is not None:
location["accuracy"] = accuracy
state["location"] = location
elif "lock_status" in status:
state["lock"] = status.get("lock_status")

Expand Down
31 changes: 18 additions & 13 deletions custom_components/ninebot/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,27 @@ def entity_picture(self) -> str | None:
picture = self.device_profile.get("image_url")
return picture if isinstance(picture, str) and picture else None

@property
def available(self) -> bool:
return super().available and self.latitude is not None and self.longitude is not None
@callback
def _on_updated(self) -> None:
"""Handle updated data."""
self._attr_latitude = None
self._attr_longitude = None
self._attr_location_accuracy = None

@property
def latitude(self) -> float | None:
location = self.device_state.get("location")
if not isinstance(location, dict):
return None
return

latitude = location.get("latitude")
return latitude if isinstance(latitude, int | float) else None
longitude = location.get("longitude")
if isinstance(latitude, int | float) and isinstance(longitude, int | float):
self._attr_latitude = latitude
self._attr_longitude = longitude

accuracy = location.get("accuracy")
if isinstance(accuracy, int | float):
self._attr_location_accuracy = accuracy

@property
def longitude(self) -> float | None:
location = self.device_state.get("location")
if not isinstance(location, dict):
return None
longitude = location.get("longitude")
return longitude if isinstance(longitude, int | float) else None
def available(self) -> bool:
return super().available and self.latitude is not None and self.longitude is not None