merdok / homebridge-webos-tv

Homebridge plugin for LG webOS TVs
MIT License
646 stars 88 forks source link

Issue when compute keyFile path? #530

Closed ivan-garcia-parras closed 2 months ago

ivan-garcia-parras commented 2 months ago

Hi,

I have detected that, every time I restart the PC where I have homebrige+homebridge-webos-tv installed, the TV asks me again for connection confirmation.

Reviewing in the source code how the path to "keyFile" is calculated, I see that there are possible inconsistencies: https://github.com/search?q=repo%3Amerdok%2Fhomebridge-webos-tv%20keyfile&type=code

In "WebosTvHelper.js" not depends of keyFile config: https://github.com/merdok/homebridge-webos-tv/blob/master/lib/tools/WebosTvHelper.js#L140

Is that so?

Greetings,

merdok commented 2 months ago

Yes, that is right WebosTvHelper.js does not depend on the homebridge keyFile config as it is used for the CLI tools. For that reason i cannot get the config directory from homebridge, hence those are stored in a separate location.

ivan-garcia-parras commented 2 months ago

thanks for your answer.

I am trying to save all the configuration generated by the plugin so that, using an sh script, I can install homebridge+webostv from scratch.

Could this be the reason that every time I restart the PC the TV asks me again for confirmation of the connection?

In what path does the webostvhelper.js file save the key? I see that it uses the env-paths library, but I can't find the file.

merdok commented 2 months ago

The final path depends on the OS which you are using, see details here https://www.npmjs.com/package/env-paths It might be that the directory it points to on your OS might be cleared after every restart of the PC and then the TV asks again for a confirmation.

ivan-garcia-parras commented 2 months ago

Thanks for the involvement.

I am using homebridge docker image (https://github.com/homebridge/docker-homebridge/pkgs/container/homebridge)

According to the env-paths documentation, being linux, the path should be: ~/.local/share/webostv-nodejs

It's right?

And I understand that the "mkdirSync" function (https://github.com/merdok/homebridge-webos-tv/blob/master/lib/tools/WebosTvHelper.js#L40) is not being able to create the directories due to lack of permissions.

If you confirm the path, I can try to modify my sh scripts, generating the directories of the path and copying the key file, complying with the format 'keyFile' + ip.split('.').join('') + '' + mac.split(':').join('') described on line 140 (https://github.com/merdok/homebridge-webos-tv/blob/master/lib/tools/WebosTvHelper.js#L140 )

merdok commented 2 months ago

I am not sure about the path in homebridge docker image, but it might indeed be correct. Yeah, if there are no permissions then the directory will not be created.

ivan-garcia-parras commented 2 months ago

I have already found the problem: I was recreating the keyfile and adding a \r\n at the end, generating a new line.

Now I generate the file both in the path defined in the homebridge configuration ("keyFile") and in the path "~/.local/share/webostv-nodejs"

And, for the second route, I have given permissions to the user "homebridge". And to the file. (I'm not sure if this is necessary but it works).

There is no problem in the source code.

Thanks for the help.

I close the issue.