remco-k / domoticz-goodwe-modbusudp-plugin

A Domoticz plugin that connects to GoodWe inverters over LAN or WLAN via UDP that supports Modbus.
4 stars 1 forks source link

Update plugin.py #10

Closed JannemanDev closed 2 months ago

JannemanDev commented 2 months ago

changed status code to a number (like error code and warning code) so you can use notifications, for example when the value is equal to 1 (=malfunction)

remco-k commented 2 months ago

Hi @JannemanDev, thank you for your work. I just pulled it into an intermediate branch pull-10-status-code-numeric and then after some tests, merged it to master.

One question though, I'm not that familiar with Domoticz on the level of changing a data type text in an existing system to something else, in this case a number. It doesn't do that by itself (obviously) so I just removed the device Status code (Unit 5) from my Domoticz installation, then restarted Domoticz and the plugin then re-creates the device with the new type. That worked fine.

I assume this is the (only) way to do this, in this case. Or is there more?

History (in my case >1 year) of that device (Status code) is now lost. In future cases I'd like to know how such data can be retained. Do you know a way?

My guess is that you just never can change a data type of a device, but you'll need to add a completely new device.

Or better yet: change the data type of an existing device and change its current unit number (5) to a new one that doesn't exist yet in the same plugin. In this case Domoticz will (I assumme) create a new Status code device with the new unit number. The old one (with the 5) will still exist in Domoticz, including its history. But will not be updated anymore by the plugin (that is to be expected). What do you think, would that be the way to do these kinds of future changes?

Regards, Remco

JannemanDev commented 2 months ago

easy just backup the database, open in db browser (sqlite db editor), edit the right value in the right column in the right table, write changes, restore using the updated database. This is how I did it. If you do this fast you wont lose much for example sensor data. Probably you can also just locate the in use database and point db browser to it directly, that way you wont lose any sensor data. I am on mobile right now. Will edit with more details later.

remco-k commented 1 month ago

Hi, changing the database manually would have worked for me. I'm more in te search for a future solution for a non-technical Domoticz user, the ones that don't know how to do these things manually. And the ones that don't know this needs to be done in the first place. (I assume there is a problem at this moment, if someone just updates to this current version 0.0.6 and does nothing else but updating it, then the Status code just stops working because of the mismatch in datatype)

That brings me back to my question: would changing the unit number for such a case like this prevent a user to do manual changes to the Domoticz database and config?

JannemanDev commented 1 month ago

You are absolutely right. We need a solution for the user that installs this new version without need for extra manually editing database step :) Maybe this is more a question for the Domoticz plugins community. I am not familiair with plugin development, but of course this is something thats already solved. We are the first one making updates to a plugin :) Here are some pointers after some googling and asking my friend Chad: https://chatgpt.com/c/c0987fb8-af2f-48de-9b10-7c2b8f8572dd Goto Methods>Update by scrolling down from here https://www.domoticz.com/wiki/Developing_a_Python_plugin#Units

So in your plugin run a migration script (SQL update .sql script) for the more advanced use cases, but I think 99% of the time you can just use the Domoticz Plugin framework/API (in combination with checking plugin version) that does the heavy SQL lifting for you.