Page 1 of 1

Unit deletion failed, UnitEx object is not associated with a plugin

Posted: Thursday 28 April 2022 13:22
by heggink
@dnpwwo: whilst trying to develop a new plugin I get the above error. Here are the 2 code snippets for creating and deleting:

I create 2 devices as follows:

Code: Select all

        if dev_id not in Devices:
                mySwitchUnit = Domoticz.Unit(Name=dev_id, DeviceID=dev_id, Unit=1, Type=244, Subtype=73, Switchtype=0, Options={}, Used=1, Description="")
                mySwitchUnit.Create()
                myTextUnit = Domoticz.Unit(Name=dev_id, DeviceID=dev_id, Unit=2, TypeName="General", Subtype=19, Options={}, Used=1, Description="")
                myTextUnit.Create()
Then if anyone of teh 2 gets deleted through teh domotcz interface, I want to delete the otherone myself:

Code: Select all

        def onDeviceRemoved(self, DeviceID, Unit):
                Domoticz.Log("Device onDeviceRemoved for DeviceID: " +str(DeviceID)+" and Unit: "+str(Unit))
                if Unit == 1:
                        Domoticz.Log("Device onDeviceRemoved unit 1 so delete 2")
                        Devices[DeviceID].Units[2].Delete()
                else:
                        Domoticz.Log("Device onDeviceRemoved unit 1 so delete 1")
                        Devices[DeviceID].Units[1].Delete()
What am I doing wrong?

Re: Unit deletion failed, UnitEx object is not associated with a plugin

Posted: Friday 29 April 2022 8:28
by Dnpwwo
@heggink,

Nothing, I reproduced your code and it didn't work for me either.

I've pushed a fix.

Re: Unit deletion failed, UnitEx object is not associated with a plugin

Posted: Friday 29 April 2022 8:42
by heggink
Excellent. Thanks.

Sent from my SM-G980F using Tapatalk


Re: Unit deletion failed, UnitEx object is not associated with a plugin

Posted: Friday 29 April 2022 9:07
by JanJaap
Hi,

It is not only the deletion that doesn't work, any referencing of units in this way (or calling methods) doesn't work. Is all that fixed? Which version will it be pushed into?

see also: topic Deleting units in DomoticzEx framework

Re: Unit deletion failed, UnitEx object is not associated with a plugin

Posted: Friday 29 April 2022 10:18
by Dnpwwo
@JanJaap,

I have responded in the other thread, but for clarity: The dictionary containing a device's units is 'Units' not 'Unit'.

That is why Domoticz is correctly reporting:

Code: Select all

2022-04-24 16:26:25.867 Error: testplug: AttributeError: 'DomoticzEx.Device' object has no attribute 'Unit'