yo-han / Home-Assistant-Carelink

Unofficial Home Assistant Carelink Component
MIT License
24 stars 12 forks source link

Issue when adding integration with new auth process #74

Closed bvdkerkhof closed 7 months ago

bvdkerkhof commented 8 months ago

I was able to run the auth script and got a logindata.json file on my Windows machine. On my Raspberry Pi i added the logindata.json file to the custom_components/carelink/ folder.

When adding the integration again it gives me an unknown error. When checking the log files it gives me the following output:

2024-03-06 11:54:04.671 ERROR (MainThread) [custom_components.carelink.config_flow] Unexpected exception
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/carelink/config_flow.py", line 81, in async_step_user
    info = await validate_input(self.hass, user_input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/carelink/config_flow.py", line 49, in validate_input
    if not await client.login():
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/carelink/api.py", line 443, in login
    await self.__execute_init_procedure()
  File "/home/homeassistant/.homeassistant/custom_components/carelink/api.py", line 298, in __execute_init_procedure
    self.__tokenData = await self._process_token_file(CON_CONTEXT_AUTH)

  File "/home/homeassistant/.homeassistant/custom_components/carelink/api.py", line 443, in login
    await self.__execute_init_procedure()
  File "/home/homeassistant/.homeassistant/custom_components/carelink/api.py", line 298, in __execute_init_procedure
    self.__tokenData = await self._process_token_file(CON_CONTEXT_AUTH)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/carelink/api.py", line 434, in _process_token_file
    await self._write_token_file(token_data, filename)
  File "/home/homeassistant/.homeassistant/custom_components/carelink/api.py", line 404, in _write_token_file
    with open(filename, 'w') as f:
         ^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'custom_components/carelink/logindata.json

`

Running HA 2024.2.3 Raspbery Pi with Python 3.12.2 Core installation

sedy89 commented 8 months ago

Could you try to modify CON_CONTEXT_AUTH in api.py and put '.homeassistant/' in front of the existing path?

bvdkerkhof commented 8 months ago

Thanks for the info, i added the .homeassistant/ in front of the path withouth a reboot of HA and that didnt work. As i also upgraded some other packages i did a reboot and modified the path to the full system path /home/homeassistant/.homeassistant/custom_components/carelink/logindata.json and that did the trick.

sedy89 commented 8 months ago

Every change in the code requires a reboot. I missed to say that, but I am glad that it is finally working for you. I will try to make this path less static.

hhuitema commented 8 months ago

From a fresh install i cannot get it to work. Getting the same initial error as in the opening post. i tried adjusting to the paths mentioned above, but the error remains. And since the installer does not complete i do not see the integration appearing.

Maybe a sidenote, but i do get any of the country selectors while making the session details, nor do i get the opportunity to add patient information. (unless i copy paste all information in the config screen by hand) since previous all this data was mandatory, is this information now fetched on the background?

Slight addon comment, when leaving the config completely empty (as suggested) i get a functional error back, 'wrong username / password'. Essentially leaving the install process broken at this stage.

sedy89 commented 8 months ago

Yes, the data is fetched in the background. You can specify a patient, but if you follow only one patient, it would be unnecessary. If you provide the file in the carelink folder and you don't use the nightscout uploader, it should be fine to leave the integration mask empty.

Regarding the issue during setup, you can go to settings in HA and check the overall protocol. Please paste it here if you see the Carlink integration error.

hhuitema commented 8 months ago

Thanks for your quick updates... :-)

So my current state is that i have a logindata.json. This is uploaded to HomeAssistant in the correct folder. the integration itself is not yet active, so i install it through HACS. if i cancel setup, the integration remains dorment, if i say yes to the config i cannot finalize it by leaving all empty (error, wrong user/password) if i enter manually all data, then i get an internal error. If i cancel the setup the integration remains dorment again.

How can i get passed this install cycle?

sedy89 commented 8 months ago

Once you install the latest version (again) from HACS, it will clean the folder again. If you had copied the login file before, it will be gone l.

You should download the integration again via HACS, copy the file into the integration folder and reboot.

If you do those steps in the correct ordering, you should be able to add the integration without filling the data manually.

If it still throws an error, you should be able to see the issue in the HA error log in the setting

hhuitema commented 8 months ago

Got it to work now... :-)

Biggest difference compared to how i installed before: do not use the 'add this integration to HA'. but instead use the download button on the context menu in HACS. That will create the folder, just add the login.json. Reboot HomeAsstant.

Then as a last step you still need to add the integration. just click on add-integration button in the integrations, find carelink and click next. and finished.

github-actions[bot] commented 7 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 7 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.