Page 1 of 1
check if device creation was succesful
Posted: Saturday 29 June 2024 7:24
by akamming
Hi,
In the extended plugin framework there is a create function for devices, like
DomoticzEx.Unit(Name="Kilo Watts", DeviceID="Power", Unit=16, TypeName="kWh").Create()
This function however will fail if "accept new devices" is set to false in the domoticz settings. So how can check in the code if this function succeeded?
I'm looking for something like:
Code: Select all
result=DomoticzEx.Unit(Name="Kilo Watts", DeviceID="Power", Unit=16, TypeName="kWh").Create()
if result=true:
#Handle code after device was created
else:
#handle code for a not created device
Re: check if device creation was succesful
Posted: Saturday 29 June 2024 9:32
by pipiche
If it fails I think the unit returned is -1, no ?
Envoyé de mon iPhone en utilisant Tapatalk
Re: check if device creation was succesful
Posted: Monday 01 July 2024 19:54
by Barberousse
akamming wrote: ↑Saturday 29 June 2024 7:24
DomoticzEx.Unit(Name="Kilo Watts", DeviceID="Power", Unit=16, TypeName="kWh").Create()
I would check if device is in Devices:
Code: Select all
if ("Power" in Devices) and (16 in Devices["Power"].Units):
...
else:
Domoticz.Error("Device creation failed")
Re: check if device creation was succesful
Posted: Tuesday 02 July 2024 9:12
by akamming
Barberousse wrote: ↑Monday 01 July 2024 19:54
akamming wrote: ↑Saturday 29 June 2024 7:24
DomoticzEx.Unit(Name="Kilo Watts", DeviceID="Power", Unit=16, TypeName="kWh").Create()
I would check if device is in Devices:
Code: Select all
if ("Power" in Devices) and (16 in Devices["Power"].Units):
...
else:
Domoticz.Error("Device creation failed")
this is how i currently do it, but it seems a lot of code. If it fails domoticz logs it, so would be nice in the code you could also directly get the error why it failed instead of just finding out it still does not exist
Re: check if device creation was succesful
Posted: Tuesday 02 July 2024 14:06
by lost
Isn't there a way to allow new devices for plugin code, especially when some pairing mode is active, to basically avoid the issue of the user just forgetting to do it manually before pairing as this will for sure be needed in such case?
So no such error to handle = no more problem!

Re: check if device creation was succesful
Posted: Tuesday 02 July 2024 23:03
by waltervl
pipiche wrote: ↑Saturday 29 June 2024 9:32
If it fails I think the unit returned is -1, no?
Akamming, did you check this? As the remark is from a very experienced plugin developer...