Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't add integration #75

Closed
saintfrater opened this issue Oct 21, 2021 · 35 comments
Closed

Can't add integration #75

saintfrater opened this issue Oct 21, 2021 · 35 comments
Labels

Comments

@saintfrater
Copy link

Describe the bug
When I try to setup the account, I get "Language code is not valid."

To Reproduce
Steps to reproduce the behavior:

I've installed the "Toyota Connected Services" via HACS
Then I try to add and integration normally (via Settings -> Integration -> Add Integration, the lookup for toyota)

I'll put email account (working on MYT), password and select "Europe"

Then click on "submit"

Expected behavior
connection to MYT :D

Additional context

System Health

version core-2021.8.5
installation_type Home Assistant Core
dev false
hassio false
docker false
user homeassist
virtualenv true
python_version 3.8.11
os_name Linux
os_version 4.19.0-17-amd64
arch x86_64
timezone Europe/Brussels
Home Assistant Community Store
GitHub API ok
Github API Calls Remaining 4978
Installed Version 1.15.2
Stage running
Available Repositories 887
Installed Repositories 2
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Lovelace
dashboards 5
resources 2
views 9
mode storage
@DurgNomis-drol
Copy link
Owner

I am not able to reproduce this unfortunately and thus can not fix it. I can see that you are running it in a virtualenv. Can you please check that you have the latest version of langcodes installed through pip (3.2.1)? 😃

@savvasha
Copy link

savvasha commented Nov 6, 2021

Hi there @DurgNomis-drol ,

I am having the same issue as @saintfrater . I already checked and my langcodes is the latest (3.2.1) version.

System Health

version core-2021.11.1
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.9.7
os_name Linux
os_version 4.4.180+
arch x86_64
timezone Asia/Nicosia
Home Assistant Community Store
GitHub API ok
Github API Calls Remaining 4993
Installed Version 1.15.2
Stage running
Available Repositories 887
Installed Repositories 6
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Lovelace
dashboards 1
resources 6
views 4
mode storage

@DurgNomis-drol
Copy link
Owner

@savvasha Where are you located in the world? Your Home Assistant timezones is set in Asia? 🤔 Just curious if it is something to do with where the Toyota account is created.

@savvasha
Copy link

savvasha commented Nov 6, 2021

@DurgNomis-drol Well... I am living in Cyprus which politically is in Europe. Nicosia is the capital city.

The strange thing is that your integration was working perfectly... until it stopped working! I tried to re-install it and received the error with the language. I even tried older versions but with the same result...

@DurgNomis-drol
Copy link
Owner

That makes sense. The other guys is from Belgium, so that is probably not the problem then. I will see if I can create a test script tomorrow for you guys so we can isolate the problem 😊

@savvasha
Copy link

savvasha commented Nov 7, 2021

Great! Thanks :)

@DurgNomis-drol
Copy link
Owner

Please make sure that you have the latest version of mytoyota installed (0.7.3) when you run the below script. Please post you output here.

IMPORTANT: Sensitiv data should be censored, but please double check anyways. 😃

import json
import asyncio
from mytoyota.client import MyT

username = "jane@doe.com"
password = "MyPassword"
locale = "en-gb"

client = MyT(username=username, password=password, locale=locale, region="europe")


async def get_information():
    print("Logging in...")
    await client.login()

    print("Retrieving cars...")
    cars = await client.get_vehicles()

    for car in cars:
        vehicle = await client.get_vehicle_status(car)

loop = asyncio.get_event_loop()
loop.run_until_complete(get_information())
loop.close()

@savvasha
Copy link

savvasha commented Nov 7, 2021

Please accept my ignorance... But how can I run your script inside my docker container?

@DurgNomis-drol
Copy link
Owner

You don't have to run it in the container. This script uses the underlying package. You can/should run this in any linux commandline, preferably on the same machine as you HA install. Just create a python script test.py and paste the above into that and edit email and password. The just do python3 test.py in you commandline 😃

@savvasha
Copy link

savvasha commented Nov 7, 2021

Hmm ok. As I mentioned above, my machine is a Synology NAS and I am running HA using a docker container with the official image from homeassistant.
I try to ssh to my NAS and run the python script but it returns the following error:

Traceback (most recent call last):
  File "rav4.py", line 3, in <module>
    from mytoyota.client import MyT
ModuleNotFoundError: No module named 'mytoyota'

Probably I need to find a way to do the procedure inside the container.

@DurgNomis-drol
Copy link
Owner

You need to install the mytoyota module first. Like this pip3 install mytoyota==0.7.3 😃

@savvasha
Copy link

savvasha commented Nov 7, 2021

I think is better to wait for @saintfrater to try it, cause I dont want to mess with my synology environment by installing python components :)

@DurgNomis-drol
Copy link
Owner

You can also do this on any other PC that runs linux 😃

@savvasha
Copy link

savvasha commented Nov 7, 2021

Ok, I tried it to my laptop with linux and got the following:

Logging in...
Retrieving cars...

nothing else

@DurgNomis-drol
Copy link
Owner

Can you try this below instead? 😃

import json
import asyncio
import logging
logging.basicConfig(level=logging.DEBUG)

from mytoyota.client import MyT

username = "jane@doe.com"
password = "MyPassword"
locale = "en-gb"

client = MyT(username=username, password=password, locale=locale, region="europe")


async def get_information():
    print("Logging in...")
    await client.login()

    print("Retrieving cars...")
    cars = await client.get_vehicles()

    for car in cars:
        vehicle = await client.get_vehicle_status(car)

loop = asyncio.get_event_loop()
loop.run_until_complete(get_information())
loop.close()

@savvasha
Copy link

savvasha commented Nov 7, 2021

It seems to working? I mask out some info.

DEBUG:asyncio:Using selector: EpollSelector
Logging in...
DEBUG:mytoyota:Performing first login
DEBUG:mytoyota:Getting new token...
DEBUG:httpx._client:HTTP Request: POST https://ssoms.toyota-europe.com/authenticate "HTTP/1.1 200 OK"
DEBUG:mytoyota:Extracting token from result
DEBUG:mytoyota:Token is the correct format
DEBUG:mytoyota:Saving token and uuid
Retrieving cars...
DEBUG:mytoyota:Getting list of vehicles associated with the account
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'en-gb', 'X-TME-LOCALE': 'en-gb', 'X-TME-TOKEN': 'Q*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=Q*****************************************************************************************************************', 'uuid': 'e***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:httpx._client:HTTP Request: GET https://cpb2cs.toyota-europe.com/vehicle/user/efda1b99************************/vehicles?services=uio&legacy=true "HTTP/1.1 200 OK"
DEBUG:mytoyota:Getting status for vehicle - JTMW53FV6********...
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'en-gb', 'X-TME-LOCALE': 'en-gb', 'X-TME-TOKEN': 'Q*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=Q*****************************************************************************************************************', 'uuid': 'e***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'en-gb', 'X-TME-LOCALE': 'en-gb', 'X-TME-TOKEN': 'Q*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=Q*****************************************************************************************************************', 'uuid': 'e***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'en-gb', 'X-TME-LOCALE': 'en-gb', 'X-TME-TOKEN': 'Q*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=Q*****************************************************************************************************************', 'uuid': 'e***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'en-gb', 'X-TME-LOCALE': 'en-gb', 'X-TME-TOKEN': 'Q*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=Q*****************************************************************************************************************', 'uuid': 'e***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/vehicle/JTMW53FV6********/addtionalInfo "HTTP/1.1 200 OK"
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/users/efda1b99************************/vehicles/JTMW53FV6********/vehicleStatus "HTTP/1.1 200 OK"
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/vehicles/JTMW53FV6********/remoteControl/status "HTTP/1.1 200 OK"
DEBUG:httpx._client:HTTP Request: GET https://cpb2cs.toyota-europe.com/vehicle/user/efda1b99************************/vehicle/JTMW53FV6********?legacy=true&services=fud,connected "HTTP/1.1 200 OK"
DEBUG:mytoyota:Presenting information as an object...
DEBUG:mytoyota:Using legacy odometer data: [{'type': 'mileage', 'value': 4598, 'unit': 'km'}, {'type': 'Fuel', 'value': 100.0}]
DEBUG:mytoyota:Raw sensor data: {'overallStatus': 'OK', 'timestamp': '2021-11-06T14:24:14Z', 'doors': {'warning': False, 'driverSeatDoor': {'warning': False, 'closed': True, 'locked': True}, 'passengerSeatDoor': {'warning': False, 'closed': True, 'locked': True}, 'rearRightSeatDoor': {'warning': False, 'closed': True, 'locked': True}, 'rearLeftSeatDoor': {'warning': False, 'closed': True, 'locked': True}, 'backDoor': {'warning': False, 'closed': True, 'locked': True}}, 'hood': {'closed': True, 'warning': False}, 'lamps': {'warning': False, 'headLamp': {'warning': False, 'off': True}, 'tailLamp': {'warning': False, 'off': True}, 'hazardLamp': {'warning': False, 'off': True}}, 'windows': {'warning': False, 'driverSeatWindow': {'warning': False, 'state': 'close'}, 'passengerSeatWindow': {'warning': False, 'state': 'close'}, 'rearRightSeatWindow': {'warning': False, 'state': 'close'}, 'rearLeftSeatWindow': {'warning': False, 'state': 'close'}}, 'key': {'warning': False, 'inCar': False}, 'lock': {'lockState': 'locked', 'source': 'key', 'failedUnlockPreconditions': ['alarmLocked']}}

@DurgNomis-drol
Copy link
Owner

It works for you on the laptop. Below is a small script for you to run on the Synology NAS, you won't need to install any thing, but this will test the specific function that creates the error you are having.

from langcodes import Language
from langcodes.tag_parser import LanguageTagError

locale = "en-gb"

valid = False
if locale:
    try:
        valid = Language.get(locale).is_valid()
    except LanguageTagError:
        pass

print(valid)

@savvasha
Copy link

savvasha commented Nov 7, 2021

I tried to open a bash console inside my HA container to run the above script. I received the following error:

python3: can't open file '/config/from langcodes import Language
from langcodes.tag_parser import LanguageTagError

locale = "en-gb"

valid = False
if locale:
    try:
        valid = Language.get(locale).is_valid()
    except LanguageTagError:
        pass

print(valid)': [Errno 2] No such file or directory

@savvasha
Copy link

savvasha commented Nov 7, 2021

But I am also getting the following when I try to install langcodes library:

bash-5.1# pip install langcodes
Requirement already satisfied: langcodes in /usr/local/lib/python3.9/site-packages (3.2.1)

@savvasha
Copy link

savvasha commented Nov 7, 2021

Nevermind. I managed to create a python file inside bash and executed.

bash-5.1# python3 test.py
True

And then I used the same method to run your first script:

bash-5.1# python3 rav4.py
Traceback (most recent call last):
  File "/config/rav4.py", line 12, in <module>
    client = MyT(username=username, password=password, locale=locale, region="europe")
  File "/usr/local/lib/python3.9/site-packages/mytoyota/client.py", line 55, in __init__
    raise ToyotaLocaleNotValid(
mytoyota.exceptions.ToyotaLocaleNotValid: Please provide a valid locale string! Valid format is: en-gb.

@DurgNomis-drol
Copy link
Owner

It is really strange that the check works when run manually, but when the same function is run in side the module it fails. 🤔
Something is different about your HA install, have you modified it in anyway? What other custom integrations do you have installed?

I am really at a lose of what to do to mitigate this problem. Can you double check that you are running the latest version of this integration?

@saintfrater
Copy link
Author

Hello,

sorry for the delay; I've run the script :

# python3 test.py
Traceback (most recent call last):
  File "test.py", line 12, in <module>
    client = MyT(username=username, password=password, locale=locale, region="europe")
  File "/srv/homeassist/lib/python3.8/site-packages/mytoyota/client.py", line 55, in __init__
    raise ToyotaLocaleNotValid(
mytoyota.exceptions.ToyotaLocaleNotValid: Please provide a valid locale string! Valid format is: en-gb.

So same error... I've checked my version and upgraded my OS and instances:

System Health

version core-2021.11.1
installation_type Home Assistant Core
dev false
hassio false
docker false
user homeassist
virtualenv true
python_version 3.8.11
os_name Linux
os_version 5.10.0-9-amd64
arch x86_64
timezone Europe/Brussels
Home Assistant Community Store
GitHub API ok
Github API Calls Remaining 4982
Installed Version 1.16.0
Stage running
Available Repositories 887
Installed Repositories 3
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Lovelace
dashboards 5
resources 3
views 9
mode storage

@DurgNomis-drol
Copy link
Owner

What other custom integrations do you guys have installed?

@savvasha
Copy link

savvasha commented Nov 7, 2021

Screenshot_20211107-180616_Home Assistant.jpg
Screenshot_20211107-180626_Home Assistant.jpg
Screenshot_20211107-180730_Home Assistant.jpg

Thats everything

@saintfrater
Copy link
Author

I've

  • HACS
  • Toyota Connected Services
  • Philips Hue Bridge
  • Verisure

@kapanikos
Copy link

kapanikos commented Nov 12, 2021

Hi there!

Looks like I have the same issue here.
I run home assistant on a raspberry pi 4b, used the toyota integration for some weeks now and everything went quite well.
Until today after I updated to core-2021.11.3 all of a sudden the integreation won't start anymore.

The log says:

Logger: homeassistant.config_entries
Source: custom_components/toyota/__init__.py:62
Integration: Toyota Connected Services (documentation, issues)
First occurred: 15:05:21 (1 occurrences)
Last logged: 15:05:21

Error setting up entry someone@somewhere.com for toyota
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 304, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/config/custom_components/toyota/__init__.py", line 62, in async_setup_entry
    client = MyT(
  File "/usr/local/lib/python3.9/site-packages/mytoyota/client.py", line 55, in __init__
    raise ToyotaLocaleNotValid(
mytoyota.exceptions.ToyotaLocaleNotValid: Please provide a valid locale string! Valid format is: en-gb.

I already tried the scripts above, with a similar outcome as savvasha. Although the script returned less sensors in my case, but that is a limitation of my Corolla I guess ;-)

The script that is checking the locale returns: True

My installed langcode has version 3.3.0
mytoyota is version 0.7.3

If you are also interested in timezones and regions ... My Pi and I are located in Germany ;-)

And I already ran dos2unix over the files, because every line ended with ^M
But as expected, that didn't help. Just for the good feeling :-)

@DurgNomis-drol
Copy link
Owner

Does the integration work if you use an older version of it?

Some changes have been made to langcodes in the last month or so, though they have not been released yet (3.3.0). I may need to rewrite the function that couses this issue, though it is difficult because I cannot recreate it so I can test it.

@kapanikos
Copy link

Well ... I'm not sure, if what I'm doing happens system wide.
I installed langcodes yesterday. Meanwhile I rebooted the host and today langcodes is gone.
pip list does not list langcodes anymore.

Of course there's no problem, to install langcodes 3.2.1 or an older version, but that doesn't change anything for the toyota integration. Still the same error.

Do I have to install the langcodes in a "special" way to make it persistant and system wide? I don't use pip that much.

@DurgNomis-drol
Copy link
Owner

I meant try to install an older version of this integration, not langcodes.

When i have time I will rewrite the check function in mytoyota to not use langcodes and eliminate this problem

@DurgNomis-drol
Copy link
Owner

DurgNomis-drol commented Nov 14, 2021

Can someone please try to install the latest master and test if it fixes you problem. I disabled the check for now until i can create a better validation function. Hope this fixes you problems 😃

@savvasha
Copy link

Hi @DurgNomis-drol !

It is working perfectly!!

Thank you very much :)

@DurgNomis-drol
Copy link
Owner

Great to hear, I will publish a new release (1.2.4) 😃

@DurgNomis-drol
Copy link
Owner

Everybody please update to the latest version (1.2.4)

https://github.com/DurgNomis-drol/ha_toyota/releases/tag/v1.2.4

@renewoensdregt
Copy link
Contributor

Thanks!! Working like a charm again!

@kapanikos
Copy link

Works again for me too, thanks for your effort! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants