From f7daa26e2d8924810576631bcf61b5b08e86d9f9 Mon Sep 17 00:00:00 2001 From: htmltiger <1429451+htmltiger@users.noreply.github.com> Date: Tue, 18 Jan 2022 02:29:33 +0000 Subject: [PATCH 1/2] support more filetypes --- custom_components/config_editor/__init__.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/custom_components/config_editor/__init__.py b/custom_components/config_editor/__init__.py index debfb0f..7d43341 100644 --- a/custom_components/config_editor/__init__.py +++ b/custom_components/config_editor/__init__.py @@ -10,7 +10,7 @@ _LOGGER = logging.getLogger(__name__) async def async_setup(hass, config): hass.components.websocket_api.async_register_command(websocket_create) - hass.states.async_set(DOMAIN+".version", 2) + hass.states.async_set(DOMAIN+".version", 3) return True @@ -22,19 +22,23 @@ async def async_setup(hass, config): vol.Required("action"): str, vol.Required("file"): str, vol.Required("data"): str, + vol.Required("ext"): str, } ) async def websocket_create(hass, connection, msg): action = msg["action"] - yamlname = "tmptest.yaml" - if (msg["file"].endswith(".yaml")): + ext = msg["ext"] + if ext not in ["yaml","py","json","conf","js","txt","log"]: + ext = "yaml" + yamlname = "tmptest."+ext + if (msg["file"].endswith("."+ext)): yamlname = msg["file"].replace("../", "/").strip('/') fullpath = hass.config.path(yamlname) def rec(p, q): r = [ f for f in os.listdir(p) if os.path.isfile(os.path.join(p, f)) and - f.endswith(".yaml") + f.endswith("."+ext) ] for j in r: p = j if q == '' else os.path.join(q, j) @@ -62,7 +66,7 @@ async def websocket_create(hass, connection, msg): finally: connection.send_result( msg["id"], - {'msg': res+': '+fullpath, 'file': yamlname, 'data': content} + {'msg': res+': '+fullpath, 'file': yamlname, 'data': content, 'ext': ext} ) elif (action == 'save'): @@ -94,8 +98,8 @@ async def websocket_create(hass, connection, msg): rec(dirnm, '') drec(dirnm, '') if (len(listyaml) < 1): - listyaml = ['list_error.yaml'] + listyaml = ['list_error.'+ext] connection.send_result( msg["id"], - {'msg': str(len(listyaml))+' File(s)', 'file': listyaml} + {'msg': str(len(listyaml))+' File(s)', 'file': listyaml, 'ext': ext} ) From a3a2524d950c54b5008ce0f32cfa95d9557e21aa Mon Sep 17 00:00:00 2001 From: htmltiger <1429451+htmltiger@users.noreply.github.com> Date: Tue, 18 Jan 2022 02:30:26 +0000 Subject: [PATCH 2/2] Update manifest.json --- custom_components/config_editor/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/config_editor/manifest.json b/custom_components/config_editor/manifest.json index 775ed3e..031c0e5 100644 --- a/custom_components/config_editor/manifest.json +++ b/custom_components/config_editor/manifest.json @@ -1,7 +1,7 @@ { "domain": "config_editor", "name": "Config Editor", - "version": "2.0", + "version": "3.0", "codeowners": ["@htmltiger"], "documentation": "https://github.com/htmltiger/config-editor-card", "issue_tracker": "https://github.com/htmltiger/config-editor/issues",