DZVents: have devices() and groups(), etc. accept sets
Posted: Saturday 26 May 2018 14:58
I would like it very much if the following syntax could be made possible:
Currently domoticz.devices(<idx>) or domoticz.devices(<name>) returns a single device from the set of devices, and domoticz.devices() returns the complete set of devices. domoticz.devices( <set of device names>) or domoticz.devices( <set of idx values>) would return only those devices from domoticz.devices() that have a name or idx value specified in the set. This allows for much easier coding of set operations in combination with the iterator functions .foreach(), .filter(), .reduce(), etc..
Some additional rules to make the behavior unambigious:
- If an empty set is passed in (f.e. domoticz.devices({})), an empty set should be returned. Do not raise an error like devices( <name/idx> ) does.
- if a name or an idx value is in the specified set that does not exist on a device in domoticz, ignore such non-existent names and idx-es. Do not raise an error. If you want to make sure all devices in a set exist, an easy check can be built using .filter(), or .foreach(). If however domoticz.devices({ <empty set or set with invalid name or idx> }) would raise an error, it is very hard to detect the situation and/or work around the error.
- the set can contain both idx values and names intermixed.
- if the same device can be identified by one or more names or idx values in the set, such device is only included once in the returned set. In other words, domoticz.devices({<set>}) always returns a set of unique devices.
Code: Select all
-- example using an explicit set of names.
local mysensors = domoticz.devices({ 'sensor1', 'sensor2', 'sensor3' })
-- example using a variable that is a set of names
local switch_names = { 'switch1', 'switch2', 'switch8', 'switch 3' }
local myswitches = domoticz.devices(switch_names)
-- or using idx values:
local myothersensors = domoticz.devices({ 23, 31, 221, 222 })
-- or both mixed:
local mythingies = domoticz.devices( { 'switch3', 43 })
Some additional rules to make the behavior unambigious:
- If an empty set is passed in (f.e. domoticz.devices({})), an empty set should be returned. Do not raise an error like devices( <name/idx> ) does.
- if a name or an idx value is in the specified set that does not exist on a device in domoticz, ignore such non-existent names and idx-es. Do not raise an error. If you want to make sure all devices in a set exist, an easy check can be built using .filter(), or .foreach(). If however domoticz.devices({ <empty set or set with invalid name or idx> }) would raise an error, it is very hard to detect the situation and/or work around the error.
- the set can contain both idx values and names intermixed.
- if the same device can be identified by one or more names or idx values in the set, such device is only included once in the returned set. In other words, domoticz.devices({<set>}) always returns a set of unique devices.