Python framework breaking change - advance warning

Python and python framework

Moderator: leecollings

Post Reply
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Python framework breaking change - advance warning

Post 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.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
User avatar
jorgh
Posts: 124
Joined: Friday 27 June 2014 23:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8224
Location: Netherlands
Contact:

Re: Python framework breaking change - advance warning

Post 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
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python framework breaking change - advance warning

Post 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.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Python framework breaking change - advance warning

Post 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) ?
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python framework breaking change - advance warning

Post 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"
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Python framework breaking change - advance warning

Post 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
elgringo
Posts: 96
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Left
Contact:

Re: Python framework breaking change - advance warning

Post 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!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest