def UpdateDevice(Unit, nValue, sValue, updEvery=False):
# Make sure that the Domoticz device still exists (they can be deleted) before updating it
if (Unit in Devices):
if (Devices[Unit].nValue != nValue) or (Devices[Unit].sValue != sValue):
Devices[Unit].Update(nValue, str(sValue))
#Domoticz.Debug("Update "+str(nValue)+":'"+str(sValue)+"' ("+Devices[Unit].Name+")")
elif updEvery:
# Update device even not changed every X minutes - for Temp and Volt values
updMinutes = 15
Domoticz.Debug("LastUpdate: '" + Devices[Unit].LastUpdate + "' ("+Devices[Unit].Name+")")
#devUpdate = datetime.strptime("2017-06-22 18:24:21", "%Y-%m-%d %H:%M:%S")
#devUpdate = datetime.strptime(Devices[Unit].LastUpdate, "%Y-%m-%d %H:%M:%S")
devUpdate = datetime(*(time.strptime(Devices[Unit].LastUpdate, "%Y-%m-%d %H:%M:%S")[0:6]))
devBefore = datetime.now() - devUpdate
if (devBefore > timedelta(minutes=updMinutes)):
Domoticz.Debug("Updated before: " + str(devBefore) + " ("+Devices[Unit].Name+")")
Devices[Unit].Update(nValue, str(sValue))
return
# Generic helper functions
评论列表
文章目录