How to use the appdaemon.utils function in appdaemon

To help you get started, we’ve selected a few appdaemon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github home-assistant / appdaemon / appdaemon / __main__.py View on Github external
# Get command line args

        parser = argparse.ArgumentParser()

        parser.add_argument("-c", "--config", help="full path to config directory", type=str, default=None)
        parser.add_argument("-p", "--pidfile", help="full path to PID File", default=None)
        parser.add_argument("-t", "--timewarp", help="speed that the scheduler will work at for time travel", default=1, type=float)
        parser.add_argument("-s", "--starttime", help="start time for scheduler ", type=str)
        parser.add_argument("-e", "--endtime", help="end time for scheduler ", type=str, default=None)
        parser.add_argument("-D", "--debug", help="global debug level", default="INFO", choices=
                            [
                                "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"
                            ])
        parser.add_argument('-m', '--moduledebug', nargs=2, action='append', help=argparse.SUPPRESS)
        parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + utils.__version__)
        parser.add_argument('--profiledash', help=argparse.SUPPRESS, action='store_true')

        args = parser.parse_args()

        config_dir = args.config
        pidfile = args.pidfile

        if config_dir is None:
            config_file_yaml = utils.find_path("appdaemon.yaml")
        else:
            config_file_yaml = os.path.join(config_dir, "appdaemon.yaml")

        if config_file_yaml is None:
            print("FATAL: no configuration directory defined and defaults not present\n")
            parser.print_help()
            sys.exit(1)
github home-assistant / appdaemon / appdaemon / adapi.py View on Github external
    @utils.sync_wrapper
    async def listen_log(self, callback, level="INFO", **kwargs):
        """Registers the App to receive a callback every time an App logs a message.

        Args:
            callback (function): Function to be called when a message is logged.
            level (str): Logging level to be used - lower levels will not be forwarded
                to the app (Default: ``"INFO"``).
            **kwargs (optional): Zero or more keyword arguments.

        Keyword Args:
            log (str, optional): Name of the log to listen to, default is all logs. The name
                should be one of the 4 built in types ``main_log``, ``error_log``, ``diag_log``
                or ``access_log`` or a user defined log entry.
            pin (bool, optional): If True, the callback will be pinned to a particular thread.
            pin_thread (int, optional): Specify which thread from the worker pool the callback
                will be run by (0 - number of threads -1).
github home-assistant / appdaemon / appdaemon / state.py View on Github external
def sanitize_state_kwargs(app, kwargs):
        kwargs_copy = kwargs.copy()
        return utils._sanitize_kwargs(kwargs_copy, [
            "old", "new", "__attribute", "duration", "state",
            "__entity", "__duration", "__old_state", "__new_state",
            "oneshot", "pin_app", "pin_thread", "__delay"
        ] + app.list_constraints())
github home-assistant / appdaemon / appdaemon / adapi.py View on Github external
    @utils.sync_wrapper
    async def unregister_endpoint(self, handle):
        """Removes a previously registered endpoint.

        Args:
            handle: A handle returned by a previous call to ``register_endpoint``

        Returns:
            None.

        Examples:
            >>> self.unregister_endpoint(handle)

        """
        await self.AD.http.unregister_endpoint(handle, self.name)
github home-assistant / appdaemon / appdaemon / hassapi.py View on Github external
"name": name,
                "id": conf.objects[name]["id"],
                "type": "state",
                "function": function,
                "entity": entity,
                "kwargs": kwargs
            }

        #
        # In the case of a quick_start parameter,
        # start the clock immediately if the device is already in the new state
        #
        if "immediate" in kwargs and kwargs["immediate"] is True:
            if entity is not None and "new" in kwargs and "duration" in kwargs:
                if conf.ha_state[entity]["state"] == kwargs["new"]:
                    exec_time = utils.get_now_ts() + int(kwargs["duration"])
                    kwargs["handle"] = utils.insert_schedule(
                        name, exec_time, function, False, None,
                        entity=entity,
                        attribute=None,
                        old_state=None,
                        new_state=kwargs["new"], **kwargs
                )

        return handle
github home-assistant / appdaemon / appdaemon / dashboard.py View on Github external
def _load_yaml(self, stream):
        myyaml = None
        yaml.add_constructor('!secret', ha._secret_yaml, Loader=yaml.SafeLoader)
        try:
            myyaml = yaml.load(stream, Loader=yaml.SafeLoader)
        except ValueError as v:
            self.logger.warning(str(v))

        return myyaml