Python plugins: Issue with device creation in beta 3.8035

Python and python framework

Moderator: leecollings

Post Reply
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Python plugins: Issue with device creation in beta 3.8035

Post by Logread »

I upgraded my development system (and unfortunately one of my production systems without a good backup) to beta 3.8035 and found out a weird issue with Device.Create... The method works fine with the first 2 calls (when creating the first two devices), and then any subsequent device creation fails with the following errors in the log:

Code: Select all

2017-07-04 15:15:35.708 Error: CPlugin:CDevice_init, unable to find module for current interpreter.
2017-07-04 15:15:35.708 Error: Device creation failed, Device object is not associated with a plugin.
The devices that fail to be created are all of type "Custom" if that can help (I have not tried with other types yet to see if it fails as well)

This affects all the different python plugins that I wrote, and that were running fine on 3.8000 (the latest one I had worked with before upgrading).

Hoping that one of the python plugins framework developers can help ?
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Python plugins: Issue with device creation in beta 3.8035

Post by Logread »

Responding to myself since I think I have found what became "wrong" coding with beta 3.8035:

the plugins where I see the issue have in common the fact that some devices are created and immediately updated in the same "onHeartbeat" callback... Seems with the version 3.8035 of domoticz only one device can be created and updated within the same call to "onHeartbeat"... If I change the code so that on the first heartbeat the devices that need to be created are and that then on the second and subsequent heartbeats these devices are updated (AND ONLY THEN)...

So this code that used to work:

Code: Select all

            # display the data
            for pollutant in self.pollutants:
                Domoticz.Debug(
                    "Pollutant: {} = {} (max = {})".format(pollutant.name, pollutant.level, pollutant.levelmax))
                if pollutant.level:
                    # if device does not yet exist, then create it
                    if not (pollutant.index in Devices):
                        Domoticz.Device(Name=pollutant.name, Unit=pollutant.index, TypeName="Custom",
                                        Options={"Custom": "1;{}".format(pollutant.unit)}, Used=pollutant.used).Create()
                    # update the device
                    self.UpdateDevice(pollutant.index, pollutant.level, pollutant.green, pollutant.red)
needs to be replaced by this one:

Code: Select all

            # display the data
            device_created = False
            for pollutant in self.pollutants:
                Domoticz.Debug(
                    "Pollutant: {} = {} (max = {})".format(pollutant.name, pollutant.level, pollutant.levelmax))
                if pollutant.level:
                    # if device does not yet exist, then create it
                    if not (pollutant.index in Devices):
                        Domoticz.Device(Name=pollutant.name, Unit=pollutant.index, TypeName="Custom",
                                        Options={"Custom": "1;{}".format(pollutant.unit)}, Used=pollutant.used).Create()
                        device_created = True
                    else:
                        # update the device
                        self.UpdateDevice(pollutant.index, pollutant.level, pollutant.green, pollutant.red)
            if device_created:
                self.lastupdate = now
                # force an update on the next heartbeat rather than on the usual polling interval
Pretty strange behaviour... Would be good to revert to previous one if possible. In the meantime I'll rewrite my plugins to address this
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest