Merge pull request #6 from htmltiger/htmltiger-patch-1

support all file types
This commit is contained in:
htmltiger 2022-03-11 21:21:45 +00:00 committed by GitHub
commit f101b537be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View file

@ -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", 3)
hass.states.async_set(DOMAIN+".version", 4)
return True
@ -28,17 +28,18 @@ async def async_setup(hass, config):
async def websocket_create(hass, connection, msg):
action = msg["action"]
ext = msg["ext"]
if ext not in ["yaml","py","json","conf","js","txt","log"]:
if ext not in ["yaml","py","json","conf","js","txt","log","css","all"]:
ext = "yaml"
yamlname = "tmptest."+ext
if (msg["file"].endswith("."+ext)):
yamlname = msg["file"].replace("../", "/").strip('/')
fullpath = hass.config.path(yamlname)
def extok(e):
if len(e)<2:
return False
return ( ext == 'all' or e.endswith("."+ext) )
def rec(p, q):
r = [
f for f in os.listdir(p) if os.path.isfile(os.path.join(p, f)) and
f.endswith("."+ext)
extok(f)
]
for j in r:
p = j if q == '' else os.path.join(q, j)
@ -49,10 +50,16 @@ async def websocket_create(hass, connection, msg):
v = os.path.join(r, d)
if os.path.isdir(v):
p = d if s == '' else os.path.join(s, d)
if(p.count(os.sep) < 2) and p != 'custom_components':
if(p.count(os.sep) < 3) and ( ext == 'all' or p != 'custom_components' ):
rec(v, p)
drec(v, p)
yamlname = msg["file"].replace("../", "/").strip('/')
if not extok(msg["file"]):
yamlname = "temptest."+ext
fullpath = hass.config.path(yamlname)
if (action == 'load'):
_LOGGER.info('Loading '+fullpath)
content = ''

View file

@ -1,7 +1,7 @@
{
"domain": "config_editor",
"name": "Config Editor",
"version": "3.0",
"version": "4.0",
"codeowners": ["@htmltiger"],
"documentation": "https://github.com/htmltiger/config-editor-card",
"issue_tracker": "https://github.com/htmltiger/config-editor/issues",