当前位置: 首页>>代码示例>>Python>>正文


Python ZWaveNetwork.set_poll_interval方法代码示例

本文整理汇总了Python中openzwave.network.ZWaveNetwork.set_poll_interval方法的典型用法代码示例。如果您正苦于以下问题:Python ZWaveNetwork.set_poll_interval方法的具体用法?Python ZWaveNetwork.set_poll_interval怎么用?Python ZWaveNetwork.set_poll_interval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openzwave.network.ZWaveNetwork的用法示例。


在下文中一共展示了ZWaveNetwork.set_poll_interval方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ZWDeviceController

# 需要导入模块: from openzwave.network import ZWaveNetwork [as 别名]
# 或者: from openzwave.network.ZWaveNetwork import set_poll_interval [as 别名]
class ZWDeviceController(IOTDeviceController):
    def louie_network_started(network):
        print (
            "Hello from network : I'm started : homeid %0.8x - %d nodes were found."
            % (network.home_id, network.nodes_count)
        )

    def louie_network_failed(network):
        print ("Hello from network : can't load :(.")

    def louie_network_ready(network):
        print ("Hello from network : I'm ready : %d nodes were found." % network.nodes_count)
        print ("Hello from network : my controller is : %s" % network.controller)
        dispatcher.connect(louie_node_update, ZWaveNetwork.SIGNAL_NODE)
        dispatcher.connect(louie_value_update, ZWaveNetwork.SIGNAL_VALUE)

    def louie_node_update(network, node):
        print ("Hello from node : %s." % node)

    def louie_value_update(network, node, value):
        print ("Hello from value : %s." % value)

    def __init__(self, name, location, nodefilename="/opt/seciot/nodenames.json"):
        IOTDeviceController.__init__(self, name)

        # Restore node stuff
        nodefile = open(nodefilename, "r")
        nodejson = nodefile.read()
        self.node_dict = json.loads(nodejson)

        # Init options
        device = "/dev/ttyACM0"
        sniff = 300.0
        options = ZWaveOption(device, config_path="/opt/openzwave/config", user_path=".", cmd_line="")
        options.set_logging(False)
        options.set_console_output(False)
        options.lock()
        # Create a network object
        self.network = ZWaveNetwork(options, autostart=False)
        self.network.set_poll_interval(10, True)
        # We connect to the louie dispatcher
        dispatcher.connect(self.louie_network_started, ZWaveNetwork.SIGNAL_NETWORK_STARTED)
        dispatcher.connect(self.louie_network_failed, ZWaveNetwork.SIGNAL_NETWORK_FAILED)
        self.network.start()
        # We wait for the network.
        print "***** Waiting for network to become ready : "
        for i in range(0, 300):
            if self.network.state >= self.network.STATE_READY:
                print "***** Network is ready"
                break
            else:
                sys.stdout.write(".")
                sys.stdout.flush()
            time.sleep(1.0)
            # We update the name of the controller
        self.network.controller.node.name = name
        self.network.controller.node.location = location

    def export(self):
        # list of devices
        # each device has zwavename, friendly name, device type, statepool, currentstates (timestamped)
        # return self.network.nodes
        return self.node_dict.keys()

    def readState(self, node):
        print "read", self.node_dict
        print "read", node
        if type(node) in [str, unicode]:
            nodenum = self.node_dict[node]
        else:
            print type(node)
            nodenum = node
        mynode = self.network.nodes[nodenum]
        state = None
        for switch in mynode.get_switches():
            state = mynode.get_switch_state(switch)
            print node
            print state
        return state

    def setState(self, node, state):
        print "set", self.node_dict
        print "set", node
        if type(node) in [str, unicode]:
            nodenum = self.node_dict[node]
        else:
            nodenum = node
        if state in [1, "1", u"1", True]:
            boolstate = True
        elif state in [0, "0", u"0", False]:
            boolstate = False
        else:
            print state
            print type(state)
            raise error("bad")
        print state
        for switch in self.network.nodes[nodenum].get_switches():
            self.network.nodes[nodenum].set_switch(switch, boolstate)
开发者ID:aakatz3,项目名称:seciot,代码行数:100,代码来源:zwservice.py


注:本文中的openzwave.network.ZWaveNetwork.set_poll_interval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。