本文整理汇总了Python中Domoticz.Connection方法的典型用法代码示例。如果您正苦于以下问题:Python Domoticz.Connection方法的具体用法?Python Domoticz.Connection怎么用?Python Domoticz.Connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Domoticz
的用法示例。
在下文中一共展示了Domoticz.Connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onMessage
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onMessage(self, Connection, Data):
self.DumpVariable(Data, "OnMessage SessionState: "+ str(self.sessionState) + ", Data", Level=8, BytesAsStr = True)
if (Connection == self.connection):
if ('Status' in Data) and ('Data' in Data):
datastr = (Data['Data'].decode("utf-8"))
if (Data['Status'] == '200') and (self.sessionState == 1):
try:
tree = etree.XML(Data['Data'])
self.session = tree.find('session').text
self.LogMessage("Session ID: "+self.session , 7)
except:
pass
return
示例2: onMessage
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onMessage(self, Connection, Data, Status, Extra):
#Domoticz.Debug("Received: " + str(Data))
command = json.loads(Data.decode("utf-8"))
#Domoticz.Log("Command: " + command['action'])
if command['status'] == "Ok":
action = command['action']
if action == "setConfig":
# Config set
Connection.Send(Message=json.dumps({"action":"getLights"}).encode(encoding='utf_8'), Delay=1)
if action == "getLights":
self.registerDevices(command['result'])
if action == "deviceUpdate":
self.updateDeviceState(command['result'])
if command['status'] == "Failed":
Domoticz.Log("Command {0} failed with error: {1}.".format(command['action'],command['error']))
Domoticz.Log(str(command))
示例3: onConnect
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onConnect(self, Connection, Status, Description):
global isConnected
if (Status == 0):
isConnected = True
Domoticz.Log("Connected successfully to: "+Parameters["SerialPort"])
# Run RFPlayer configuration
RFpConf()
else:
Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Parameters["SerialPort"])
Domoticz.Debug("Failed to connect ("+str(Status)+") to: "+Parameters["SerialPort"]+" with error: "+Description)
return True
# present de base
示例4: onMessage
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onMessage(self, Connection, Data):
global Tmprcv
global ReqRcv
###########################################
Tmprcv=Data.decode(errors='ignore')
################## check if more than 1 sec between two message, if yes clear ReqRcv
lastHeartbeatDelta = (datetime.datetime.now()-self.lastHeartbeat).total_seconds()
if (lastHeartbeatDelta > 1):
ReqRcv=''
Domoticz.Debug("Last Message was "+str(lastHeartbeatDelta)+" seconds ago, Message clear")
#Wait not end of data '\r'
if Tmprcv.endswith('\r',0,len(Tmprcv))==False :
ReqRcv+=Tmprcv
else : # while end of data is receive
ReqRcv+=Tmprcv
########## TODO : verifier si une trame ZIA n est pas en milieu de message (2messages collés ou perturbation+ message accoller)
if ReqRcv.startswith("ZIA--{"):
Domoticz.Debug(ReqRcv)
ReadConf(ReqRcv)
if ReqRcv.startswith("ZIA33"):
Domoticz.Debug(ReqRcv)
ReadData(ReqRcv)
ReqRcv=''
self.lastHeartbeat = datetime.datetime.now()
return
# present de base action executer qd une commande est passé a Domoticz
示例5: onStart
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onStart(self):
if Parameters["Mode6"] == "Debug":
Domoticz.Debugging(1)
Domoticz.Debug("onStart called")
if 1 not in Devices:
Domoticz.Debug("Create Status Device")
Domoticz.Device(Name="Status", Unit=1, Type=17, Switchtype=17, Used=1).Create()
if 2 not in Devices:
Domoticz.Debug("Create Volume Device")
Domoticz.Device(Name="Volume", Unit=2, Type=244, Subtype=73, Switchtype=7, Image=8, Used=1).Create()
if 3 not in Devices:
Domoticz.Debug("Create HDMI Device")
Options = { "LevelActions" : "|||||||",
"LevelNames" : "Off|HDMI1|HDMI2|HDMI3|HDMI4|HDMI5|HDMI6|HDMI7",
"LevelOffHidden" : "true",
"SelectorStyle" : "0"
}
Domoticz.Device(Name="Source", Unit=3, TypeName="Selector Switch", Switchtype=18, Options=Options, Used=1).Create()
if 4 not in Devices:
Domoticz.Debug("Create AV Device")
Options = { "LevelActions" : "||||||",
"LevelNames" : "Off|AV1|AV2|AV3|AV4|AV5|AV6",
"LevelOffHidden" : "true",
"SelectorStyle" : "0"
}
Domoticz.Device(Name="AV Source", Unit=4, TypeName="Selector Switch", Switchtype=18, Options=Options, Used=1).Create()
self.connection = Domoticz.Connection(Name="Yamaha connection", Transport="TCP/IP", Protocol="Line", Address=Parameters["Address"], Port=Parameters["Port"])
self.connection.Connect()
Domoticz.Heartbeat(20)
示例6: onConnect
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onConnect(self, Connection, Status, Description):
Domoticz.Debug("onConnect called. Status: " + str(Status))
if (Status == 0):
self.isConnected = True
self.onHeartbeat()
else:
self.isConnected = False
示例7: onMessage
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onMessage(self, Connection, Data):
Domoticz.Debug("onMessage called")
self.outstandingPings = self.outstandingPings - 1
strData = Data.decode("utf-8", "ignore")
for line in strData.splitlines():
arrData = line.split('=')
for x in arrData:
Domoticz.Debug(x)
if (arrData[0] == "@MAIN:PWR"):
if (arrData[1] == "On"):
UpdateDevice(1, 1, Devices[1].sValue)
elif (arrData[1] == "Standby"):
UpdateDevice(1, 0, Devices[1].sValue)
elif (arrData[0] == "@MAIN:VOL"):
vol = float(arrData[1])
sliderValue = int(vol*5/4 + 100)
UpdateDevice(2, Devices[2].nValue, str(sliderValue))
elif (arrData[0] == "@MAIN:MUTE"):
if (arrData[1] == "Off"):
UpdateDevice(2, 2, Devices[2].sValue)
elif (arrData[1] == "On"):
UpdateDevice(2, 0, Devices[2].sValue)
elif (arrData[0] == "@MAIN:INP"):
s = arrData[1]
inp = int(s[-1:])
if (s.startswith("HDMI")):
UpdateDevice(3,2,str(inp*10))
UpdateDevice(4,2,"0")
elif (s.startswith("AV")):
UpdateDevice(4,2,str(inp*10))
UpdateDevice(3,2,"0")
elif (arrData[0] == "@MAIN:SOUNDPRG"):
UpdateDevice(1, Devices[1].nValue, arrData[1])
示例8: onDisconnect
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onDisconnect(self, Connection):
Domoticz.Debug("onDisconnect called")
self.isConnected = False
示例9: onConnect
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onConnect(self, Connection, Status, Description):
if (Status == 0):
self.LogMessage("Connected successfully to: "+Connection.Address+":"+Connection.Port, 3)
self.sendMessage({'command' : 'serverinfo'})
self.errorReported = False
else:
if not self.errorReported:
self.errorReported = True
self.LogMessage("Failed to connect ("+str(Status)+") to: "+Connection.Address+":"+Connection.Port+" with error: "+Description, 3)
return
示例10: onDisconnect
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onDisconnect(self, Connection):
self.LogMessage("onDisconnect "+Connection.Address+":"+Connection.Port, 7)
return
示例11: onMessage
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onMessage(Connection, Data):
global _plugin
_plugin.onMessage(Connection, Data)
示例12: onConnect
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onConnect(self, Connection, Status, Description):
if (Status == 0):
self.LogMessage("Connected successfully to: "+Connection.Address+":"+Connection.Port, 5)
# if connect we must send data
# depending on if a key/session/command is known
if (len(self.key) <= 2):
self.LogMessage("Pairing key is unknown. Request pairing key (shown on TV)", 1)
reqKey = "<!--?xml version=\"1.0\" encoding=\"utf-8\"?--><auth><type>AuthKeyReq</type></auth>"
self.sessionState = 0
self.sendMessage(Message=reqKey, URL="/hdcp/api/auth")
else:
if self.session is None: # or always session id
pairCmd = '<?xml version="1.0" encoding="utf-8"?><auth><type>AuthReq</type><value>'+ self.key + '</value></auth>'
self.sessionState = 1
self.sendMessage(Message=pairCmd, URL="/hdcp/api/auth")
else: # message
items = len(self.queuedCommands)
if items > 0:
cmd = self.queuedCommands.pop(0)
self.LogMessage("Sending command '" + cmd +"', still "+str(items-1)+" command in queue", 5)
cmdText = '<?xml version="1.0" encoding="utf-8"?><command><session>'+self.session+'</session><name>HandleKeyInput</name><value>'+str(self.LGCodes[cmd])+'</value></command>'
self.sessionState = 2
self.sendMessage(Message=cmdText, URL="/hdcp/api/dtv_wifirc")
else:
self.LogMessage("Failed to connect ("+str(Status)+") to: "+Connection.Address+":"+Connection.Port+" with error: "+Description, 4)
self.queuedCommands.clear() # clear send commands
self.session = None
return
示例13: onDisconnect
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onDisconnect(self, Connection):
items = len(self.queuedCommands)
self.LogMessage("onDisconnect "+Connection.Address+":"+Connection.Port+", still "+ str(items)+" in the queue", 7)
# if there are still command continue
if (items > 0) and (len(self.key) > 2):
self.DumpVariable(self.queuedCommands, "queuedCommands", Level=7)
self.checkConnection()
return
示例14: sendMessage
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def sendMessage(self, Message, URL, Verb="POST", Headers={ 'Content-Type': 'application/atom+xml; charset=utf-8', 'Connection': 'Keep-Alive'}):
Headers['Host']=self.connection.Address+":"+self.connection.Port
data = {"Verb":Verb, "URL":URL, "Headers": Headers, 'Data': Message}
self.DumpVariable(data, "Data to send", Level=8, BytesAsStr = True)
self.connection.Send(data)
return
####################### Generic helper member functions for plugin #######################
示例15: onConnect
# 需要导入模块: import Domoticz [as 别名]
# 或者: from Domoticz import Connection [as 别名]
def onConnect(self, Connection, Status, Description):
if (Status == 0):
self.LogMessage("Connected successfully to: "+Connection.Address+":"+Connection.Port, 3)
if self.mustForceOff:
self.connection.Send(self.commandOff)
self.mustForceOff = False
else:
self.LogMessage("Failed to connect ("+str(Status)+") to: "+Connection.Address+":"+Connection.Port+" with error: "+Description, 3)
self.updateDevices()
return