check if device creation was succesful

Python and python framework

Moderator: leecollings

Post Reply
akamming
Posts: 394
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

check if device creation was succesful

Post 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
pipiche
Posts: 2016
Joined: Monday 02 April 2018 20:33
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: France
Contact:

Re: check if device creation was succesful

Post by pipiche »

If it fails I think the unit returned is -1, no ?


Envoyé de mon iPhone en utilisant Tapatalk
Zigbee for Domoticz plugin / RPI3B+ / Electrolama ZZH-P / 45 devices

If the plugin provides you value, you can support me with a donation Paypal.

Wiki is available here.

Zigbee for Domoticz FAQ
Barberousse
Posts: 140
Joined: Wednesday 02 December 2015 21:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: check if device creation was succesful

Post 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")
akamming
Posts: 394
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: check if device creation was succesful

Post 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
lost
Posts: 667
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: check if device creation was succesful

Post 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! :)
User avatar
waltervl
Posts: 5983
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: check if device creation was succesful

Post 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...
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest