diff --git a/apps/predbat/ha.py b/apps/predbat/ha.py index 96667faa..8a64a2b3 100644 --- a/apps/predbat/ha.py +++ b/apps/predbat/ha.py @@ -38,6 +38,8 @@ def __init__(self, base): self.base = base self.log = base.log self.state_data = {} + self.slug = None + if not self.ha_key: self.log("Warn: ha_key or SUPERVISOR_TOKEN not found, you can set ha_url/ha_key in apps.yaml. Will use direct HA API") else: @@ -47,10 +49,24 @@ def __init__(self, base): self.ha_key = None else: self.log("Info: Connected to Home Assistant at {}".format(self.ha_url)) + + res = self.api_call("/addons/self/info") + if res: + # get add-on slug name which is the actual directory name under /addon_configs that /config is mounted to + self.config_root_p = "/addon_configs/" + res["data"]["slug"] + self.slug = res["data"]["slug"] + self.log("Info: Add-on slug is {}".format(self.slug)) + self.base.create_task(self.socketLoop()) self.websocket_active = True self.log("Info: Web Socket task started") + def get_slug(self): + """ + Get the add-on slug. + """ + return self.slug + async def socketLoop(self): """ Web socket loop for HA interface diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 59815781..41106eba 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -32,7 +32,7 @@ import asyncio import json -THIS_VERSION = "v8.3.3" +THIS_VERSION = "v8.3.4" PREDBAT_FILES = ["predbat.py", "config.py", "prediction.py", "utils.py", "inverter.py", "ha.py", "download.py", "unit_test.py"] from download import predbat_update_move, predbat_update_download, check_install @@ -10855,15 +10855,13 @@ def initialize(self): try: self.reset() self.ha_interface = HAInterface(self) - self.config_root_p = self.config_root - - # Get add-on info by making API call to HA supervisor - res = self.ha_interface.api_call("/addons/self/info") - if res: - # get add-on slug name which is the actual directory name under /addon_configs that /config is mounted to + # Printable config root + self.config_root_p = self.config_root + slug = self.ha_interface.get_slug() + if slug: # and use slug name to determine printable config_root pathname when writing debug info to the log file - self.config_root_p = "/addon_configs/" + res["data"]["slug"] + self.config_root_p = "/addon_configs/" + slug self.log("Config root is {} and printable config_root_p is now {}".format(self.config_root, self.config_root_p))