Skip to content

Commit

Permalink
fix: added workaround to extract device_id from extra attributes (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
alryaz committed Nov 29, 2022
1 parent bb6ae14 commit b035d49
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions custom_components/pandora_cas/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,22 @@ async def async_fetch_changes(self, timestamp: Optional[int] = None):

return content, updated_device_ids

@staticmethod
def _get_device_id(data: Mapping[str, Any]) -> str:
# Fixes absense of identifier value on certain device responses.
try:
device_id = data["id"]
except KeyError:
device_id = data["dev_id"]

if not device_id:
raise ValueError("Device ID is empty!")

try:
return int(device_id)
except (TypeError, ValueError):
raise ValueError(f"Could not convert device ID '{device_id}' to integer")

def _process_ws_initial_state(
self, device: "PandoraOnlineDevice", data: Mapping[str, Any]
) -> Tuple[CurrentState, Dict[str, Any]]:
Expand All @@ -769,7 +785,7 @@ def _process_ws_initial_state(
)

current_state_args = dict(
identifier=data["id"],
identifier=self._get_device_id(data),
latitude=data["x"],
longitude=data["y"],
speed=data["speed"],
Expand Down Expand Up @@ -1020,7 +1036,7 @@ def _process_ws_event(
self, device: "PandoraOnlineDevice", data: Mapping[str, Any]
) -> TrackingEvent:
return TrackingEvent(
identifier=data["id"],
identifier=self._get_device_id(data),
bit_state=BitStatus(int(data["bit_state_1"])),
cabin_temperature=data["cabin_temp"],
engine_rpm=data["engine_rpm"],
Expand Down

0 comments on commit b035d49

Please sign in to comment.