Page 1 of 1

How do I know status of Create

Posted: Thursday 29 November 2018 9:20
by pipiche
How do I get the status of a Create ?

For instance if I do Domoticz.Device(xxxxx, xxxx .... ).Create()

How can I know that if have succeed or not ?

Re: How do I know status of Create

Posted: Monday 03 December 2018 10:26
by mvzut
This is how I did it in my plugin (ELV/e-Q3 MAX! plugin):

Code: Select all

old_device_count = len(Devices)
# Create device
Domoticz.Device(Name=name + " - " + typename, Unit=availableID, DeviceID=deviceid, Type=devicetype, Subtype=subtype, Switchtype=switchtype, Options=options, Image = image, Used=1).Create()
if len(Devices) != old_device_count:
    # Device created
    Domoticz.Log("Created device '" + Parameters["Name"] + " - " + name + " - " + typename + "'")
else:
    # Device not created!
    Domoticz.Error("Device '" + Parameters["Name"] + " - " + name + " - " + typename + "' could not be created. Is 'Accept new Hardware Devices' enabled under Settings?")
No idea if this is the only or the most effective way, but it works.

By the way, I wish there was a way to enable device creation from the plugin itself, it is not very user friendly in my opinion that people have to manually set this before they install a plugin. If you explicitly choose to install a plugin, this implicitly means (in my opinion) that you want it to create devices, obviously... But that's just my opinion ;-)

Re: How do I know status of Create

Posted: Monday 03 December 2018 11:04
by pipiche
@mvzut, thanks for your response. In the mean time I found an otherway

Code: Select all

t = "Temp+Hum+Baro"  # Detecteur temp + Hum + Baro
unit = FreeUnit(self, Devices)
Domoticz.Debug("CreateDomoDevice - unit: %s" %unit)
myDev = Domoticz.Device(DeviceID=str(DeviceID_IEEE), Name=str(t) + "-" + str(DeviceID_IEEE) + "-" + str(Ep),
              Unit=unit, TypeName=t)
myDev.Create()
ID = myDev.ID
if myDev.ID == -1 :
    Domoticz.Error("Domoticz widget creation failed. %s" %(str(myDev)))
else:
    self.ListOfDevices[NWKID]['Ep'][Ep]['ClusterType'][str(ID)] = t

Re: How do I know status of Create

Posted: Monday 03 December 2018 11:09
by mvzut
Interesting, didn't know the device ID has a value of -1 if the device doesn't exist.

Re: How do I know status of Create

Posted: Monday 10 December 2018 11:32
by pipiche
Does some of you have a mean to get the information if Domoticz 'Accept New hardware' is enable or not ?