Пример #1
0
    if args.refresh:
        stick._initialize()
        stick.start()
        time.sleep(args.refreshtime + 0.5)
        stick.sync_devices()

    if args.up:
        stick._initialize()
        stick.start()
        time.sleep(1)
        ids = [
            device['id'] for device in stick.config['devices']
            if device['name'] in args.up
        ]
        for blind_id in ids:
            stick.command(blind_id, "up")
            time.sleep(0.5)
            stick.command(blind_id, "up")
            time.sleep(0.5)
            stick.command(blind_id, "up")
            time.sleep(2)

    if args.down:
        stick._initialize()
        stick.start()
        time.sleep(1)
        ids = [
            device['id'] for device in stick.config['devices']
            if device['name'] in args.down
        ]
        for blind_id in ids:
Пример #2
0
class DuofernCLI(Cmd):
    def __init__(self,
                 serial_port=None,
                 system_code=None,
                 config_file=None,
                 *args,
                 **kwargs):
        super().__init__(*args, **kwargs)
        self.stick = DuofernStickThreaded(serial_port=args.device,
                                          system_code=args.code,
                                          config_file_json=args.configfile)
        self.stick._initialize()
        self.stick.start()
        self.prompt = "duofern> "

    def emptyline(self):
        pass

    def do_pair(self, args):
        """
        Usage:
          pair <TIMEOUT>
        
        Start pairing mode. Pass a timeout in seconds as <TIMEOUT>.
        Will return after the timeout if no devices start pairing within the given timeout.
        
        Example:
        duofern> pair 10
            
        """
        timeout = 10
        if len(args) != 0:
            try:
                timeout = int(args[0])
            except:
                print(
                    "Please use an integer number to indicate TIMEOUT in seconds"
                )
        print("Starting pairing mode... waiting  {} seconds".format(
            int(timeout)))
        self.stick.pair(timeout=timeout)
        time.sleep(args.pairtime + 0.5)
        self.stick.sync_devices()
        print("Pairing done, Config file updated.")

    def do_unpair(self, args):
        """
        Usage:
          unpair <TIMEOUT>

        Start pairing mode. Pass a timeout in seconds as <TIMEOUT>.
        Will return after the timeout if no devices start pairing within the given timeout.

        Example:
        duofern> unpair 10

        """
        timeout = 10
        if len(args) != 0:
            try:
                timeout = int(args[0])
            except:
                print(
                    "Please use an integer number to indicate TIMEOUT in seconds"
                )
        print("Starting pairing mode... waiting  {} seconds".format(
            int(timeout)))
        self.stick.unpair(timeout=timeout)
        time.sleep(args.pairtime + 0.5)
        self.stick.sync_devices()
        print("Pairing done, Config file updated.")

    def do_remote(self, args):
        code = args[0][0:6]
        timeout = int(args[1])
        self.stick.remote(code, timeout)
        time.sleep(args.pairtime + 0.5)
        self.stick.sync_devices()
        print("Pairing done, Config file updated.")

    @splitargs
    @ids_for_names
    def do_up(self, blinds):
        """
        Usage:
          up <SHUTTER> [<SHUTTER> <SHUTTER>]
          
        Lift one or several shutters. Accepts a list of shutter names sepatated by space.
        
        Example:
            duofern> up Livingroom
            duofern> up Livingroom Kitchen
        """
        for blind_id in blinds:
            print("lifting {}".format(blinds[blind_id]))
            self.stick.command(blind_id, "up")

    @splitargs
    @ids_for_names
    def do_down(self, blinds):
        """
        Usage:
          up <SHUTTER> [<SHUTTER> <SHUTTER>...]

        Lower one or several shutters. Accepts a list of shutter names sepatated by space.

        Example:
            duofern> up Livingroom
            duofern> up Livingroom Kitchen
        """
        for blind_id in blinds:
            print("lowering {}".format(blinds[blind_id]))
            self.stick.command(blind_id, "down")

    @splitargs
    def do_rename(self, args):
        """
        Usage:
          rename <NAME> <NEW_NAME>
        
        Rename an actor. Write changes to config file when done.
        
        Example:
            duofern> rename 13f897 kitchen_west
        """
        id = [
            device['id'] for device in self.stick.config['devices']
            if device['name'] == args[0]
        ]
        if len(id) == 0:
            print("Please enter a valid device name for renaming.")
        self.stick.set_name(id[0], args[1])
        print("Set name for {} to {}".format(id[0], args[0]))

    def refresh(self, args):
        """
        Usage:
          refresh
        
        Refresh config file with current changes. 
        
        example:
            duofern> refresh
        """
        self.stick.sync_devices()

    @splitargs
    @ids_for_names
    def do_on(self, blinds):
        """
        Usage:
          off <SWITCH1> [<SWITCH2> <SWITCH3>]

        Switch on one or several switch actors. Accepts a list of actor names.

        Example:
            duofern> off Livingroom
            duofern> off Livingroom Kitchen
        """
        for blind_id in blinds:
            print("lifting {}".format(blinds[blind_id]))
            self.stick.command(blind_id, "up")

    @splitargs
    @ids_for_names
    def do_off(self, blinds):
        """
        Usage:
          off <SWITCH1> [<SWITCH2> <SWITCH3>]

        Switch off one or several switch actors. Accepts a list of actor names.

        Example:
            duofern> off Livingroom
            duofern> off Livingroom Kitchen
        """
        for blind_id in blinds:
            print("lifting {}".format(blinds[blind_id]))
            self.stick.command(blind_id, "up")
Пример #3
0
    if args.refresh:
        stick._initialize()
        stick.start()
        time.sleep(args.refreshtime + 0.5)
        stick.sync_devices()

    if args.up:
        stick._initialize()
        stick.start()
        time.sleep(0.5)
        ids = [device['id'] for device in stick.config['devices'] if device['name'] in args.up]
        for blind_id in ids:
            logging.info("partytime upping {}".format(blind_id))
            logging.info(stick.duofern_parser.asyncio)
            stick.command(blind_id, "up")
            time.sleep(2)

    if args.down:
        stick._initialize()
        stick.start()
        time.sleep(0.5)
        ids = [device['id'] for device in stick.config['devices'] if device['name'] in args.down]
        for blind_id in ids:
            stick.command(blind_id, "down")
            time.sleep(2)

    if args.on:
        stick._initialize()
        stick.start()
        time.sleep(0.5)