mirror of
https://github.com/junkfix/config-editor.git
synced 2025-09-21 00:32:10 +02:00
Update __init__.py
This commit is contained in:
parent
7be6a6be4a
commit
6b0748d523
|
@ -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 = ''
|
||||
|
|
Loading…
Reference in a new issue