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

Python and python framework

Moderator: leecollings

Post Reply
marco.bag
Posts: 14
Joined: Tuesday 16 December 2014 0:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

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

Post 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.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest