How to use the appdaemon.homeassistant.log 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 / appdaemon.py View on Github external
get_ha_state()
            last_state = ha.get_now()
        except:
            ha.log(
                conf.logger, "WARNING",
                "Disconnected from Home Assistant, retrying in 5 seconds"
            )
            if conf.loglevel == "DEBUG":
                ha.log(conf.logger, "WARNING", '-' * 60)
                ha.log(conf.logger, "WARNING", "Unexpected error:")
                ha.log(conf.logger, "WARNING", '-' * 60)
                ha.log(conf.logger, "WARNING", traceback.format_exc())
                ha.log(conf.logger, "WARNING", '-' * 60)
            time.sleep(5)

    ha.log(conf.logger, "INFO", "Got initial state")
    # Load apps

    if conf.apps is True:
        ha.log(conf.logger, "DEBUG", "Reading Apps")

        read_apps(True)

        ha.log(conf.logger, "INFO", "App initialization complete")

        # Create timer thread

        # First, update "now" for less chance of clock skew error
        if conf.realtime:
            conf.now = datetime.datetime.now().timestamp()

            ha.log(conf.logger, "DEBUG", "Starting timer thread")
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
if v == {}:
                    del conf.schedule[k]

        return utc

    except:
        ha.log(conf.error, "WARNING", '-' * 60)
        ha.log(conf.error, "WARNING",
               "Unexpected error during do_every_second()")
        ha.log(conf.error, "WARNING", '-' * 60)
        ha.log(conf.error, "WARNING", traceback.format_exc())
        ha.log(conf.error, "WARNING", '-' * 60)
        if conf.errorfile != "STDERR" and conf.logfile != "STDOUT":
            # When explicitly logging to stdout and stderr, suppress
            # log messages about writing an error (since they show up anyway)
            ha.log(
                conf.logger, "WARNING",
                "Logged an error to {}".format(conf.errorfile)
            )
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
conf.time_zone = ha_config["time_zone"]

    if "elevation" in ha_config:
        conf.elevation = ha_config["elevation"]
        if "elevation" in config['AppDaemon']:
            ha.log(conf.logger, "WARNING",
                   "'elevation' directive is deprecated, please remove")
    else:
        conf.elevation = config['AppDaemon']["elevation"]

    # Use the supplied timezone
    os.environ['TZ'] = conf.time_zone

    # Now we have logging, warn about deprecated directives
    if "latitude" in config['AppDaemon']:
        ha.log(
            conf.logger, "WARNING",
            "'latitude' directive is deprecated, please remove"
        )

    if "longitude" in config['AppDaemon']:
        ha.log(
            conf.logger, "WARNING",
            "'longitude' directive is deprecated, please remove"
        )

    if "timezone" in config['AppDaemon']:
        ha.log(
            conf.logger, "WARNING",
            "'timezone' directive is deprecated, please remove"
        )
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
def clear_object(object_):
    ha.log(conf.logger, "DEBUG", "Clearing callbacks for {}".format(object_))
    with conf.callbacks_lock:
        if object_ in conf.callbacks:
            del conf.callbacks[object_]
    with conf.schedule_lock:
        if object_ in conf.schedule:
            del conf.schedule[object_]
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
for name in config:
            if name == "DEFAULT" or name == "AppDaemon":
                continue
            if module_name == config[name]["module"]:
                class_name = config[name]["class"]

                init_object(name, class_name, module_name, config[name])

    except:
        ha.log(conf.error, "WARNING", '-' * 60)
        ha.log(conf.error, "WARNING",
               "Unexpected error during loading of {}:".format(name))
        ha.log(conf.error, "WARNING", '-' * 60)
        ha.log(conf.error, "WARNING", traceback.format_exc())
        ha.log(conf.error, "WARNING", '-' * 60)
        if conf.errorfile != "STDERR" and conf.logfile != "STDOUT":
            ha.log(
                conf.logger, "WARNING",
                "Logged an error to {}".format(conf.errorfile)
            )
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
def dump_objects():
    ha.log(
        conf.logger, "INFO",
        "--------------------------------------------------"
    )
    ha.log(conf.logger, "INFO", "Objects")
    ha.log(
        conf.logger, "INFO",
        "--------------------------------------------------"
    )
    for object_ in conf.objects.keys():
        ha.log(
            conf.logger, "INFO",
            "{}: {}".format(object_, conf.objects[object_])
        )
    ha.log(
        conf.logger, "INFO",
        "--------------------------------------------------"
    )
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
ha_config = None
    while ha_config is None:
        try:
            ha_config = ha.get_ha_config()
        except:
            ha.log(
                conf.logger, "WARNING",
                "Unable to connect to Home Assistant, retrying in 5 seconds"
            )
            if conf.loglevel == "DEBUG":
                ha.log(conf.logger, "WARNING", '-' * 60)
                ha.log(conf.logger, "WARNING", "Unexpected error:")
                ha.log(conf.logger, "WARNING", '-' * 60)
                ha.log(conf.logger, "WARNING", traceback.format_exc())
                ha.log(conf.logger, "WARNING", '-' * 60)
        time.sleep(5)

    conf.version = parse_version(ha_config["version"])

    conf.ha_config = ha_config

    conf.latitude = ha_config["latitude"]
    conf.longitude = ha_config["longitude"]
    conf.time_zone = ha_config["time_zone"]

    if "elevation" in ha_config:
        conf.elevation = ha_config["elevation"]
        if "elevation" in config['AppDaemon']:
            ha.log(conf.logger, "WARNING",
                   "'elevation' directive is deprecated, please remove")
    else:
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
)

    # Check with HA to get various info

    ha_config = None
    while ha_config is None:
        try:
            ha_config = ha.get_ha_config()
        except:
            ha.log(
                conf.logger, "WARNING",
                "Unable to connect to Home Assistant, retrying in 5 seconds"
            )
            if conf.loglevel == "DEBUG":
                ha.log(conf.logger, "WARNING", '-' * 60)
                ha.log(conf.logger, "WARNING", "Unexpected error:")
                ha.log(conf.logger, "WARNING", '-' * 60)
                ha.log(conf.logger, "WARNING", traceback.format_exc())
                ha.log(conf.logger, "WARNING", '-' * 60)
        time.sleep(5)

    conf.version = parse_version(ha_config["version"])

    conf.ha_config = ha_config

    conf.latitude = ha_config["latitude"]
    conf.longitude = ha_config["longitude"]
    conf.time_zone = ha_config["time_zone"]

    if "elevation" in ha_config:
        conf.elevation = ha_config["elevation"]
        if "elevation" in config['AppDaemon']:
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
del conf.schedule[name][entry]

    except:
        ha.log(conf.error, "WARNING", '-' * 60)
        ha.log(
            conf.error, "WARNING",
            "Unexpected error during exec_schedule() for App: {}".format(name)
        )
        ha.log(conf.error, "WARNING", "Args: {}".format(args))
        ha.log(conf.error, "WARNING", '-' * 60)
        ha.log(conf.error, "WARNING", traceback.format_exc())
        ha.log(conf.error, "WARNING", '-' * 60)
        if conf.errorfile != "STDERR" and conf.logfile != "STDOUT":
            # When explicitly logging to stdout and stderr, suppress
            # log messages about writing an error (since they show up anyway)
            ha.log(
                conf.logger, "WARNING",
                "Logged an error to {}".format(conf.errorfile)
            )
        ha.log(conf.error, "WARNING", "Scheduler entry has been deleted")
        ha.log(conf.error, "WARNING", '-' * 60)

        del conf.schedule[name][entry]