majki09 / domoticz_lg_thinq_plugin

Domoticz plugin for LG ThinQ devices.
MIT License
21 stars 7 forks source link

Check if is possible to have the `wideq_state.json` file inside the `userdata` folder #6

Closed majki09 closed 2 years ago

majki09 commented 2 years ago

Isn't it possible to have the wideq_state.json file inside the userdata folder? That would be much better for the docker setup, because userdata is a docker volume and thus accessible.

_Originally posted by @kipusoep in https://github.com/majki09/domoticz_lg_thinq_plugin/issues/5#issuecomment-1011953936_

majki09 commented 2 years ago

Hi @kipusoep! What userdata actually you mean? Domoticz plugin's configuration data should be stored in Configuration fields. Configuration allows the plugin store structured data in the database rather than writing files or creating Domoticz variables to hold it.

I'm about to move all wideq_state.json fields to Configuration, so all config from wideq_state.json file will be saved into domoticz database.

Will this be OK for you?

kipusoep commented 2 years ago

I guess the userdata folder is docker specific. From https://registry.hub.docker.com/r/domoticz/domoticz :

volumes:
  - ./config:/opt/domoticz/userdata

So this userdata folder is a subfolder of the domoticz root folder. That's where the database etc. is stored. Here's an example from a fresh instance:

-rw-r--r-- 1 root root    4096 Jan 18 09:40 domoticz.db
-rw-r--r-- 1 root root   32768 Jan 18 09:40 domoticz.db-shm
-rw-r--r-- 1 root root 1112432 Jan 18 09:40 domoticz.db-wal
drwxr-xr-x 2 root root    4096 Jan 18 09:40 plugins

This is currently in my instance:

drwxr-xr-x 105 root root     4096 Aug 17 16:00 Config
-rwxr-xr-x   1 root root    97954 Apr 26  2020 History.txt
-rwxr-xr-x   1 root root    35147 Apr  2  2020 License.txt
drwxr-xr-x   5 root root     4096 Aug 17 15:59 backups
-rwxr-xr-x   1 root root      477 Jan 18 09:42 domocookie.txt
-rwxr-xr-x   1 root root 13861696 Apr 26  2020 domoticz
-rw-r--r--   1 root root  3260416 Jan 18 09:40 domoticz.db
-rw-r--r--   1 root root    32768 Jan 18 09:42 domoticz.db-shm
-rw-r--r--   1 root root  4144752 Jan 18 09:42 domoticz.db-wal
-rwxr-xr-x   1 root root     4433 Apr  2  2020 domoticz.sh
drwxr-xr-x   4 root root     4096 Aug 17 16:00 dzVents
drwxr-xr-x   5 root root     4096 Jan 13 10:28 plugins
drwxr-xr-x   8 root root     4096 Aug 17 16:00 scripts
-rwxr-xr-x   1 root root     3414 Apr  2  2020 server_cert.pem
-rwxr-xr-x   1 root root      610 Apr  2  2020 updatebeta
-rwxr-xr-x   1 root root      627 Apr  2  2020 updaterelease
-rw-r--r--   1 root root      540 Jan 12 17:11 wideq_state.json
drwxr-xr-x  13 root root     4096 Aug 17 16:01 www

There's probably stuff that shouldn't even be there, but the thing is I don't know which items ;-)

Anyway, storing it in the database is the best solution ofcourse, because it's one of the things that's inside the volume :-)

majki09 commented 2 years ago

Ah OK, now it's more than clear 👍 Thanks! So yeah, hopefully I will get this to have all that wideq_state.json stuff inside domoticz.db. I think that should make this plugin fully "dockerable".

majki09 commented 2 years ago

OK, I have made some changes, but I need you to check if it actually works for you. Just git pull --rebase to have https://github.com/majki09/domoticz_lg_thinq_plugin/commit/28c62b6c30fb99afb19d8ed4589f77c2013e00bd If it's OK then I will close this issue.

kipusoep commented 2 years ago

I'll give it a go next week!

kipusoep commented 2 years ago

As you may have noticed, I wasn't able yet to try this. I hope I can do it this week.

majki09 commented 2 years ago

Hi @kipusoep! No problem, take your time 😄

kipusoep commented 2 years ago

Darn this has taken far too long. I'm going to try again to focus on this somewhere in the next 2 weeks.

kipusoep commented 2 years ago

So I finally been able to test it. The persistence seems to work according to the logs:

2022-05-10 21:09:36.898 Status: Airco 1e verdieping: Initialized version 1.2.2, author 'majki'
2022-05-10 21:09:36.925 Status: Airco Zolder: Initialized version 1.2.2, author 'majki'
2022-05-10 21:09:37.259 Airco Zolder: LG API2 (gateway) config saved do Domoticz Configuration.
2022-05-10 21:09:37.260 Airco Zolder: LG API2 (auth) config saved do Domoticz Configuration.
2022-05-10 21:09:37.260 Airco Zolder: Getting AC status successful.
2022-05-10 21:09:37.663 Airco 1e verdieping: LG API2 (gateway) config saved do Domoticz Configuration.
2022-05-10 21:09:37.664 Airco 1e verdieping: LG API2 (auth) config saved do Domoticz Configuration.
2022-05-10 21:09:37.665 Airco 1e verdieping: Getting AC status successful.

But when I remove the wideq_state.json file and restart domoticz, I get errors:

2022-05-10 21:10:14.576 Error: Airco 1e verdieping: Call to function 'onStart' failed, exception details:
2022-05-10 21:10:14.583 Error: Airco Zolder: Call to function 'onStart' failed, exception details:
2022-05-10 21:10:14.587 Error: Airco 1e verdieping: Traceback (most recent call last):
2022-05-10 21:10:14.588 Error: Airco 1e verdieping: File "/opt/domoticz/userdata/plugins/domoticz_lg_thinq_plugin/plugin.py", line 565, in onStart
2022-05-10 21:10:14.588 Error: Airco 1e verdieping: _plugin.onStart()
2022-05-10 21:10:14.588 Error: Airco 1e verdieping: File "/opt/domoticz/userdata/plugins/domoticz_lg_thinq_plugin/plugin.py", line 96, in onStart
2022-05-10 21:10:14.588 Error: Airco 1e verdieping: state=self.state)
2022-05-10 21:10:14.588 Error: Airco 1e verdieping: File "/opt/domoticz/userdata/plugins/domoticz_lg_thinq_plugin/example.py", line 298, in example
2022-05-10 21:10:14.588 Error: Airco 1e verdieping: client._auth = authenticate(client.gateway)
2022-05-10 21:10:14.588 Error: Airco 1e verdieping: File "/opt/domoticz/userdata/plugins/domoticz_lg_thinq_plugin/example.py", line 25, in authenticate
2022-05-10 21:10:14.588 Error: Airco 1e verdieping: callback_url = input()
2022-05-10 21:10:14.588 Error: Airco 1e verdieping: EOFError: EOF when reading a line
2022-05-10 21:10:14.590 Error: Airco Zolder: Traceback (most recent call last):
2022-05-10 21:10:14.590 Error: Airco Zolder: File "/opt/domoticz/userdata/plugins/domoticz_lg_thinq_plugin/plugin.py", line 565, in onStart
2022-05-10 21:10:14.590 Error: Airco Zolder: _plugin.onStart()
2022-05-10 21:10:14.590 Error: Airco Zolder: File "/opt/domoticz/userdata/plugins/domoticz_lg_thinq_plugin/plugin.py", line 96, in onStart
2022-05-10 21:10:14.590 Error: Airco Zolder: state=self.state)
2022-05-10 21:10:14.590 Error: Airco Zolder: File "/opt/domoticz/userdata/plugins/domoticz_lg_thinq_plugin/example.py", line 298, in example
2022-05-10 21:10:14.590 Error: Airco Zolder: client._auth = authenticate(client.gateway)
2022-05-10 21:10:14.591 Error: Airco Zolder: File "/opt/domoticz/userdata/plugins/domoticz_lg_thinq_plugin/example.py", line 25, in authenticate
2022-05-10 21:10:14.591 Error: Airco Zolder: callback_url = input()
2022-05-10 21:10:14.591 Error: Airco Zolder: EOFError: EOF when reading a line
kipusoep commented 2 years ago

Right, I found out reading config from database has been disabled here, why? Seems to work fine if I checkout 28c62b6c30fb99afb19d8ed4589f77c2013e00bd specifically.

majki09 commented 2 years ago

Hey @kipusoep! I finally had some time to touch this - sorry for waiting. With latest commit 392f5c1550d68c7887fa2d94bf5df958592714f9 there is no need to move wideq_state.json file anywhere - location is auto-detected now and it's working both for docker and non-docker domoticz instances. Pleas give it a try and let me know, maybe we will finally have a chance to close this issue 😃

kipusoep commented 2 years ago

I pulled and restarted the container, seems to work fine! Thanks :-D