Page 1 of 1

How to create/read/update devices using DeviceID instead of Units

Posted: Wednesday 05 July 2017 10:30
by marco.bag
Dear All,
I'm creating a new plugin for Domoticz, the issue is that i cannot use the [Unit] as index since it's just a number from 0 to 256.

In my script i've to create devices and update it using as index the MAC address or part of it, since creating an external file to match the Unit number with the MAC address looks to me not optimal.

It's possible to create/read/update a device from the python plugin system using the DeviceID instead of the unit number?
If yes, it's possible to have a small example?

Thank you so much

Re: How to create/read/update devices using DeviceID instead of Units

Posted: Saturday 08 July 2017 1:46
by Dnpwwo
@marco.bag,

You can't but I don't think you need to. If you want a dictionary of devices indexed by DeviceID rather than Unit number then just create one in the onStart callback (and after you create or delete one).

Something like this might do it:

Code: Select all

    DeviceIDdict = {}
    for x in Devices:
       DeviceIDdict[Devices[x].DeviceID] = Devices[x]
I'm pretty sure that will do a shallow copy so any updates to the devices will be visible in both dictionaries over the lifetime of the plugin.