itchannel / fordpass-ha

Fordpass integration for Home Assistant
316 stars 58 forks source link

'NoneType' object does not support item assignment #367

Closed TravelingAdMan closed 1 year ago

TravelingAdMan commented 1 year ago

The following has been coming up in the logs and I cannot get any data from FordPass. This was previously working and I tried rolling back to various early versions of the fordpass-ha code to no avail.

Any ideas? Thanks!

Logger: custom_components.fordpass Source: custom_components/fordpass/init.py:227 Integration: Fordpass (documentation, issues) First occurred: 7:48:13 PM (6 occurrences) Last logged: 7:50:08 PM

'NoneType' object does not support item assignment

itchannel commented 1 year ago

Does a restart fix it? I think it might be related to the ongoing instability issue in the new API endpoint.

I'm currently working on a fix, so hopefully that will fix it for you.

TravelingAdMan commented 1 year ago

A restart of HA or the OS does not have any effect. I’ve even tried this on a fresh install of the OS and HA without restoring from my old config and I still get the same result.

I have verified that I am still able to manipulate my car from the FordPass iOS app.

itchannel commented 1 year ago

Try the 1.58 Beta. I've added a lot more granular logging and error handling. So might be able to narrow your issue down a little more. Just make sure debugging is turned on.

Also what previous version worked for you and what is your region?

TravelingAdMan commented 1 year ago

Hi I appreciate your work on this!

I have a couple new errors:

This error originated from a custom integration.

Logger: custom_components.fordpass Source: custom_components/fordpass/init.py:229 Integration: Fordpass (documentation, issues) First occurred: 7:43:42 AM (1 occurrences) Last logged: 7:43:42 AM

403 Client Error: Forbidden for url: https://api.autonomic.ai/v1/telemetry/sources/fordpass/vehicles/##VIN REDACTED##?lrdt=01-01-1970+00%3A00%3A00

This error originated from a custom integration.

Logger: custom_components.fordpass Source: custom_components/fordpass/init.py:230 Integration: Fordpass (documentation, issues) First occurred: 7:43:42 AM (1 occurrences) Last logged: 7:43:42 AM

Error communicating with FordPass for ##VIN REDACTED##

This error originated from a custom integration.

Logger: custom_components.fordpass Source: custom_components/fordpass/init.py:231 Integration: Fordpass (documentation, issues) First occurred: 7:43:42 AM (1 occurrences) Last logged: 7:43:42 AM

Returning Stale data to prevent unavaliable status

This error originated from a custom integration.

Logger: custom_components.fordpass Source: helpers/update_coordinator.py:322 Integration: Fordpass (documentation, issues) First occurred: 7:43:42 AM (5 occurrences) Last logged: 7:48:28 AM

Error fetching fordpass data: Error communicating with FordPass for ##VIN REDACTED##

Those 4 errors are now repeating.

SquidBytes commented 1 year ago

So there is a problem getting the vehicle status from the new API, which is Forbidden URL. This could mean you have an expired token. Few quick questions just to verify

Also another reboot after some time could help communication. I would also be curious to see what the output of autonomicData.py is

itchannel commented 1 year ago

@TravelingAdMan

Can you confirm the following on top of @SquidBytes questions.

TravelingAdMan commented 1 year ago

Those same 4 errors have occurred 238 times since installing the beta and are still occurring as of a minute ago of this writing.

I’m in the US with a 2022 Ford Explorer.

I can access the vehicle from the iOS app and remote start and lock and unlock the car as of 10 minutes ago.

It is the only account connected to FordPass and the only vehicle on a new install of Debian and HA that I installed yesterday. I did not restore my old config and went from scratch.

I will reboot now and see if there is any change.

TravelingAdMan commented 1 year ago

Reboot had no change. Deleted FordPass integration checked the directory to make sure the token was gone. Redownloaded FordPassHA latest beta. Same errors as before.

SquidBytes commented 1 year ago

Are you able to run 'autonimicData py' and get any output? I'm going to guess its not going to work - but if it does the json data can help.

SquidBytes commented 1 year ago

Just want to also cover some basics to rule out other potential problems. Does your fordpass_token.txt file contain information? Are you using a VPN?

TravelingAdMan commented 1 year ago

FordPass token contains data. No VPN.

when I go to run the python script I receive the following.

nents/fordpass $ sudo python3 autonomicData.py Error finding FordPass token text file: /config/custom_components/fordpass/*_fordpass_token.txt, []

Could this be a file permissions issue on my end? I can clearly see the token file that would match that wild card format in the directory and the token contains data.

itchannel commented 1 year ago

@SquidBytes might be a question for you I tried your script and it works fine so must be something with @TravelingAdMan HA setup.

@TravelingAdMan can you cat out the token file from the terminal. Also might be worth manually putting the path to the file in autonomics.PY

replace the below line should work

    existingfordToken = os.path.join(fordPassDir, "*_fordpass_token.txt")

with

existingfordToken = "/config/custom_components/fordpass/{EMAIL_HERE}_fordpass_token.txt"

Make sure you replace {EMAIL_HERE} with the email used/ one in the token filename.

SquidBytes commented 1 year ago

FordPass token contains data. No VPN.

👍

nents/fordpass $ sudo python3 autonomicData.py Error finding FordPass token text file: /config/custom_components/fordpass/*_fordpass_token.txt, []

You shouldn't need to run it as sudo. Does your folder structure look any different from that when you are in a terminal? For example, if you go into the fordpass directory on HA and pwd, do you get /config/custom_components/fordpass? I'm assuming yes, because I can see "nents/fordpass" in your output.

As I'm tying this I'm having extra thoughts to help troubleshoot. You said earlier

new install of Debian and HA that I installed yesterday.

Are you running HA in a VM? or a Docker within Debian? The paths in my autonomicData.py are local paths, which may be different depending on your configuration but if you're running it locally in the same directory it should be fine. If you're running HA in a docker, and you're ssh'd into Debian, just make sure you are in your docker environment

As itchannel said it would be useful to know if, while in the terminal, you are able to cat {email}_fordpass_token.txt If nothing is printed, or you have a "No such file or directory" problem make sure you're in the right directory and check the contents with ls

Could this be a file permissions issue on my end? I can clearly see the token file that would match that wild card format in the directory and the token contains data.

I wouldn't think so, because if the token file exists, it was created by the integration so the permissions should be fine.

Also, as far as troubleshooting and me telling you to run different commands - I don't mean to insinuate you don't know what you're doing, I just don't know your experience working in a terminal.

For comparison. I am running HomeAssistant in its own VM. I have added my VIN number into the autonomicData.py script using VSCode. Using the VSCode Terminal, this is what my structure looks like running the commands and ensuring it works. image

TravelingAdMan commented 1 year ago

So...

I am running HA in docker. I figured out that it was looking for my config directory in the root of my system and not in my actual config directory in my user directory. After changing the path to my config directory and adding my vin to the fp_vin variable in the autonomicData.py I am receiving the following error when running from terminal.

jon@berry4:~/docker/homeAssistant/config/custom_components/fordpass $ python3 autonomicData.py Starting Automatically redacting json HTTP Error: 403 Client Error: Forbidden for url: https://api.autonomic.ai/v1beta/telemetry/sources/fordpass/vehicles/##VIN##:query Traceback (most recent call last): File "/home/jon/docker/homeAssistant/config/custom_components/fordpass/autonomicData.py", line 168, in <module> with open(fileName, 'w') as file: ^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '/config/custom_components/fordpass/my_status_2023-10-16_09:08:55_REDACTED.json'

When I run from the bash of the home assistant docker container I receive the same

6056a486b15e:/config/custom_components/fordpass$ python3 autonomicData.py Starting Automatically redacting json HTTP Error: 403 Client Error: Forbidden for url: https://api.autonomic.ai/v1beta/telemetry/sources/fordpass/vehicles/##VIN##:query File saved: /config/custom_components/fordpass/my_status_2023-10-16_09:26:50_REDACTED.json Note: json file will be deleted if fordpass-ha is updated

Note: I am replacing my VIN number with ##VIN##

SquidBytes commented 1 year ago

I am running HA in docker. I figured out that it was looking for my config directory in the root of my system and not in my actual config directory in my user directory

Gotcha, yeah I didn't think of that until recently. Everyone's setup is a bit different.

HTTP Error: 403 Client Error: Forbidden for url: https://api.autonomic.ai/v1beta/telemetry/sources/fordpass/vehicles/##VIN##

Yeah, this is about what I expected, I was just hoping something else might happen.

A request is being submitted, you're just being blocked. That's why we kept asking if you're account was locked out, or if the app is unable to communicate with your vehicle. Error 403 points me in that direction.

I would be hesitant to tell you to log out of your FordPass App because IF you are locked out, it might only take place after you sign out. Maybe try logging into your account on a desktop?

If you're able to login, maybe try creating a secondary account to use with HA? Just make sure you authorize your vehicle.

These are just suggestions, I'm struggling to think of other issues that could be causing this.

TravelingAdMan commented 1 year ago

Everything works now!

There was an issue with our user accounts once I logged out and logged in with the previous email address everything started working again. I had to call FordPass support in order for them to let me know that if you change your email address you have to login with the previous email in order to authorize new accounts. It was only after I logged out though that it requested authorization. Prior to that the app was working with my new email. Weird and something to keep top of mind if this issue comes up for somebody else!

ziptbm commented 1 year ago

I just updated to 1.58-Beta1 and I'm now seeing this error.

`This error originated from a custom integration.

Logger: custom_components.fordpass Source: custom_components/fordpass/init.py:229 Integration: Fordpass (documentation, issues) First occurred: 13:40:40 (3 occurrences) Last logged: 14:10:49

'NoneType' object is not subscriptable cannot access local variable 'response' where it is not associated with a value`

and I'm also seeing this one as well.

`This error originated from a custom integration.

Logger: custom_components.fordpass Source: custom_components/fordpass/init.py:231 Integration: Fordpass (documentation, issues) First occurred: 13:40:40 (3 occurrences) Last logged: 14:10:49

Returning Stale data to prevent unavaliable status`

I noticed that my Mach-E is continually reporting as unlocked even though that vehicle automatically locks the doors as soon as I walk away (unlike my F150 Lightning). When I send the lock command, it shows locking for a bit and then returns as unlocked. I'm not sure if this is related to the issues shared above, but it's persistent across reboots. My F150 Lightning unlock command works without issue and reports correctly.

I've got debug logging enabled, but just need to know what specifically to pull from those logs that would be helpful here.

TravelingAdMan commented 1 year ago

The fix for my issue was logging out of FordPass and logging back in to discover that an email change had caused my account to stop working even though it was still working in the FordPass app. When logging back in I had to request activation from my original email address.

I would try logging out and logging back in to your FordPass app on your phone to see if there are any issues with your account; along with removing the FordPass HA integration from Settings->Devices & Services in HA. Reloading HA (or better rebooting your OS) and then adding your FordPass integration. If the same errors appear then it was a different issue than mine.

Best of luck!

itchannel commented 1 year ago

Closing as original issue was fixed :)