예제 #1
0
파일: scan.py 프로젝트: Jicehef/pyzigbee
def scan():
    """
    Scan the network looking for zigbee devices and print the found IDs
    """
    # Note that you may need to pass a configuration file to
    # the GatewayFactory since your low level device may be different
    # from the default one. Please read the 'Configuration' section
    # of the documentation
    gateway = GatewayFactory().create_gateway(ref="088328")

    with closing(gateway.open()) as gateway:
        ids = gateway.scan()

    print("Zigbee devices on the network:", ids)
예제 #2
0
    def do_gw_change(self, ref):
        """
        Change the current gateway

        arg: gateway reference
        """
        self.gateway = GatewayFactory(conf_filename=self.conf_filename)\
            .create_gateway(ref=ref)
예제 #3
0
 def __init__(self, conf_filename=None):
     cmd.Cmd.__init__(self)
     self.conf_filename = conf_filename
     self.gateway = GatewayFactory(conf_filename=self.conf_filename) \
         .create_gateway(ref="088328")
     self.logger = logging.getLogger("pyzigbee.shell")
     self.pp = pprint.PrettyPrinter(indent=4)
     self.platform_srvc = create_platform_service()
     PyZigBeeShell.intro += "\ngateway: %s \n" % self.gateway.get_info()["description"]
     PyZigBeeShell.intro += "conf file: %s \n" % self.conf_filename
     PyZigBeeShell.intro += "platform: %s \n" % self.platform_srvc
예제 #4
0
 def do_gw_supported(self, arg):
     """
     Print list of currently supported gateways
     """
     arg = arg
     self.pp.pprint(GatewayFactory.get_supported_refs())
예제 #5
0
class PyZigBeeShell(cmd.Cmd):
    """
    PyZigBeeShell is the Cmd class of the pyzigbee shell app
    """

    intro = "###################################\n" \
            "# Welcome to the PyZigBee shell!  #\n" \
            "#       (pyzigbee lib: %s)%s#\n" \
            "# Type help or ? to list commands.#\n" \
            "###################################\n" \
            % (__version__, (10 - len(__version__)) * " ")
    prompt = '(pyzigbeesh) '

    def __init__(self, conf_filename=None):
        cmd.Cmd.__init__(self)
        self.conf_filename = conf_filename
        self.gateway = GatewayFactory(conf_filename=self.conf_filename) \
            .create_gateway(ref="088328")
        self.logger = logging.getLogger("pyzigbee.shell")
        self.pp = pprint.PrettyPrinter(indent=4)
        self.platform_srvc = create_platform_service()
        PyZigBeeShell.intro += "\ngateway: %s \n" % self.gateway.get_info()["description"]
        PyZigBeeShell.intro += "conf file: %s \n" % self.conf_filename
        PyZigBeeShell.intro += "platform: %s \n" % self.platform_srvc

    def do_clear(self, arg):
        """
        Clear screen
        """
        arg = arg
        self.platform_srvc.clear()

    @handle_exception
    def do_gw_info(self, arg):
        """
        Print information about the current gateway
        """
        arg = arg
        self.pp.pprint(self.gateway.get_info())

    @handle_exception
    def do_gw_supported(self, arg):
        """
        Print list of currently supported gateways
        """
        arg = arg
        self.pp.pprint(GatewayFactory.get_supported_refs())

    @handle_exception
    def do_gw_change(self, ref):
        """
        Change the current gateway

        arg: gateway reference
        """
        self.gateway = GatewayFactory(conf_filename=self.conf_filename)\
            .create_gateway(ref=ref)

    @handle_exception
    def do_scan(self, arg):
        """
        Scan the network and print the found zigbee devices

        Optional arg: number of seconds to wait for an answer
        """
        if arg == "":
            arg = 5

        with closing(self.gateway.open()) as gateway:
            zigbee_devices = gateway.scan(delay=arg)

        for zigbee_device in zigbee_devices:
            print("index: %03d   id: %s" %
                  (zigbee_device['index'], zigbee_device['zigbee_id']))

    @handle_exception
    def do_receive(self, arg):
        """
        Receive frame from the network

        Optional arg: number of seconds to block (no arg means infinite)
        """
        with closing(self.gateway.open()) as gateway:
            print(gateway.receive(timeout=arg))

    @handle_exception
    def do_bind(self, arg):
        """
        Bind procecure

        arg: is the zigbee ID to bind with
        """
        with closing(self.gateway.open()) as gateway:
            gateway.bind(zigbee_id=arg)

    @handle_exception
    def do_unbind(self, arg):
        """
        Unbind procecure

        arg: is the zigbee ID to unbind from
        """
        with closing(self.gateway.open()) as gateway:
            gateway.unbind(zigbee_id=arg)

    @handle_exception
    def do_version(self, arg):
        """
        Request the device for its firmware/hardware version numbers

        Optional arg: zigbee ID (if unset request the gateway version numbers)
        """
        with closing(self.gateway.open()) as gateway:
            print("firmware:", gateway.get_firmware_version(zigbee_id=arg))
            print("hardware:", gateway.get_hardware_version(zigbee_id=arg))

    @handle_exception
    def do_drv_read(self, arg):
        """
        Read data trough the gateway driver (bypassing protocol decoding)

        Optional arg: number of bytes to read
        """
        print(self.gateway.driver.read(to_read=arg))

    @handle_exception
    def do_drv_receive(self, arg):
        """
        Receive frame from the network

        Optional arg: number of seconds to block (no arg means infinite)
        """
        print(self.gateway.receive(timeout=arg))

    @handle_exception
    def do_drv_write(self, arg):
        """
        Write data to the gateway driver (bypassing protocol encoding)

        example: drv_write 12345
        """
        self.gateway.driver.write(arg)

    @handle_exception
    def do_drv_open(self, arg):
        """
        Open the gateway driver
        """
        arg = arg
        self.gateway.driver.open()

    @handle_exception
    def do_drv_close(self, arg):
        """
        Close the gateway driver
        """
        arg = arg
        self.gateway.driver.close()
예제 #6
0
 def test_get_supported(self):
     assert_true("088328" in GatewayFactory.get_supported_refs())