Commit bf28fdba authored by nextime's avatar nextime

Initial connection between thermostat gui and backend

parent 84d25f0e
......@@ -65,13 +65,13 @@ if($panel && is_array($panel)) {
class="panel panel-theme-<?=$_DOMOTIKA['gui_theme']?> thermo-statuspanel text-on-white-theme-<?=$_DOMOTIKA['gui_theme']?>">
<div class="notifylist">
<div class="list-group theme-<?=$_DOMOTIKA['gui_theme']?>" data-snap-ignore="true">
<? foreach($climastatuses as $cs) { if($cs['clima_status']!=$climastatus) { ?>
<? foreach($climastatuses as $cs) { ?>
<button type="button" style="width:100%;margin-top:5px;"
data-domotika-statusselect="<?=$cs['clima_status']?>"
data-domotika-type="statuschoose"
data-domotika-type="statusselect"
data-domotika-panel="thermo-statuschooselist-<?=$button['id']."-".$panel['id']?>"
class="btn btn-success"><?=$cs['clima_status']?></button>
<? }} ?>
<? } ?>
</div>
</div>
</div>
......
......@@ -14,6 +14,39 @@ function thermoResetGaugeLevel(g,l) {
}
function changeClimaStatus(newstatus, request){
$("[data-domotika-type=btn-choosestatuses]").each(
function(){
$(this).html("<b>"+newstatus+'<b> <i class="glyphicon glyphicon-chevron-down"></i>')
}
);
$("[data-domotika-type=statusselect]").each(
function(){
if($(this).attr('data-domotika-statusselect')==newstatus)
$(this).hide();
else
$(this).show();
}
);
if(typeof(request)!='undefined') {
console.debug("Change status to "+newstatus);
$.post("/rest/v1.2/clima/status/json", 'status='+newstatus);
}
}
function changeThermostatStatus(newstatus, parts2, parts3)
{
var program=$("#thermo-btnprogram-"+parts2+'-'+parts3);
var manual=$("#thermo-btnmanual-"+parts2+'-'+parts3);
if(newstatus=='manual'){
program.alterClass(program.attr('data-dmcolor-on'), program.attr('data-dmcolor-off'));
manual.alterClass(manual.attr('data-dmcolor-off'), manual.attr('data-dmcolor-on'));
} else {
program.alterClass(program.attr('data-dmcolor-off'), program.attr('data-dmcolor-on'));
manual.alterClass(manual.attr('data-dmcolor-on'), manual.attr('data-dmcolor-off'));
}
}
function checkSliderSet(slider){
if(slider.data('lastchanged'))
{
......@@ -47,16 +80,8 @@ $("[data-domotika-type=thermo-level]").each(
var parts=$(this).attr('id').split("-");
$("#thermo-showset-"+parts[2]+'-'+parts[3]).text(parseFloat($(this).val()).toFixed(1));
thermoResetGaugeLevel('gauge-'+parts[2]+'-'+parts[3], parseFloat($(this).val()));
var program=$("#thermo-btnprogram-"+parts[2]+'-'+parts[3]);
var manual=$("#thermo-btnmanual-"+parts[2]+'-'+parts[3]);
program.alterClass(program.attr('data-dmcolor-on'), program.attr('data-dmcolor-off'));
manual.alterClass(manual.attr('data-dmcolor-off'), manual.attr('data-dmcolor-on'));
changeThermostatStatus('manual', parts[2], parts[3]);
},
/*
set: function() {
$(this).data('lastchanged', Date.now());
}
*/
});
$(this).data('oldval', $(this).val());
$(this).data('lastchanged', false);
......@@ -76,11 +101,7 @@ $("[data-domotika-type=thermo-level]").each(
{
$('#'+$(this).attr('id').replace('thermo-level-','thermo-showset-')).text(parseFloat($(this).val()).toFixed(1));
thermoResetGaugeLevel('gauge-'+parts[2]+'-'+parts[3], parseFloat($(this).val()));
var program=$("#thermo-btnprogram-"+parts[2]+'-'+parts[3]);
var manual=$("#thermo-btnmanual-"+parts[2]+'-'+parts[3]);
program.alterClass(program.attr('data-dmcolor-on'), program.attr('data-dmcolor-off'));
manual.alterClass(manual.attr('data-dmcolor-off'), manual.attr('data-dmcolor-on'));
//$(this).data('lastchanged', Date.now());
changeThermostatStatus('manual', parts[2], parts[3]);
}
});
......@@ -92,11 +113,7 @@ $("[data-domotika-type=thermo-level]").each(
slide.val(parseFloat(slide.val())-0.5);
$('#'+$(this).attr('id').replace('thermo-minus-','thermo-showset-')).text(parseFloat(slide.val()).toFixed(1));
var parts=$(this).attr('id').split("-");
var program=$("#thermo-btnprogram-"+parts[2]+'-'+parts[3]);
var manual=$("#thermo-btnmanual-"+parts[2]+'-'+parts[3]);
program.alterClass(program.attr('data-dmcolor-on'), program.attr('data-dmcolor-off'));
manual.alterClass(manual.attr('data-dmcolor-off'), manual.attr('data-dmcolor-on'));
//slide.data('lastchanged', Date.now());
changeThermostatStatus('manual', parts[2], parts[3]);
}, 200, 700, true);
plus.continouoshold(function(){
......@@ -104,11 +121,7 @@ $("[data-domotika-type=thermo-level]").each(
slide.val(parseFloat(slide.val())+0.5);
$('#'+$(this).attr('id').replace('thermo-plus-','thermo-showset-')).text(parseFloat(slide.val()).toFixed(1));
var parts=$(this).attr('id').split("-");
var program=$("#thermo-btnprogram-"+parts[2]+'-'+parts[3]);
var manual=$("#thermo-btnmanual-"+parts[2]+'-'+parts[3]);
program.alterClass(program.attr('data-dmcolor-on'), program.attr('data-dmcolor-off'));
manual.alterClass(manual.attr('data-dmcolor-off'), manual.attr('data-dmcolor-on'));
//slide.data('lastchanged', Date.now());
changeThermostatStatus('manual', parts[2], parts[3]);
}, 200, 700, true);
}
......@@ -134,6 +147,8 @@ $("[data-domotika-type=statusselect]").each(
$(this).fastClick(function(){
var panel="#"+$(this).attr('data-domotika-panel');
$(panel).hide(150);
var newstatus=$(this).attr('data-domotika-statusselect');
changeClimaStatus(newstatus, true);
});
}
);
......@@ -143,8 +158,7 @@ $("[data-domotika-type=btnprogram]").each(
function() {
var parts=$(this).attr('id').split("-");
var other=$("#thermo-btnmanual-"+parts[2]+'-'+parts[3]);
other.alterClass(other.attr('data-dmcolor-on'), other.attr('data-dmcolor-off'));
$(this).alterClass($(this).attr('data-dmcolor-off'), $(this).attr('data-dmcolor-on'));
changeThermostatStatus('program', parts[2], parts[3]);
});
}
);
......@@ -153,9 +167,7 @@ $("[data-domotika-type=btnmanual]").each(
function(){$(this).fastClick(
function() {
var parts=$(this).attr('id').split("-");
var other=$("#thermo-btnprogram-"+parts[2]+'-'+parts[3]);
other.alterClass(other.attr('data-dmcolor-on'), other.attr('data-dmcolor-off'));
$(this).alterClass($(this).attr('data-dmcolor-off'), $(this).attr('data-dmcolor-on'));
changeThermostatStatus('manual', parts[2], parts[3]);
});
}
);
......
......@@ -236,6 +236,11 @@ class StatsData(DBObject):
class StatsHistory(DBObject):
TABLENAME="stats_history"
class Thermostats(DBObject):
TABLENAME="thermostats"
class ThermostatsProgs(DBObject):
TABLENAME="thermostats_progs"
def cleanFlags():
......@@ -269,6 +274,9 @@ def _retValueQuery(res, defval='DEFAULT'):
def getNetStatus():
return Uniques.find(where=["name='netstatus'"],limit=1).addCallback(_retValueQuery, 'DEFAULT')
def getClimaStatus():
return Uniques.find(where=["name='climastatus'"],limit=1).addCallback(_retValueQuery, 'OFF')
def getStatusRealtime(stname):
return StatusRealtime.find(where=["status_name=?", stname],limit=1).addCallback(_retValueQuery, False)
......
......@@ -2322,6 +2322,15 @@ class domotikaService(service.Service):
return 'TRUE'
return 'FALSE'
def web_on_getClimaStatus(self):
return dmdb.getClimaStatus()
def web_on_setClimaStatus(self, newstatus):
return dmdb.setUnique('climastatus', newstatus);
def web_on_getThermostat(self, thermostat):
return dmdb.Thermostats.find(where=["name='%s'" % thermostat],limit=1)
def web_on_voiceReceived(self, txt, confidence=0.0, lang="it"):
return self.voiceRecognized(txt, confidence, lang, voicesrc='RestAPI')
......
......@@ -524,6 +524,32 @@ class ChartRest(RestCore):
return self.callbackResponse(self.core.getChartData(chartname), request)
class ClimaRest(RestCore):
path="clima"
@route("/status",(Http.GET))
@wrapResponse
def getStatus(self, request, *a, **kw):
return self.callbackResponse(self.core.getClimaStatus(), request)
@route("/status",(Http.PUT,Http.POST))
@wrapResponse
def setStatus(self, request, *a, **kw):
r = self._getRequestArgs(request)
if 'status' in r.keys():
statusname=r['status']
return self.callbackResponse(self.core.setClimaStatus(statusname), request)
return ResponseConversion(request, code=500, entity="No status in request")
@route("/thermostat/<thermostat>",(Http.GET))
@wrapResponse
def getThermostatStatus(self, request, thermostat, *a, **kw):
return self.callbackResponse(self.core.getThermostat(thermostat), request)
RESTv12LIST=(
UserRest,
CronRest,
......@@ -533,6 +559,7 @@ RESTv12LIST=(
NotifyRest,
RelayRest,
ChartRest,
ClimaRest,
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment