Page 1 of 1

Python framework breaking change - advance warning

Posted: Monday 15 May 2017 6:06
by Dnpwwo
In a week or so I plan to create a pull request to the beta channel that, when merged, will change the callback APIs in the Python plugin framework. This change will add a parameter to following callbacks:
  • onConnect
  • onMessage
  • onDisconnect
and will break any current plugins that handle these events. Additionally, several Domoticz library functions will be removed. These are:
  • Transport
  • Protocol
  • Connect
  • Send
  • Disconnect
This functionality will continue to be made available to plugins via a new Connection object.

Recommended action:
  • If you are the author of a plugin that does not use the built in connectivity features of the plugin framework you should remove any references to these callbacks completely and publish an updated version. Domoticz will gracefully handle missing callbacks by ignoring them so this can be done at any time
  • If you are the author of a plugin that does use the native connectivity you should review the changes documented on the wiki (http://www.domoticz.com/wiki/Developing ... #Callbacks) and the new Connection object (http://www.domoticz.com/wiki/Developing ... onnections). I will continue to update this over the next few days.
This change is being made to allow a plugin to have multiple, simultaneous connections to enable them to:
  • connect to multiple external devices
  • simultaneous normal and network discovery operations
  • accept incoming connections
Switching from the current connection handling to the new model is very straightforward, I will provide examples.

Apologies in advance for any inconvenience caused.

Re: Python framework breaking change - advance warning

Posted: Monday 15 May 2017 9:43
by jorgh
@dnwwwo,

Quick question, will the UDP transport be able to send network broadcasts? If so, it could be used to auto-discover devices on the network. In the Onkyo plugin I've now implemented it using the Python raw TCP/IP api's. But using the framework would be a nicer implementation of course.

Regards,

Jorg

Re: Python framework breaking change - advance warning

Posted: Tuesday 16 May 2017 5:59
by Dnpwwo
@jorgh,

Yes. Device discovery would certainly make life easier for less technical users .

I'm focusing on changing the API first (done), adding 'Listen' functionality second (in progress) and UDP/IP third so it might take a little while. My target test case is to be able to send and receive SNMP messages which requires both broadcast and multiple connections.

Re: Python framework breaking change - advance warning

Posted: Tuesday 23 May 2017 10:08
by Logread
@dnwwwo,

Would it be possible to add a "Name" attribute (optional) to the new Connection object so that the onConnect and onMessage callbacks can more easily identify the nature of the incoming connection (I am working on a plugin that rely on multiple instances of a connection with the same transport and protocol but will adjust the parameters of the Send method for each specific instance of Connection) ?

Re: Python framework breaking change - advance warning

Posted: Wednesday 24 May 2017 11:36
by Dnpwwo
@Logread,

Sure, I added one although from a Python perspective I am not sure it is required.

If you create a Connection, and keep a reference to it in your code, you can just compare that to the Connection supplied to onMessage. Like:

Code: Select all

class BasePlugin:
    myConn = None

    def onStart(self):
        Domoticz.Connection(Name="Test Connection", Transport="TCP/IP", Protocol="Line", Port="9090").Connect()
        
    def onConnect(self, Connection, Status, Description):
        Domoticz.Log("Connected successfully to: "+Connection.Address+":"+Connection.Port)
        self.myConn = Connection

    def onMessage(self, Connection, Status, Description):
        Domoticz.Log("Message from: "+Connection.Address+":"+Connection.Port)
        if (Connection == self.myConn):
            Domoticz.Log("This is the Connection I created earlier !!")
for Connection objects created by listening sockets I will default the name to something unique like "Address:Port"

Re: Python framework breaking change - advance warning

Posted: Wednesday 24 May 2017 13:33
by Logread
Dnpwwo wrote:@Logread,

Sure, I added one although from a Python perspective I am not sure it is required.
Many thanks. I understand that it is possible to do without this, but it is easier for me :D

Re: Python framework breaking change - advance warning

Posted: Thursday 01 June 2017 7:46
by elgringo
Since some plugins do not work anymore I assume the is integrated? If so can you confirm it form whuch version this has been done? ;)

Second the wike (https://www.domoticz.com/wiki/Developin ... hon_plugin), i miss some information (and I hope you can add it)
  • Parameter described of the callbacks. What is stored in with parameter
  • When receivng messages it it possible they are split in muliple callbacks?
  • Protocol 'None' can this be used for a binairy connection? I have several binary protocol plugins (solar inverter, LED controllers) I current read the raw bytes and interpret them
When you can an example finished (SNMP) can you post this here or on the wiki? Thanks alot!