Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #230 from DewGew/UI-SettingsPage
Browse files Browse the repository at this point in the history
UI Settings page
  • Loading branch information
DewGew authored Nov 26, 2020
2 parents e8994f8 + 35d63ef commit 5953e82
Show file tree
Hide file tree
Showing 11 changed files with 713 additions and 77 deletions.
2 changes: 1 addition & 1 deletion const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

"""Constants for Google Assistant."""
VERSION = '1.9.5'
VERSION = '1.9.6'
PUBLIC_URL = 'https://[your public url]'
CONFIGFILE = 'config/config.yaml'
LOGFILE = 'dzga.log'
Expand Down
3 changes: 1 addition & 2 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ def uptime():
if len(string) > 0 or hours > 0:
string += str(hours) + " " + (hours == 1 and "hour" or "hours") + ", "
if len(string) > 0 or minutes > 0:
string += str(minutes) + " " + (minutes == 1 and "minute" or "minutes") + ", "
string += str(seconds) + " " + (seconds == 1 and "second" or "seconds")
string += str(minutes) + " " + (minutes == 1 and "minute" or "minutes")

return string

Expand Down
39 changes: 27 additions & 12 deletions smarthome.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
import subprocess
import sys
import threading
import yaml
from collections.abc import Mapping
from itertools import product
from pid import PidFile
Expand Down Expand Up @@ -737,22 +737,21 @@ def settings(self, s):
s.redirect('login?redirect_uri={0}'.format('settings'))
return

enableReport = ReportState.enable_report_state()
update = checkupdate()
confJSON = json.dumps(configuration)
public_url = getTunnelUrl()
message = ''
meta = '<!-- <meta http-equiv="refresh" content="5"> -->'
code = readFile(os.path.join(FILE_DIR, CONFIGFILE))

templatepage = env.get_template('home.html')
s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
conf=confJSON, public_url=public_url, update=update,
conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

def settings_post(self, s):
enableReport = ReportState.enable_report_state()
update = checkupdate()
confJSON = json.dumps(configuration)
public_url = getTunnelUrl()
code = readFile(os.path.join(FILE_DIR, CONFIGFILE))
meta = '<!-- <meta http-equiv="refresh" content="5"> -->'
Expand All @@ -761,12 +760,12 @@ def settings_post(self, s):
textToSave = s.form.get("save", None)
codeToSave = textToSave.replace("+", " ")
saveFile(CONFIGFILE, codeToSave)
message = 'Config saved'
message = 'Configuration saved. Restart DZGA for the settings to take effect'
logger.info(message)
logs = readFile(os.path.join(logfilepath, LOGFILE))
templatepage = env.get_template('home.html')
s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
conf=confJSON, public_url=public_url, update=update,
conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

if s.form.get("backup"):
Expand All @@ -776,7 +775,7 @@ def settings_post(self, s):
logger.info(message)
templatepage = env.get_template('home.html')
s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
conf=confJSON, public_url=public_url, update=update,
conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

if s.form.get("restart"):
Expand All @@ -785,7 +784,7 @@ def settings_post(self, s):

templatepage = env.get_template('home.html')
s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
conf=confJSON, public_url=public_url, update=update,
conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))
restartServer()

Expand All @@ -801,15 +800,15 @@ def settings_post(self, s):
message = 'Add Homegraph api key or a Homegraph Service Account json file to sync devices in the UI! You can still sync by voice eg. "Hey Google, Sync my devices".'
templatepage = env.get_template('home.html')
s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
conf=confJSON, public_url=public_url, update=update,
conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

if s.form.get("reload"):
message = ''

templatepage = env.get_template('home.html')
s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
conf=confJSON, public_url=public_url, update=update,
conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

if s.form.get("deletelogs"):
Expand All @@ -821,7 +820,7 @@ def settings_post(self, s):
message = 'Logs removed'
templatepage = env.get_template('home.html')
s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
conf=confJSON, public_url=public_url, update=update,
conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

if s.form.get("update"):
Expand All @@ -832,11 +831,27 @@ def settings_post(self, s):

templatepage = env.get_template('home.html')
s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
conf=confJSON, public_url=public_url, update=update,
conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

subprocess.call(['pip3', 'install','-r', os.path.join(FILE_DIR, 'requirements/pip-requirements.txt')])
restartServer()

if s.form.get("saveSettings"):
savedSettings = json.loads(s.form.get("saveSettings", None))
with open(os.path.join(FILE_DIR, CONFIGFILE), 'r') as conf_file:
newsettings = yaml.safe_load(conf_file)
newsettings.update(savedSettings)

saveFile(CONFIGFILE, yaml.safe_dump(newsettings, allow_unicode=True))
logger.info(yaml.dump(savedSettings))
message = 'Settings saved. Restart DZGA for the settings to take effect'
logger.info(message)
logs = readFile(os.path.join(logfilepath, LOGFILE))
templatepage = env.get_template('home.html')
s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))


def smarthome_sync(self, payload, token):
Expand Down
22 changes: 18 additions & 4 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ <h5 class="modal-title" id="modalLabel">Security Risk</h5>
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu2">
<i class="material-icons">content_paste</i>
<p>Configuration</p>
<a class="nav-link" data-toggle="tab" href="#menu5">
<i class="material-icons">settings</i>
<p>Settings</p>
</a>
</li>
<li class="nav-item">
Expand All @@ -78,6 +78,12 @@ <h5 class="modal-title" id="modalLabel">Security Risk</h5>
<p>Help</p>
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu2">
<i class="material-icons">content_paste</i>
<p>Configuration</p>
</a>
</li>
</ul>
</div>
</div>
Expand All @@ -103,7 +109,15 @@ <h5 class="modal-title" id="modalLabel">Security Risk</h5>
<script src="static/js/core/jquery.min.js"></script>
<script src="static/js/core/popper.min.js"></script>
<script src="static/js/core/bootstrap-material-design.min.js"></script>
<script src= "static/js/plugins/perfect-scrollbar.jquery.min.js"></script>
<script src="static/js/plugins/perfect-scrollbar.jquery.min.js"></script>
<script src="static/js/plugins/jquery.validate.min.js"></script>
<script src="static/js/plugins/moment.min.js"></script>
<script src="static/js/plugins/sweetalert2.js"></script>
<script src="static/js/plugins/jquery.bootstrap-wizard.js"></script>
<script src="static/js/plugins/bootstrap-selectpicker.js"></script>
<script src="static/js/plugins/bootstrap-datetimepicker.min.js"></script>
<script src="static/js/plugins/bootstrap-tagsinput.js"></script>
<script src="static/js/plugins/arrive.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/yaml/yaml.js"></script>
Expand Down
183 changes: 169 additions & 14 deletions templates/help.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,175 @@
<div id="menu3" class="tab-pane fade" role="tabpanel">
<div class="col-md-8">
<div class="card">
<div class="card-header card-header-primary">
<h4 class="card-title">Help</h4>
<p class="card-category"></p>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header card-header-primary">
<h4 class="card-title">Help</h4>
<p class="card-category"></p>
</div>
<div class="card-body">
<p>For help or more information about configuration and to setup Action on Google:</br>
<a href="https://github.com/DewGew/Domoticz-Google-Assistant/wiki" target="_blank" rel="noopener">Domoticz Google Assistant wiki</a> or at
<a href="https://discordapp.com/invite/AmJV6AC" target="_blank" rel="noopener" aria-label="Discord">Discord</a></p>

<h6>Manual update</h6>
<p><kbd>bash &#60;(curl -s https://raw.githubusercontent.com/DewGew/dzga-installer/master/install.sh)</kbd></p>

</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header card-header-success">
<h4 class="card-title">Device Configuraton</h4>
<p class="card-category"></p>
</div>
<div class="card-body">
<p>
Nicknames, rooms, ack and report_state can also be set in the Domoticz user interface. New function hide ,hide devices from Google Assistant still but can still see this in UI as type 'Hidden'. Simply put the device configuration in the device description, in a section between 'voicecontrol' tags like:
<br>
<code>&lt;voicecontrol&gt;<br>
&nbsp;&nbsp;nicknames = Kitchen Blind One, Left Blind, Blue Blind<br>
&nbsp;&nbsp;room = Kitchen<br>
&nbsp;&nbsp;ack = True<br>
&nbsp;&nbsp;report_state = False<br>
&nbsp;&nbsp;hide = True<br>
&lt;/voicecontrol&gt;<br>
</code>
</p>
<p>
Other parts of the description are ignored, so you can still leave other useful descriptions. Every variable should be on a separate line. If there is no such configuration in the Domoticz device it will still try the config:
<br><code>
Device_Config:<br>
&nbsp;&nbsp;123:<br>
&nbsp;&nbsp;&nbsp;&nbsp;ack: true<br>
&nbsp;&nbsp;&nbsp;&nbsp;room: 'Livingroom'<br>
&nbsp;&nbsp;&nbsp;&nbsp;nicknames:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- 'Celing light'<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- 'Smart light'<br>
&nbsp;&nbsp;234:<br>
&nbsp;&nbsp;&nbsp;&nbsp;room: 'Bedroom'<br>
&nbsp;&nbsp;&nbsp;&nbsp;report_state: false<br>
&nbsp;&nbsp;&nbsp;&nbsp;hide: true<br>
<br>
Scene_Config:<br>
&nbsp;&nbsp;3:<br>
&nbsp;&nbsp;&nbsp;&nbsp;room: 'Kitchen'<br>
&nbsp;&nbsp;&nbsp;&nbsp;nicknames:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- 'Cool scene'<br>
</code>
</p>
</div>
</div>
</div>
</div>
<div class="card-body">
<p>For help or more information about configuration and to setup Action on Google:</br>
<a href="https://github.com/DewGew/Domoticz-Google-Assistant/wiki" target="_blank" rel="noopener">Domoticz Google Assistant wiki</a> or at
<a href="https://discordapp.com/invite/AmJV6AC" target="_blank" rel="noopener" aria-label="Discord">Discord</a></p>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header card-header-primary">
<h4 class="card-title">Device Type</h4>
<p class="card-category"></p>
</div>
<div class="card-body">
<p>
Function to change device type, icon and some behavior depending on the device (e.g open/close instead of on/off).<br>
<code>
&lt;voicecontrol&gt;<br>
&nbsp;&nbsp;devicetype = oven<br>
&lt;/voicecontrol&gt;<br>
</code>
or in config.yaml:<br>
<code>
Device_Config:<br>
&nbsp;&nbsp;456:<br>
&nbsp;&nbsp;&nbsp;&nbsp;devicetype: 'oven'<br>
</code>
</p>
<p>
Light or Switch devices can choose types from:<br>

<h6>Manual update</h6>
<p><kbd>bash &#60;(curl -s https://raw.githubusercontent.com/DewGew/dzga-installer/master/install.sh)</kbd></p>

<code>light, ac_unit, bathtub, coffeemaker, dishwasher, dryer, fan, heater, kettle, media,<br>microwave, outlet, oven, speaker, switch, vacuum, washer, waterheater, window, door, gate, garage </code>.
</p>
<p>For heater, kettle, waterheater, oven you can still use <code>merge_thermo_idx</code> to merge thermostat to control temperature.</p>
<p>Door Contact devices can choose window, gate or garage.</p>
<p>Blind devices can choose window, door, gate or garage.</p>
<p>Selector devices can choose only vacuum</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header card-header-warning">
<h4 class="card-title">Thermostat Devices</h4>
<p class="card-category"></p>
</div>
<div class="card-body">
<p><b>For thermostat devices only.</b><br>
Function to merge actual temperature from another temp device or modes from selector device to thermostat. Merged device will automaticly hidden. Levels from selector device supported is: Off - Heat - Cool - Auto - Eco.
Bug Thermostat idx must be a number above Temp/selector idx.<br>
<code>
&lt;voicecontrol&gt;<br>
&nbsp;&nbsp;actual_temp_idx = 123<br>
&nbsp;&nbsp;selector_modes_idx = 234<br>
&lt;/voicecontrol&gt;<br>
</code>
or in config.yaml:<br>
<code>
Device_Config:<br>
&nbsp;&nbsp;456:<br>
&nbsp;&nbsp;&nbsp;&nbsp;actual_temp_idx: '123'<br>
&nbsp;&nbsp;&nbsp;&nbsp;selector_modes_idx: '234'<br>
</code>

<p><b>For heater/waterheater/kettle/oven devices only.</b><br>
Function to merge thermostat device to control temperature. Merged device will automaticly hidden.
Bug Thermostat idx must be a number above Temp/selector idx.
<code>
&lt;voicecontrol&gt;<br>
&nbsp;&nbsp;merge_thermo_idx = 123<br>
&lt;/voicecontrol&gt;<br>
</code>
or in config.yaml:<br>
<code>
Device_Config:<br>
&nbsp;&nbsp;456:<br>
&nbsp;&nbsp;&nbsp;&nbsp;merge_thermo_idx: '123'<br>
</code>
</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header card-header-warning">
<h4 class="card-title">Security Device</h4>
<p class="card-category"></p>
</div>
<div class="card-body">
<p>User-friendly name for the level in your language.. See: https://developers.google.com/actions/smarthome/traits/#supported-languages<br>
<code>
Armhome:<br>
&nbsp;&nbsp;level_synonym:<br>
&nbsp;&nbsp;&nbsp;&nbsp;- 'zuhause und bewachen'<br>
&nbsp;&nbsp;&nbsp;&nbsp;- 'Level 1'<br>
&nbsp;&nbsp;&nbsp;&nbsp;- 'SL1'<br>
&nbsp;&nbsp;lang: 'de'<br>
Armaway:<br>
&nbsp;&nbsp;level_synonym:<br>
&nbsp;&nbsp;&nbsp;&nbsp;- 'weg und bewachen'<br>
&nbsp;&nbsp;&nbsp;&nbsp;- 'Level 2'<br>
&nbsp;&nbsp;&nbsp;&nbsp;- 'SL2'<br>
&nbsp;&nbsp;lang: 'de'<br>
</code>
</p>

</div>
</div>
</div>
</div>
</div>

</div>
Loading

0 comments on commit 5953e82

Please sign in to comment.