This part will check what type devices are supposed to be there and if new ones should be created (or even deleted, depends on plugin settings)
Code: Select all
def CheckDevice(self, name, deviceid, typename):
# Initialization of variables for device creation
switchtype = 0
image = 0
options = {"LevelActions": "|||",
"LevelNames": "Auto|Manual|Vacation|Boost",
"LevelOffHidden": "false",
"SelectorStyle": "0"}
if typename == "Valve":
devicetype = 243
subtype = 6
elif typename == "Thermostat":
devicetype = 242
subtype = 1
elif typename == "Temperature":
devicetype = 80
subtype = 5
elif typename == "Mode":
devicetype = 244
subtype = 62
switchtype = 18
image = 15
elif typename == "Contact":
devicetype = 244
subtype = 73
switchtype = 2
# Check if device is wanted
DeviceWanted = True
if Parameters["Mode1"] == "False" and typename == "Valve" or Parameters["Mode2"] == "False" and typename == "Mode":
DeviceWanted = False
# Check if device with given deviceid and devicetype is already present
DeviceFound = False
for Device in Devices:
if Devices[Device].DeviceID == deviceid and Devices[Device].Type == devicetype:
DeviceFound = True
# Delete found device if not wanted anymore
if not DeviceWanted:
Domoticz.Log("Deleted device " + Devices[Device].Name)
Devices[Device].Delete()
break
# If device not found but wanted, create it
if not DeviceFound and DeviceWanted:
# Check first available unit ID
availableID = 1
if Devices:
for device in Devices:
if device > availableID: break
else: availableID += 1
# Create device
Domoticz.Device(Name=name + " - " + typename, Unit=availableID, DeviceID=deviceid, Type=devicetype, Subtype=subtype, Switchtype=switchtype, Options=options, Image = image, Used=1).Create()
if availableID in Devices:
# Device created
Domoticz.Log("Created device '" + Parameters["Name"] + " - " + name + " - " + typename + "'")
else:
# Device not created!
Domoticz.Error("Device '" + Parameters["Name"] + " - " + name + " - " + typename + "' could not be created. Is 'Accept new Hardware Devices' enabled under Settings?")