filcole / pycarwings2

Python library for interacting with the NissanConnect EV (aka CARWINGS) telematics service.
Apache License 2.0
33 stars 20 forks source link

AttributeError: 'dict' object has no attribute 'length' #10

Closed BenWoodford closed 5 years ago

BenWoodford commented 5 years ago

Seems to be another weird response (or lack of parsing by Python?) in the climate control response.

2019-01-11 17:20:02 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/nissan_leaf.py", line 187, in async_update_data
    await self.async_refresh_data(now)
  File "/config/custom_components/nissan_leaf.py", line 292, in async_refresh_data
    climate_response = await self.async_get_climate()
  File "/config/custom_components/nissan_leaf.py", line 368, in async_get_climate
    self.leaf.get_latest_hvac_status
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/deps/lib/python3.6/site-packages/pycarwings2/pycarwings2.py", line 397, in get_latest_hvac_status
    return CarwingsLatestClimateControlStatusResponse(response)
  File "/config/deps/lib/python3.6/site-packages/pycarwings2/responses.py", line 319, in __init__
    racr.length > 0 and
AttributeError: 'dict' object has no attribute 'length'

Here's the payload back from Nissan:

2019-01-11 17:20:02 DEBUG (SyncWorker_8) [pycarwings2.pycarwings2] Response HTTP Response Body: b'{"status":200,"RemoteACRecords":{"OperationResult":"START_BATTERY","OperationDateAndTime":"11-Jan-2019 17:51","RemoteACOperation":"STOP","ACStartStopDateAndTime":"2019\\/01\\/11 16:52","CruisingRangeAcOn":"74328.0","CruisingRangeAcOff":"79544.0","ACStartStopURL":"","PluginState":"NOT_CONNECTED","ACDurationBatterySec":"900","ACDurationPluggedSec":"7200"}}'

I don't see why that would cause length to not work. It should be processing it as JSON. Might be best to put a try/catch around that and just assume climate control is off if it errors.

filcole commented 5 years ago

Hi @BenWoodford,

Might be caused by attempted fix for #9. Can you add pycarwings2: debug to config: section in HomeAssistant to turn on logging of what exactly the Nissan servers are returning please?

Thanks, Phil

BenWoodford commented 5 years ago

The response JSON is already there 😜

filcole commented 5 years ago

HI Ben,

I'm a doofus, I see it now. Thanks.

Phil

On Fri, 11 Jan 2019 at 22:19, Ben Woodford notifications@github.com wrote:

The response JSON is already there 😜

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/filcole/pycarwings2/issues/10#issuecomment-453675433, or mute the thread https://github.com/notifications/unsubscribe-auth/AFy_vlLoC7mqZ_v_uGAmjPiJpwLZXlq5ks5vCQ4IgaJpZM4Z74Xk .

-- Phil

filcole commented 5 years ago

Hi @BenWoodford. I've release pycarwings2 version 2.4 which should fix this issue. See commit https://github.com/filcole/pycarwings2/commit/71204d1aaea52a191bbb4df210535cd4353bf350

BenWoodford commented 5 years ago

Much obliged, was annoying opening up Home on my phone and finding that it thought Climate Control was already on