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 ?
How do I know status of Create
Moderator: leecollings
-
mvzut
- Posts: 443
- Joined: Thursday 12 November 2015 10:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: The Netherlands
- Contact:
Re: How do I know status of Create
This is how I did it in my plugin (ELV/e-Q3 MAX! plugin):
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
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?")
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
Raspberry Pi 4 - RFXtrx433 - CC2531 Zigbee - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - 6 x Sonos - 4 x IP cameras - Wall mounted tablet + Dashticz - Google Home integration - MANY switches/sensors
Re: How do I know status of Create
@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-
mvzut
- Posts: 443
- Joined: Thursday 12 November 2015 10:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: The Netherlands
- Contact:
Re: How do I know status of Create
Interesting, didn't know the device ID has a value of -1 if the device doesn't exist.
Raspberry Pi 4 - RFXtrx433 - CC2531 Zigbee - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - 6 x Sonos - 4 x IP cameras - Wall mounted tablet + Dashticz - Google Home integration - MANY switches/sensors
Re: How do I know status of Create
Does some of you have a mean to get the information if Domoticz 'Accept New hardware' is enable or not ?