Skip to content

Commit

Permalink
Added script reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
danielperna84 committed Oct 12, 2017
1 parent 5310007 commit 1017da3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 0.2.1 (2017-10-12)
- Added script reloading

Version 0.2.0 (2017-09-25)
- Update MaterializeCSS to 0.100.1 @jmart518
- Added git push option @danielperna84
Expand Down
39 changes: 39 additions & 0 deletions configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@
<li class="divider"></li>
<!--<li><a href="#modal_check_config">Check HASS Configuration</a></li>-->
<li><a class="modal-trigger" href="#modal_reload_automations">Reload automations</a></li>
<li><a class="modal-trigger" href="#modal_reload_scripts">Reload scripts</a></li>
<li><a class="modal-trigger" href="#modal_reload_groups">Reload groups</a></li>
<li><a class="modal-trigger" href="#modal_reload_core">Reload core</a></li>
<li><a class="modal-trigger" href="#modal_restart">Restart HASS</a></li>
Expand All @@ -618,6 +619,7 @@
<li class="divider"></li>
<!--<li><a href="#modal_check_config">Check HASS Configuration</a></li>-->
<li><a class="modal-trigger" href="#modal_reload_automations">Reload automations</a></li>
<li><a class="modal-trigger" href="#modal_reload_scripts">Reload scripts</a></li>
<li><a class="modal-trigger" href="#modal_reload_groups">Reload groups</a></li>
<li><a class="modal-trigger" href="#modal_reload_core">Reload core</a></li>
<li><a class="modal-trigger" href="#modal_restart">Restart HASS</a></li>
Expand Down Expand Up @@ -1276,6 +1278,16 @@
<a onclick="reload_automations()" class=" modal-action modal-close waves-effect waves-green btn-flat light-blue-text">Yes</a>
</div>
</div>
<div id="modal_reload_scripts" class="modal">
<div class="modal-content">
<h4 class="grey-text text-darken-3">Reload scripts<i class="mdi mdi-settings right grey-text text-darken-3" style="font-size: 2rem;"></i></h4>
<p>Do you want to reload the scripts?</p>
</div>
<div class="modal-footer">
<a class=" modal-action modal-close waves-effect waves-red btn-flat light-blue-text">No</a>
<a onclick="reload_scripts()" class=" modal-action modal-close waves-effect waves-green btn-flat light-blue-text">Yes</a>
</div>
</div>
<div id="modal_reload_groups" class="modal">
<div class="modal-content">
<h4 class="grey-text text-darken-3">Reload groups<i class="mdi mdi-settings right grey-text text-darken-3" style="font-size: 2rem;"></i></h4>
Expand Down Expand Up @@ -2287,6 +2299,13 @@
});
}
function reload_scripts() {
$.get("api/reload_scripts", function (resp) {
var $toastContent = $("<div>Scripts reloaded</div>");
Materialize.toast($toastContent, 2000);
});
}
function reload_groups() {
$.get("api/reload_groups", function (resp) {
var $toastContent = $("<div><pre>Groups reloaded</pre></div>");
Expand Down Expand Up @@ -2996,6 +3015,26 @@ def do_GET(self):
res['restart'] = str(err)
self.wfile.write(bytes(json.dumps(res), "utf8"))
return
elif req.path == '/api/reload_scripts':
LOG.info("/api/reload_scripts")
self.send_header('Content-type', 'text/json')
self.end_headers()
res = {"reload_scripts": False}
try:
headers = {
"Content-Type": "application/json"
}
if HASS_API_PASSWORD:
headers["x-ha-access"] = HASS_API_PASSWORD
req = urllib.request.Request("%sservices/script/reload" % HASS_API, headers=headers, method='POST')
with urllib.request.urlopen(req) as response:
LOG.debug(json.loads(response.read().decode('utf-8')))
res['service'] = "called successfully"
except Exception as err:
LOG.warning(err)
res['restart'] = str(err)
self.wfile.write(bytes(json.dumps(res), "utf8"))
return
elif req.path == '/api/reload_groups':
LOG.info("/api/reload_groups")
self.send_header('Content-type', 'text/json')
Expand Down
19 changes: 19 additions & 0 deletions dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@
<li class="divider"></li>
<!--<li><a href="#modal_check_config">Check HASS Configuration</a></li>-->
<li><a class="modal-trigger" href="#modal_reload_automations">Reload automations</a></li>
<li><a class="modal-trigger" href="#modal_reload_scripts">Reload scripts</a></li>
<li><a class="modal-trigger" href="#modal_reload_groups">Reload groups</a></li>
<li><a class="modal-trigger" href="#modal_reload_core">Reload core</a></li>
<li><a class="modal-trigger" href="#modal_restart">Restart HASS</a></li>
Expand All @@ -542,6 +543,7 @@
<li class="divider"></li>
<!--<li><a href="#modal_check_config">Check HASS Configuration</a></li>-->
<li><a class="modal-trigger" href="#modal_reload_automations">Reload automations</a></li>
<li><a class="modal-trigger" href="#modal_reload_scripts">Reload scripts</a></li>
<li><a class="modal-trigger" href="#modal_reload_groups">Reload groups</a></li>
<li><a class="modal-trigger" href="#modal_reload_core">Reload core</a></li>
<li><a class="modal-trigger" href="#modal_restart">Restart HASS</a></li>
Expand Down Expand Up @@ -1200,6 +1202,16 @@ <h4 class="grey-text text-darken-3">Reload automations<i class="mdi mdi-settings
<a onclick="reload_automations()" class=" modal-action modal-close waves-effect waves-green btn-flat light-blue-text">Yes</a>
</div>
</div>
<div id="modal_reload_scripts" class="modal">
<div class="modal-content">
<h4 class="grey-text text-darken-3">Reload scripts<i class="mdi mdi-settings right grey-text text-darken-3" style="font-size: 2rem;"></i></h4>
<p>Do you want to reload the scripts?</p>
</div>
<div class="modal-footer">
<a class=" modal-action modal-close waves-effect waves-red btn-flat light-blue-text">No</a>
<a onclick="reload_scripts()" class=" modal-action modal-close waves-effect waves-green btn-flat light-blue-text">Yes</a>
</div>
</div>
<div id="modal_reload_groups" class="modal">
<div class="modal-content">
<h4 class="grey-text text-darken-3">Reload groups<i class="mdi mdi-settings right grey-text text-darken-3" style="font-size: 2rem;"></i></h4>
Expand Down Expand Up @@ -2211,6 +2223,13 @@ <h4 class="grey-text text-darken-3"><a class="black-text" href="https://github.c
});
}

function reload_scripts() {
$.get("api/reload_scripts", function (resp) {
var $toastContent = $("<div>Scripts reloaded</div>");
Materialize.toast($toastContent, 2000);
});
}

function reload_groups() {
$.get("api/reload_groups", function (resp) {
var $toastContent = $("<div><pre>Groups reloaded</pre></div>");
Expand Down

0 comments on commit 1017da3

Please sign in to comment.