How do I know status of Create

Python and python framework
Post Reply
pipiche
Posts: 156
Joined: Monday 02 April 2018 20:33
Target OS: Raspberry Pi
Domoticz version: beta
Location: France
Contact:

How do I know status of Create

Post by pipiche » Thursday 29 November 2018 10:20

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 ?

mvzut
Posts: 448
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: How do I know status of Create

Post by mvzut » Monday 03 December 2018 11:26

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 ;-)
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - Alexa - MANY switches/sensors

pipiche
Posts: 156
Joined: Monday 02 April 2018 20:33
Target OS: Raspberry Pi
Domoticz version: beta
Location: France
Contact:

Re: How do I know status of Create

Post by pipiche » Monday 03 December 2018 12:04

@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: 448
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: How do I know status of Create

Post by mvzut » Monday 03 December 2018 12:09

Interesting, didn't know the device ID has a value of -1 if the device doesn't exist.
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - Alexa - MANY switches/sensors

pipiche
Posts: 156
Joined: Monday 02 April 2018 20:33
Target OS: Raspberry Pi
Domoticz version: beta
Location: France
Contact:

Re: How do I know status of Create

Post by pipiche » Monday 10 December 2018 12:32

Does some of you have a mean to get the information if Domoticz 'Accept New hardware' is enable or not ?

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests