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)) { ...@@ -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']?>"> class="panel panel-theme-<?=$_DOMOTIKA['gui_theme']?> thermo-statuspanel text-on-white-theme-<?=$_DOMOTIKA['gui_theme']?>">
<div class="notifylist"> <div class="notifylist">
<div class="list-group theme-<?=$_DOMOTIKA['gui_theme']?>" data-snap-ignore="true"> <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;" <button type="button" style="width:100%;margin-top:5px;"
data-domotika-statusselect="<?=$cs['clima_status']?>" data-domotika-statusselect="<?=$cs['clima_status']?>"
data-domotika-type="statuschoose" data-domotika-type="statusselect"
data-domotika-panel="thermo-statuschooselist-<?=$button['id']."-".$panel['id']?>" data-domotika-panel="thermo-statuschooselist-<?=$button['id']."-".$panel['id']?>"
class="btn btn-success"><?=$cs['clima_status']?></button> class="btn btn-success"><?=$cs['clima_status']?></button>
<? }} ?> <? } ?>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -14,6 +14,39 @@ function thermoResetGaugeLevel(g,l) { ...@@ -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){ function checkSliderSet(slider){
if(slider.data('lastchanged')) if(slider.data('lastchanged'))
{ {
...@@ -47,16 +80,8 @@ $("[data-domotika-type=thermo-level]").each( ...@@ -47,16 +80,8 @@ $("[data-domotika-type=thermo-level]").each(
var parts=$(this).attr('id').split("-"); var parts=$(this).attr('id').split("-");
$("#thermo-showset-"+parts[2]+'-'+parts[3]).text(parseFloat($(this).val()).toFixed(1)); $("#thermo-showset-"+parts[2]+'-'+parts[3]).text(parseFloat($(this).val()).toFixed(1));
thermoResetGaugeLevel('gauge-'+parts[2]+'-'+parts[3], parseFloat($(this).val())); thermoResetGaugeLevel('gauge-'+parts[2]+'-'+parts[3], parseFloat($(this).val()));
var program=$("#thermo-btnprogram-"+parts[2]+'-'+parts[3]); changeThermostatStatus('manual', 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'));
}, },
/*
set: function() {
$(this).data('lastchanged', Date.now());
}
*/
}); });
$(this).data('oldval', $(this).val()); $(this).data('oldval', $(this).val());
$(this).data('lastchanged', false); $(this).data('lastchanged', false);
...@@ -76,11 +101,7 @@ $("[data-domotika-type=thermo-level]").each( ...@@ -76,11 +101,7 @@ $("[data-domotika-type=thermo-level]").each(
{ {
$('#'+$(this).attr('id').replace('thermo-level-','thermo-showset-')).text(parseFloat($(this).val()).toFixed(1)); $('#'+$(this).attr('id').replace('thermo-level-','thermo-showset-')).text(parseFloat($(this).val()).toFixed(1));
thermoResetGaugeLevel('gauge-'+parts[2]+'-'+parts[3], parseFloat($(this).val())); thermoResetGaugeLevel('gauge-'+parts[2]+'-'+parts[3], parseFloat($(this).val()));
var program=$("#thermo-btnprogram-"+parts[2]+'-'+parts[3]); changeThermostatStatus('manual', 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());
} }
}); });
...@@ -92,11 +113,7 @@ $("[data-domotika-type=thermo-level]").each( ...@@ -92,11 +113,7 @@ $("[data-domotika-type=thermo-level]").each(
slide.val(parseFloat(slide.val())-0.5); slide.val(parseFloat(slide.val())-0.5);
$('#'+$(this).attr('id').replace('thermo-minus-','thermo-showset-')).text(parseFloat(slide.val()).toFixed(1)); $('#'+$(this).attr('id').replace('thermo-minus-','thermo-showset-')).text(parseFloat(slide.val()).toFixed(1));
var parts=$(this).attr('id').split("-"); var parts=$(this).attr('id').split("-");
var program=$("#thermo-btnprogram-"+parts[2]+'-'+parts[3]); changeThermostatStatus('manual', 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());
}, 200, 700, true); }, 200, 700, true);
plus.continouoshold(function(){ plus.continouoshold(function(){
...@@ -104,11 +121,7 @@ $("[data-domotika-type=thermo-level]").each( ...@@ -104,11 +121,7 @@ $("[data-domotika-type=thermo-level]").each(
slide.val(parseFloat(slide.val())+0.5); slide.val(parseFloat(slide.val())+0.5);
$('#'+$(this).attr('id').replace('thermo-plus-','thermo-showset-')).text(parseFloat(slide.val()).toFixed(1)); $('#'+$(this).attr('id').replace('thermo-plus-','thermo-showset-')).text(parseFloat(slide.val()).toFixed(1));
var parts=$(this).attr('id').split("-"); var parts=$(this).attr('id').split("-");
var program=$("#thermo-btnprogram-"+parts[2]+'-'+parts[3]); changeThermostatStatus('manual', 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());
}, 200, 700, true); }, 200, 700, true);
} }
...@@ -134,6 +147,8 @@ $("[data-domotika-type=statusselect]").each( ...@@ -134,6 +147,8 @@ $("[data-domotika-type=statusselect]").each(
$(this).fastClick(function(){ $(this).fastClick(function(){
var panel="#"+$(this).attr('data-domotika-panel'); var panel="#"+$(this).attr('data-domotika-panel');
$(panel).hide(150); $(panel).hide(150);
var newstatus=$(this).attr('data-domotika-statusselect');
changeClimaStatus(newstatus, true);
}); });
} }
); );
...@@ -143,8 +158,7 @@ $("[data-domotika-type=btnprogram]").each( ...@@ -143,8 +158,7 @@ $("[data-domotika-type=btnprogram]").each(
function() { function() {
var parts=$(this).attr('id').split("-"); var parts=$(this).attr('id').split("-");
var other=$("#thermo-btnmanual-"+parts[2]+'-'+parts[3]); var other=$("#thermo-btnmanual-"+parts[2]+'-'+parts[3]);
other.alterClass(other.attr('data-dmcolor-on'), other.attr('data-dmcolor-off')); changeThermostatStatus('program', parts[2], parts[3]);
$(this).alterClass($(this).attr('data-dmcolor-off'), $(this).attr('data-dmcolor-on'));
}); });
} }
); );
...@@ -153,9 +167,7 @@ $("[data-domotika-type=btnmanual]").each( ...@@ -153,9 +167,7 @@ $("[data-domotika-type=btnmanual]").each(
function(){$(this).fastClick( function(){$(this).fastClick(
function() { function() {
var parts=$(this).attr('id').split("-"); var parts=$(this).attr('id').split("-");
var other=$("#thermo-btnprogram-"+parts[2]+'-'+parts[3]); changeThermostatStatus('manual', 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'));
}); });
} }
); );
......
...@@ -236,6 +236,11 @@ class StatsData(DBObject): ...@@ -236,6 +236,11 @@ class StatsData(DBObject):
class StatsHistory(DBObject): class StatsHistory(DBObject):
TABLENAME="stats_history" TABLENAME="stats_history"
class Thermostats(DBObject):
TABLENAME="thermostats"
class ThermostatsProgs(DBObject):
TABLENAME="thermostats_progs"
def cleanFlags(): def cleanFlags():
...@@ -269,6 +274,9 @@ def _retValueQuery(res, defval='DEFAULT'): ...@@ -269,6 +274,9 @@ def _retValueQuery(res, defval='DEFAULT'):
def getNetStatus(): def getNetStatus():
return Uniques.find(where=["name='netstatus'"],limit=1).addCallback(_retValueQuery, 'DEFAULT') 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): def getStatusRealtime(stname):
return StatusRealtime.find(where=["status_name=?", stname],limit=1).addCallback(_retValueQuery, False) return StatusRealtime.find(where=["status_name=?", stname],limit=1).addCallback(_retValueQuery, False)
......
...@@ -2322,6 +2322,15 @@ class domotikaService(service.Service): ...@@ -2322,6 +2322,15 @@ class domotikaService(service.Service):
return 'TRUE' return 'TRUE'
return 'FALSE' 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"): def web_on_voiceReceived(self, txt, confidence=0.0, lang="it"):
return self.voiceRecognized(txt, confidence, lang, voicesrc='RestAPI') return self.voiceRecognized(txt, confidence, lang, voicesrc='RestAPI')
......
...@@ -524,6 +524,32 @@ class ChartRest(RestCore): ...@@ -524,6 +524,32 @@ class ChartRest(RestCore):
return self.callbackResponse(self.core.getChartData(chartname), request) 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=( RESTv12LIST=(
UserRest, UserRest,
CronRest, CronRest,
...@@ -533,6 +559,7 @@ RESTv12LIST=( ...@@ -533,6 +559,7 @@ RESTv12LIST=(
NotifyRest, NotifyRest,
RelayRest, RelayRest,
ChartRest, 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