ardevd / jlrpy

Python library for interacting with the JLR Remote Car API
MIT License
84 stars 29 forks source link

Change to fix issue #81 #83

Closed simonjmckenna closed 4 years ago

simonjmckenna commented 4 years ago

the get_status() call in jlrpy when called with no key - returns a new format, breaking charge_offpeak.py This works in parallel with change #80

The change fixes charge_offpeak.py to allow it to get at the returned vehicle status by building a dict from the 'vehiclestatus' list.

ardevd commented 4 years ago

I dont think this works as intended. status = { d['key'] : d['value'] for d in vehicleStatus } will fail because you're still seemingly ignoring the fact that vehicleStatus contains two dicts, coreStatus and evStatus. With the current code you get the folloiwng.

status = { d['key'] : d['value'] for d in vehicleStatus }
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <dictcomp>
TypeError: string indices must be integers

Since you're only interested in the two EV values, I'd do this:

status = { d['key'] : d['value'] for d in vehicleStatus['evStatus'] }
simonjmckenna commented 4 years ago

Yeah tried that,

When I ran it it failed as it appeared I was getting a list with 156 entries from both dicts, rather than the 2 dicts.

There must be something wrong with my environment as that code runs fine on my raspberry pi.

Will rebuild and retry..

S.

Get Outlook for Androidhttps://aka.ms/ghei36


From: ardevd notifications@github.com Sent: Friday, August 7, 2020 10:18:37 AM To: ardevd/jlrpy jlrpy@noreply.github.com Cc: Simon McKenna simes@hotmail.co.uk; Author author@noreply.github.com Subject: Re: [ardevd/jlrpy] Change to fix issue #81 (#83)

I dont think this works as intended. status = { d['key'] : d['value'] for d in vehicleStatus } will fail because you're still seemingly ignoring the fact that vehicleStatus contains two dicts, coreStatus and evStatus. With the current code you get the folloiwng.

status = { d['key'] : d['value'] for d in vehicleStatus } Traceback (most recent call last): File "", line 1, in File "", line 1, in TypeError: string indices must be integers

Since you're only interested in the two EV values, I'd do this:

status = { d['key'] : d['value'] for d in vehicleStatus['evStatus'] }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ardevd/jlrpy/pull/83#issuecomment-670421045, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AF2EGC5JPELPIS2C7JO6DULR7PBG3ANCNFSM4PXCYKAQ.

ardevd commented 4 years ago

Thanks. #84 seems to fix the same issue so I'll go ahead and merge that one and close this one. I really appreciate the contribution!