dan-r / HomeAssistant-NissanConnect

Unofficial Home Assistant integration for interacting with Nissan Connect vehicles 🚗
Apache License 2.0
32 stars 7 forks source link

Stopped loading #23

Closed davelegg83 closed 4 months ago

davelegg83 commented 4 months ago

What happened? Restarted HA and got the error that Nissan Connect was unable to setup. Had been working fine prior to this.

Log Output

Logger: homeassistant.config_entries
Source: config_entries.py:575
First occurred: 09:01:00 (2 occurrences)
Last logged: 09:29:47

Error setting up entry NissanConnect Account for nissan_connect
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 575, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nissan_connect/__init__.py", line 47, in async_setup_entry
    await hass.async_add_executor_job(kamereon_session.login,
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nissan_connect/kamereon.py", line 698, in login
    oauth_authorize_url = resp.headers['location']
                          ~~~~~~~~~~~~^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/requests/structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
           ~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'location'

Home Assistant Version 2024.5.3

Integration Version 1.0.0

f-zappa commented 4 months ago

Good morning, also just wanted to open a ticket for the same reason. I stumbled upon incorrect data (car location was still 'home' but in fact my wife is using it). My log output is identical to the above. The Nissan App continues working normal, but maybe they changed something in the API?

dan-r commented 4 months ago

Looks like the API has changed. Just having a look to see if its something simple. For reference the response that comes back includes:

error: {
                    description: "Client authentication failed",
                    message: "invalid_client"
                }

Makes me think its just the client ID thats changed

dan-r commented 4 months ago

I've had a play around with it but haven't got anywhere yet. Looks like I'll need to decompile the APK rather than just changing some constants. I won't have any time today but should get a chance to look at it tomorrow/over the weekend.

@Tobiaswk looks like this is affecting the My Leaf app too (I did base the API client here on dartnissanconnect after all). Have you had any luck with these API changes yet?

wralb commented 4 months ago

May be coincidence, but my Ohme android app hasn't been able to get my Nissan's soc for eight hours. I tried reconnecting my Ohme app to the Nissan system and the login to Nissan now fails. Perhaps Nissan didn't tell other suppliers of an API change or this is an 'unexpected event'.

macflyhub commented 4 months ago

Same here. Ariya not updating! Arggg

Tobiaswk commented 4 months ago

@dan-r Yes, I've been looking at it. They've changed the client_id which is now a-ncb-nc-android-prod and the client_secret which is now 6GKIax7fGT5yPHuNmWNVOc4q5POBw1WRSW39ubRA8WPBmQ7MOxhm75EsmKMKENem.

I've just pushed the changes to dartnissanconnect; https://github.com/Tobiaswk/dartnissanconnect/commit/e0301993e872a63c059c3afaa258b413d435fe0e

I'm not sure if other changes have been made. I haven't had time to look at it all but authentication works again.

Tobiaswk commented 4 months ago

Interestingly it seems that whoever is responsible for the NissanConnect app on Android has changed quite a lot in app. They've obfuscated some of the "secrets" so they cannot as easily be decompiled and read directly any longer. It's still fairly easy though ;)

dan-r commented 4 months ago

Thanks @Tobiaswk I appreciate you sharing that - had a brief look at the strings from the apk earlier but couldn't get anything working.

I'll give it a go later on - I must admit my decompilation skills are a bit rusty! 🤣

ClassicGOD commented 4 months ago

For what it's worth I can confirm that changing the values in settings_map in kamereon.py to the ones provided by @Tobiaswk and restarting HA fixes the integration.

f-zappa commented 4 months ago

For what it's worth I can confirm that changing the values in settings_map in kamereon.py to the ones provided by @Tobiaswk and restarting HA fixes the integration.

Great idea, I did the same and it is also working for me.

macflyhub commented 4 months ago

And working now - this is the section I updated. In HA file editor - /homeassistant/custom_components/nissan_connect/kamereon.py Line 33... settings_map = { 'nissan': { 'EU': { 'client_id': 'a-ncb-nc-android-prod', 'client_secret': '6GKIax7fGT5yPHuNmWNVOc4q5POBw1WRSW39ubRA8WPBmQ7MOxhm75EsmKMKENem', 'scope': 'openid profile vehicles', 'auth_base_url': 'https://prod.eu2.auth.kamereon.org/kauth/', 'realm': 'a-ncb-prod', 'redirect_uri': 'org.kamereon.service.nci:/oauth2redirect', 'car_adapter_base_url': 'https://alliance-platform-caradapter-prod.apps.eu2.kamereon.io/car-adapter/', 'notifications_base_url': 'https://alliance-platform-notifications-prod.apps.eu2.kamereon.io/notifications/', 'user_adapter_base_url': 'https://alliance-platform-usersadapter-prod.apps.eu2.kamereon.io/user-adapter/', 'user_base_url': 'https://nci-bff-web-prod.apps.eu2.kamereon.io/bff-web/', },

dan-r commented 4 months ago

Thanks all for the testing - I've just released v0.5.1 with these changes and everything is working again for me now.