plugin.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:domoticz-plugins 作者: milanvo 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号