mirror of
https://github.com/junkfix/config-editor.git
synced 2026-02-22 18:26:40 +01:00
Merge pull request #3 from htmltiger/htmltiger-patch-1
Support more filetypes
This commit is contained in:
commit
da0b63609c
|
|
@ -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}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue