Пример #1
0
    async def handle_reload(call):
        #Service call to reload Dwains Theme config
        _LOGGER.debug("reload config")

        #Main config
        config_new = OrderedDict()
        for fname in loader._find_files(
                hass.config.path("dwains-theme/configs/"), "*.yaml"):
            loaded_yaml = load_yaml(fname)
            if isinstance(loaded_yaml, dict):
                config_new.update(loaded_yaml)

        dwains_theme_config.update(config_new)

        #Translations
        language = dwains_theme_config["global"]["language"]
        translations = load_yaml(
            hass.config.path("dwains-theme/translations/" + language +
                             ".yaml"))

        dwains_theme_translations.update(translations[language])

        #Icons
        icons = load_yaml(hass.config.path("dwains-theme/configs/icons.yaml"))
        dwains_theme_icons.clear()
        if isinstance(icons, dict):
            if ("icons" in icons):
                dwains_theme_icons.update(icons["icons"])

        #Reload lovelace
        _LOGGER.debug("reload lovelace")
        #await hass.data["lovelace"].async_load(True)
        #Use browser_mod to reload lovelace (because it can)
        await hass.services.async_call("browser_mod", "lovelace_reload")
Пример #2
0
def reload_configuration(hass):
    if os.path.exists(hass.config.path("dwains-dashboard/configs")):
        #Main config
        config_new = OrderedDict()
        for fname in loader._find_files(hass.config.path("dwains-dashboard/configs/"), "*.yaml"):
            loaded_yaml = load_yaml(fname)
            if isinstance(loaded_yaml, dict):
                config_new.update(loaded_yaml)

        dwains_dashboard_config.update(config_new)

        #Set defaults for safety_ok_strings and battery_empty_strings if not set in globals.yaml
        if (dwains_dashboard_config["global"]):
            if ("safety_ok_strings" not in dwains_dashboard_config["global"]):
                dwains_dashboard_config["global"].update(
                    [
                        ("safety_ok_strings", ['Ok', 'Idle', 'off'])
                    ]
                )
            if ("battery_empty_strings" not in dwains_dashboard_config["global"]):
                dwains_dashboard_config["global"].update(
                    [
                        ("battery_empty_strings", ['unavailable'])
                    ]
                )
        else:
            dwains_dashboard_config["global"] = OrderedDict(
                [
                    ("safety_ok_strings", ['Ok', 'Idle', 'off']),
                    ("battery_empty_strings", ['unavailable'])
                ]
            )

        if os.path.exists(hass.config.path("custom_components/dwains_dashboard/.installed")):
            installed = "true"
        else:
            installed = "false"

        dwains_dashboard_global.update(
            [
                ("installed", installed)
            ]
        )

        #Translations
        #language = dwains_dashboard_config["global"]["language"];
        #translations = load_yaml(hass.config.path("custom_components/dwains_dashboard/lovelace/translations/"+language+".yaml"))
        #dwains_dashboard_translations.update(translations[language])

        #Icons
        icons = load_yaml(hass.config.path("dwains-dashboard/configs/icons.yaml"))
        dwains_dashboard_icons.clear()
        if isinstance(icons, dict):
            if ("icons" in icons):
                dwains_dashboard_icons.update(icons["icons"]);

    hass.bus.async_fire("dwains_dashboard_reload")
Пример #3
0
 def _include_dir_list_yaml(loader: CustomLoader,
                            node: hass_loader.yaml.Node) -> LoadedYAML:
     """Handle !include_dir_list tag"""
     node_values = process_node(loader, node)
     loc: str = os.path.join(os.path.dirname(loader.name), node_values[0])
     return [
         load_yaml(f, node_values[1], loader._user_id, None,
                   loader._translations)
         for f in hass_loader._find_files(loc, "*.yaml")
         if os.path.basename(f) != hass_loader.SECRET_YAML
     ]
def _include_dir_list_yaml(
    loader: EnhancedLoader, node: hass_loader.yaml.Node
) -> LoadedYAML:
    """Handle !include_dir_list tag"""

    node_values = process_node(loader, node)
    loc: str = os.path.join(os.path.dirname(loader.name), node_values[0])
    return [
        load_yaml(f, node_values[1], node_values[2])
        for f in hass_loader._find_files(loc, "*.yaml")
        if os.path.basename(f) != hass_loader.SECRET_YAML
    ]
def _include_dir_named_yaml(
    loader: EnhancedLoader, node: hass_loader.yaml.Node
) -> LoadedYAML:
    """Handle !include_dir_named tag"""

    node_values = process_node(loader, node)
    mapping: OrderedDictType = OrderedDict()
    loc: str = os.path.join(os.path.dirname(loader.name), node_values[0])
    for fname in hass_loader._find_files(loc, "*.yaml"):
        filename = os.path.splitext(os.path.basename(fname))[0]
        if os.path.basename(fname) == hass_loader.SECRET_YAML:
            continue
        mapping[filename] = load_yaml(fname, node_values[1], node_values[2])
    return hass_loader._add_reference(mapping, loader, node)
def _include_dir_merge_list_yaml(
    loader: EnhancedLoader, node: hass_loader.yaml.Node
) -> LoadedYAML:
    """Handle !include_dir_merge_list tag"""

    node_values = process_node(loader, node)
    loc: str = os.path.join(os.path.dirname(loader.name), node_values[0])
    merged_list: List[hass_loader.JSON_TYPE] = []
    for fname in hass_loader._find_files(loc, "*.yaml"):
        if os.path.basename(fname) == hass_loader.SECRET_YAML:
            continue
        loaded_yaml = load_yaml(fname, node_values[1], node_values[2])
        if isinstance(loaded_yaml, list):
            merged_list.extend(loaded_yaml)
    return hass_loader._add_reference(merged_list, loader, node)
Пример #7
0
def process_yaml(hass, config_entry):

    #_LOGGER.warning('Start of function to process all yaml files!')

    #Check for HKI intallation
    if os.path.exists(hass.config.path("hki-user/config")):
        _LOGGER.warning("HKI Installed!")
        for fname in loader._find_files(hass.config.path("hki-user/config"),
                                        "*.yaml"):
            loaded_yaml = load_yamll(fname)
            if isinstance(loaded_yaml, dict):
                llgen_config.update(loaded_yaml)

    #_LOGGER.error(llgen_config)

    for fname in os.listdir(
            hass.config.path(
                "custom_components/dwains_dashboard/installation/ignorethisfolder"
            )):
        if not os.path.isfile(
                hass.config.path("dwains-dashboard/configs/" + fname)):
            if fname.endswith('.yaml'):
                _LOGGER.debug("Copy: " + fname)
                os.makedirs(hass.config.path("dwains-dashboard/addons"),
                            exist_ok=True)
                os.makedirs(hass.config.path("dwains-dashboard/configs"),
                            exist_ok=True)
                shutil.copy2(
                    hass.config.path(
                        "custom_components/dwains_dashboard/installation/ignorethisfolder/"
                        + fname), hass.config.path("dwains-dashboard/configs"))

    if os.path.exists(hass.config.path("dwains-dashboard/configs")):

        entity_popups = OrderedDict()
        # Get custom entity popups if set
        if ("customize_path" in config_entry.options):
            if os.path.exists(
                    hass.config.path(config_entry.options["customize_path"])):
                #_LOGGER.warning("Process customize.yaml")
                customize_file = load_yamll(
                    hass.config.path(config_entry.options["customize_path"]))

                for key, values in customize_file.items():
                    if ("dwains_dashboard_popup" in values):
                        data = values.get("dwains_dashboard_popup_data", "")
                        title = values.get("dwains_dashboard_popup_title", "")
                        entity_popups[key] = OrderedDict({
                            "popup_path":
                            values["dwains_dashboard_popup"],
                            "popup_data":
                            data,
                            "popup_title":
                            title
                        })

        dwains_dashboard_customize.update([("entity_popups", entity_popups)])
        #_LOGGER.error(dwains_dashboard_customize)

        #Main config
        for fname in loader._find_files(
                hass.config.path("dwains-dashboard/configs/"), "*.yaml"):
            loaded_yaml = load_yamll(fname)
            if isinstance(loaded_yaml, dict):
                dwains_dashboard_config.update(loaded_yaml)

        #_LOGGER.error(dwains_dashboard_config)

        #Set defaults for safety_ok_strings and battery_empty_strings if not set in globals.yaml
        if (not dwains_dashboard_config["global"]):
            #_LOGGER.error("empty")
            dwains_dashboard_config["global"] = OrderedDict([
                ("safety_ok_strings", ['Ok', 'Idle', 'off']),
                ("battery_empty_strings", ['unavailable'])
            ])
        else:
            #_LOGGER.error("not empty")
            if ("safety_ok_strings" not in dwains_dashboard_config["global"]):
                dwains_dashboard_config["global"].update([
                    ("safety_ok_strings", ['Ok', 'Idle', 'off'])
                ])
            if ("battery_empty_strings"
                    not in dwains_dashboard_config["global"]):
                dwains_dashboard_config["global"].update([
                    ("battery_empty_strings", ['unavailable'])
                ])
        # if ("show_covers" not in dwains_dashboard_config["global"]):
        #     dwains_dashboard_config["global"].update(
        #         [
        #             ("show_covers", ['open'])
        #         ]
        #     )

        #_LOGGER.error(dwains_dashboard_config)

        #Translations
        if ("language" in config_entry.options):
            language = LANGUAGES[config_entry.options["language"]]
        else:
            language = "en"
        translations = load_yamll(
            hass.config.path(
                "custom_components/dwains_dashboard/lovelace/translations/" +
                language + ".yaml"))

        dwains_dashboard_translations.update(translations[language])

        #Load themes
        themes = OrderedDict()
        for fname in loader._find_files(
                hass.config.path(
                    "custom_components/dwains_dashboard/lovelace/themefiles"),
                "*.yaml"):
            loaded_yaml = load_yamll(fname)
            if isinstance(loaded_yaml, dict):
                themes.update(loaded_yaml)

        if ("theme" in config_entry.options):
            config_theme = config_entry.options["theme"]
        else:
            config_theme = "Auto Mode (Dark/Light)"

        if ("primary_color" in config_entry.options):
            config_primary_color = config_entry.options["primary_color"]
        else:
            config_primary_color = "#299ec2"

        if os.path.exists(
                hass.config.path(
                    "custom_components/dwains_dashboard/.installed")):
            installed = "true"
        else:
            installed = "false"

        dwains_dashboard_global.update([("version", VERSION),
                                        ("theme", config_theme),
                                        ("primary_color",
                                         config_primary_color),
                                        ("themes", json.dumps(themes)),
                                        ("installed", installed)])

        #_LOGGER.error(dwains_dashboard_global)

        #Icons
        icons = load_yamll(
            hass.config.path("dwains-dashboard/configs/icons.yaml"))
        dwains_dashboard_icons.clear()
        if isinstance(icons, dict):
            if ("icons" in icons):
                dwains_dashboard_icons.update(icons["icons"])

        hass.bus.async_fire("dwains_dashboard_reload")

    async def handle_reload(call):
        #Service call to reload Dwains Theme config
        _LOGGER.debug("Reload Dwains Dashboard Configuration")

        reload_configuration(hass)

    # Register service dwains_dashboard.reload
    hass.services.async_register(DOMAIN, "reload", handle_reload)

    async def handle_installed(call):
        #Service call to Change the installed key in global config for Dwains dashboard
        _LOGGER.debug("Handle installed")

        path = hass.config.path(
            "custom_components/dwains_dashboard/.installed")

        if not os.path.exists(path):
            _LOGGER.debug("Create .installed file")
            open(path, 'w').close()

        reload_configuration(hass)

    # Register service dwains_dashboard.installed
    hass.services.async_register(DOMAIN, "installed", handle_installed)
def process_yaml(hass, config_entry):
    #_LOGGER.warning('Start of function to process all yaml files!')

    #Check for HKI intallation
    if os.path.exists(hass.config.path("hki-user/config")):
        _LOGGER.warning("HKI Installed!")
        for fname in loader._find_files(hass.config.path("hki-user/config"),
                                        "*.yaml"):
            loaded_yaml = load_yamll(fname)
            if isinstance(loaded_yaml, dict):
                llgen_config.update(loaded_yaml)

    if os.path.exists(hass.config.path("dwains-dashboard/configs")):
        if os.path.isdir(
                hass.config.path("dwains-dashboard/configs/more_pages")):
            for subdir in os.listdir(
                    hass.config.path("dwains-dashboard/configs/more_pages")):
                #Lets check if there is a page.yaml in the more_pages folder
                if os.path.exists(
                        hass.config.path(
                            "dwains-dashboard/configs/more_pages/" + subdir +
                            "/page.yaml")):
                    #Page.yaml exists now check if there is a config.yaml otherwise create it
                    if not os.path.exists(
                            hass.config.path(
                                "dwains-dashboard/configs/more_pages/" +
                                subdir + "/config.yaml")):
                        with open(
                                hass.config.path(
                                    "dwains-dashboard/configs/more_pages/" +
                                    subdir + "/config.yaml"), 'w') as f:
                            page_config = OrderedDict()
                            page_config.update({
                                "name": subdir,
                                "icon": "mdi:puzzle"
                            })
                            yaml.safe_dump(page_config,
                                           f,
                                           default_flow_style=False)
                            dwains_dashboard_more_pages[subdir] = {
                                "name":
                                subdir,
                                "icon":
                                "mdi:puzzle",
                                "path":
                                "dwains-dashboard/configs/more_pages/" +
                                subdir + "/page.yaml",
                            }
                    else:
                        with open(
                                hass.config.path(
                                    "dwains-dashboard/configs/more_pages/" +
                                    subdir + "/config.yaml")) as f:
                            filecontent = yaml.safe_load(f)
                            dwains_dashboard_more_pages[subdir] = {
                                "name":
                                filecontent["name"],
                                "icon":
                                filecontent["icon"],
                                "path":
                                "dwains-dashboard/configs/more_pages/" +
                                subdir + "/page.yaml",
                            }

        hass.bus.async_fire("dwains_dashboard_reload")

    async def handle_reload(call):
        #Service call to reload Dwains Theme config
        _LOGGER.warning("Reload Dwains Dashboard Configuration")

        reload_configuration(hass)

    # Register service dwains_dashboard.reload
    hass.services.async_register(DOMAIN, "reload", handle_reload)