本文整理汇总了Python中querier.Querier.setMsgHandler方法的典型用法代码示例。如果您正苦于以下问题:Python Querier.setMsgHandler方法的具体用法?Python Querier.setMsgHandler怎么用?Python Querier.setMsgHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类querier.Querier
的用法示例。
在下文中一共展示了Querier.setMsgHandler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: InsteonAddress
# 需要导入模块: from querier import Querier [as 别名]
# 或者: from querier.Querier import setMsgHandler [as 别名]
class Device:
name = ""
address = InsteonAddress()
db = None
dbbuilder = None
querier = None
def __init__(self, name, addr):
self.name = name
self.address = addr
self.db = DB()
self.querier = Querier(addr)
addDev(self)
def modifyDB(self, listener):
self.dbbuilder.setListener(listener)
# after db download complete, listener will perform action
self.getdb()
def setRecord(self, offset, laddr, group, linkType, data):
msg = self.makeMsg(offset, laddr, group, linkType,data)
self.querier.setMsgHandler(MsgHandler("got set record"))
self.querier.sendMsg(msg)
def makeMsg(self, offset, laddr, group, linkType, data):
msg = Msg.s_makeMessage("SendExtendedMessage")
msg.setAddress("toAddress", InsteonAddress(self.getAddress()))
msg.setByte("messageFlags", 0x1f)
msg.setByte("command1", 0x2f)
msg.setByte("command2", 0x00)
msg.setByte("userData1", 0x00) # don't care info
msg.setByte("userData2", 0x02) # set database
msg.setByte("userData3", offset >> 8) # high byte
msg.setByte("userData4", offset & 0xff) # low byte
msg.setByte("userData5", 8) # number of bytes set: 1...8
msg.setByte("userData6", linkType)
msg.setByte("userData7", group)
msg.setByte("userData8", laddr.getHighByte())
msg.setByte("userData9", laddr.getMiddleByte())
msg.setByte("userData10", laddr.getLowByte())
# depends on mode: could be e.g. trigger point
msg.setByte("userData11", data[0])
msg.setByte("userData12", data[1]) # unused?
msg.setByte("userData13", data[2]) # unused?
rb = msg.getBytes("command1", 15);
checksum = (~sum(rb) + 1) & 0xFF
msg.setByte("userData14", checksum)
return msg
def getName(self):
return self.name
def getAddress(self):
return self.address
def getdb(self):
"""getdb()
download the device database and print it on the console"""
iofun.out("getting db, be patient!")
self.dbbuilder.clear()
self.dbbuilder.start()
def printdb(self):
"""printdb()
print the downloaded link database to the console"""
self.dbbuilder.printdb()
def getId(self):
"""getId()
get category, subcategory, firmware, hardware version"""
self.querier.setMsgHandler(IdMsgHandler("id"))
self.querier.querysd(0x10, 0x00)
#
# link database management
#
def addController(self, addr, group, data = None):
"""addController(addr, group, data)
add device with "addr" as controller for group "group", with link data "data" """
data = data if data else [00, 00, group];
self.modifyDB(LinkRecordAdder(self, addr, group, data, True))
def removeController(self, addr, group):
"""removeController(addr, group)
remove device with "addr" as controller for group "group", with link data "data" """
self.modifyDB(LinkRecordRemover(self, addr, group, True))
def addResponder(self, addr, group, data = None):
"""addResponder(addr, group, data)
add device with "addr" as responder for group "group", with link data "data" """
data = data if data else [00, 00, group];
self.modifyDB(LinkRecordAdder(self, addr, group, data, False))
def removeResponder(self, addr, group):
"""removeResponder(addr, group)
remove device with "addr" as responder for group "group" """
self.modifyDB(LinkRecordRemover(self, addr, group, False))
def removeDevice(self, addr):
"""removeDevice(addr):
removes all links to device with address "addr" from device database"""
self.modifyDB(DeviceRemover(self, addr))
def replaceDevice(self, oldAddr, newAddr):
"""replaceDevice(oldAddr, newAddr):
#.........这里部分代码省略.........
示例2: Modem2413U
# 需要导入模块: from querier import Querier [as 别名]
# 或者: from querier.Querier import setMsgHandler [as 别名]
class Modem2413U(Device):
"""============== Insteon PowerLinc modem (PLM) ==============="""
def __init__(self, name, addr):
Device.__init__(self, name, addr)
self.dbbuilder = ModemDBBuilder(addr, self.db)
def __modifyModemDB(self, listener):
self.dbbuilder.setListener(listener)
# after db download complete, listener will perform action
iofun.out("getting db, be patient!")
self.dbbuilder.clear()
self.dbbuilder.start()
def getdb(self):
"""getdb()
download the modem database and print it on the console"""
self.dbbuilder.start()
self.dbbuilder.wait()
self.dbbuilder.dumpDB()
out("Modem Link DB complete")
def startWatch(self):
"""startWatch()
modem will print all incoming messages on terminal"""
self.querier = Querier(InsteonAddress("00.00.00"))
self.querier.setMsgHandler(MsgDumper("modem"))
self.querier.startWait(10000)
def stopWatch(self):
"""stopWatch()
stop modem from printing all incoming messages on terminal"""
if (self.querier):
self.querier.cancel()
def getid(self):
"""getid()
get modem id data"""
self.querier = Querier(InsteonAddress("00.00.00"))
self.querier.setMsgHandler(IMInfoMsgHandler("getid"))
msg = Msg.s_makeMessage("GetIMInfo")
self.querier.sendMsg(msg)
def sendOn(self, group):
"""sendOn(group)
sends ALLLink broadcast ON message to group "group" """
msg = message.createStdMsg(InsteonAddress("00.00.00"), 0x0f,
0x11, 0xFF, group)
iofun.writeMsg(msg)
iofun.out("sent msg: " + msg.toString())
def sendOff(self, group):
"""sendOff(group)
sends ALLLink broadcast OFF message to group "group" """
msg = message.createStdMsg(InsteonAddress("00.00.00"), 0x0f,
0x13, 0xFF, group)
iofun.writeMsg(msg)
iofun.out("sent msg: " + msg.toString())
def linkAsController(self, otherDevice, group):
"""linkAsController(otherDevice, group)
puts modem in link mode to control device "otherDevice" on group "group" """
addr = InsteonAddress(otherDevice)
self.querier = Querier(addr)
self.querier.setMsgHandler(DefaultMsgHandler("link as controller"))
msg = Msg.s_makeMessage("StartALLLinking")
msg.setByte("LinkCode", 0x01)
msg.setByte("ALLLinkGroup", group)
self.querier.sendMsg(msg)
def linkAsResponder(self, otherDevice, group):
"""linkAsResponder(otherDevice, group)
puts modem in link mode to respond to device "otherDevice" on group "group" """
addr = InsteonAddress(otherDevice)
self.querier = Querier(addr)
self.querier.setMsgHandler(DefaultMsgHandler("start linking"))
msg = Msg.s_makeMessage("StartALLLinking")
msg.setByte("LinkCode", 0x00)
msg.setByte("ALLLinkGroup", group)
self.querier.sendMsg(msg)
def linkAsEither(self, otherDevice, group):
"""linkAsEither(otherDevice, group)
puts modem in link mode to link as controller or responder to device "otherDevice" on group "group" """
addr = InsteonAddress(otherDevice)
self.querier = Querier(addr)
self.querier.setMsgHandler(
DefaultMsgHandler("link/unlink as controller or responder"))
msg = Msg.s_makeMessage("StartALLLinking")
msg.setByte("LinkCode", 0x03)
msg.setByte("ALLLinkGroup", group)
self.querier.sendMsg(msg)
def respondToUnlink(self, otherDevice, group):
"""respondToUnlink(otherDevice, group)
make modem respond to unlink message from other device"""
# could not get 0xFF to unlink
self.linkAsEither(otherDevice, group)
def unlinkAsController(self, otherDevice, group):
"""unlinkAsController(otherDevice, group)
puts modem in unlink mode to unlink as controller from device "otherDevice" on group "group" """
addr = InsteonAddress(otherDevice)
self.querier = Querier(addr)
self.querier.setMsgHandler(DefaultMsgHandler("unlink as controller"))
msg = Msg.s_makeMessage("StartALLLinking")
msg.setByte("LinkCode", 0xFF)
msg.setByte("ALLLinkGroup", group)
self.querier.sendMsg(msg)
def cancelLinking(self):
"""cancelLinking()
#.........这里部分代码省略.........