iobroker.heatingcontrol
Version:
HeatingControl Adapter
1,336 lines (1,024 loc) • 148 kB
HTML
<html>
<head>
<!-- Load ioBroker scripts and styles-->
<link rel="stylesheet" type="text/css" href="../../lib/css/fancytree/ui.fancytree.min.css" />
<link rel="stylesheet" type="text/css" href="../../css/adapter.css" />
<link rel="stylesheet" type="text/css" href="../../lib/css/materialize.css">
<script type="text/javascript" src="../../lib/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../../socket.io/socket.io.js"></script>
<script type="text/javascript" src="../../lib/js/materialize.js"></script>
<script type="text/javascript" src="../../lib/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="../../lib/js/jquery.fancytree-all.min.js"></script>
<script type="text/javascript" src="../../js/translate.js"></script>
<script type="text/javascript" src="../../lib/js/selectID.js"></script>
<script type="text/javascript" src="../../js/adapter-settings.js"></script>
<!-- my own styles -->
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="words.js"></script>
<style>
#dialog-room-edit {
max-height: 95% !important;
max-width: 85% !important;
width: 80% !important;
height: 90% !important;
overflow: visible !important;
top: 10px !important;
}
#dialog-select-member {
max-height: 95% !important;
max-width: 85% !important;
width: 80% !important;
height: 90% !important;
overflow: visible !important;
top: 10px !important;
}
.collapsible-body {
margin-left: 2rem !important;
padding-top: 0 !important;
}
redlabel {
color: red;
}
</style>
<script type="text/javascript">
//==========================================================================
//load / save profile
function SaveProfile(instance) {
console.log('SaveProfile called ');
$('#checkResultSaveProfile').html("saving...");
sendTo(instance, 'saveProfile', null, function (result) {
generateFile('heatingcontrol_profile.json', result);
console.log('profile saved ');
$('#checkResultSaveProfile').html("profile saved");
});
}
function generateFile(filename, obj) {
var el = document.createElement('a');
el.setAttribute('href', 'data:application/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(obj, null, 2)));
el.setAttribute('download', filename);
el.style.display = 'none';
document.body.appendChild(el);
el.click();
document.body.removeChild(el);
}
function LoadProfile(instance) {
console.log('Load profile called');
var input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('id', 'files');
input.setAttribute('opacity', 0);
input.addEventListener('change', function (e) {
hchandleFileSelect(e, instance, function () { });
}, false);
(input.click)();
}
function hchandleFileSelect(evt, instance) {
console.log('handleFileSelect ' + instance);
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function (e) {
var contents = e.target.result;
$('#checkResultLoadProfile').html("loading...");
sendTo(instance, 'loadProfile', contents, function (result) {
console.log('profile loaded with ' + result);
$('#checkResultLoadProfile').html(result);
myOnChange(true)
});
}
r.readAsText(f);
}
}
//==========================================================================
function DeleteUnusedConfig() {
let deleted = 0;
const RoomList = table2values('rooms');
for (let d = 0; d < DeviceList.length; d++) {
const room = DeviceList[d].room;
let bFound = false;
for (r = 0; r < RoomList.length; r++) {
if (room == RoomList[r].name) {
bFound = true;
}
}
if (!bFound) {
console.log('delete device ' + DeviceList[d].name);
deleted++;
DeviceList.splice(d, 1);
}
}
//and finally rearrange id's
for (let i = 0; i < DeviceList.length; i++) {
//console.log("### " + i + " " + JSON.stringify(DeviceList[i]));
DeviceList[i].id = i + 1;
//console.log("+++ " + i + " " + JSON.stringify(DeviceList[i]));
}
console.log("new device list " + JSON.stringify(DeviceList));
$('#result_deleteunusedConfig').html(deleted + " unused device deleted");
}
//==========================================================================
function findObjectIdByKey(array, key, value) {
//Achtung: key wird auf int geparsed!!
if (array !== null && typeof array !== 'undefined') {
for (let i = 0; i < array.length; i++) {
let val1 = array[i][key];
if (typeof array[i][key] !== 'number') {
val1 = parseInt(array[i][key]);
}
let val2 = value;
console.log('check for ' + val1 + ' (' + typeof val1 + ') and ' + val2 + ' (' + typeof val2 + ')');
if (val1 === val2) {
console.log('found');
return i;
}
}
}
console.log('not found');
return -1;
}
function show_hide_column(table_name, col_name, col_no, do_show) {
//this is only for header
var element = document.getElementById(col_name);
if (element != null) {
if (do_show) {
element.classList.remove("hide");
}
else {
element.classList.add("hide");
}
//here we have all other rows
var tbl = document.getElementById(table_name);
var rows = tbl.getElementsByTagName('tr');
for (var row = 0; row < rows.length; row++) {
var cols = rows[row].children;
if (col_no >= 0 && col_no < cols.length) {
var cell = cols[col_no];
if (cell.tagName == 'TD' || cell.tagName == 'TH') {
if (do_show) {
cell.classList.remove("hide");
}
else {
cell.classList.add("hide");
}
}
}
}
}
}
var AdapterIsOnline = false;
function showHideSettings() {
console.log('showHideSettings');
//always hide
if (!AdapterIsOnline) {
$('.col-adapternotonline').show();
}
else {
$('.col-adapternotonline').hide();
}
var TypeDPPresent = $('#Path2PresentDPType')[0].value
if (TypeDPPresent == 1) {
$('.col_Path2PresentDPLimit').hide();
}
else {
$('.col_Path2PresentDPLimit').show();
}
var TypeDPGuestPresent = $('#Path2GuestsPresentDPType')[0].value
if (TypeDPGuestPresent == 1) {
$('.col_Path2GuestsPresentDPLimit').hide();
}
else {
$('.col_Path2GuestsPresentDPLimit').show();
}
var TypeDPPartyNow = $('#Path2PartyNowDPType')[0].value
if (TypeDPPartyNow == 1) {
$('.col_Path2PartyNowDPLimit').hide();
}
else {
$('.col_Path2PartyNowDPLimit').show();
}
var ThermostatModeIfNoHeatingperiod = $('#ThermostatModeIfNoHeatingperiod')[0].value;
if (ThermostatModeIfNoHeatingperiod == 2) {
$('.col-FixTempIfNoHeatingPeriod').show();
}
else {
$('.col-FixTempIfNoHeatingPeriod').hide();
}
var elementPageActors = document.getElementById("page-actors");
var elementPageSensors = document.getElementById("page-sensors");
var elementPageAddTempSensors = document.getElementById("page-addTempSensors");
var $useActors = $('#UseActors');
if ($useActors.prop('checked')) {
console.log('show actor settings');
if (ThermostatModeIfNoHeatingperiod == 2) {
$('.col-useactorifnoheating').hide();
}
else {
$('.col-useactorifnoheating').show();
}
$('.col-useactorifnothermostat').show();
$('.col-ActorOnDelay').show();
$('.col-ActorOffDelay').show();
$('.col-InterActorDelay').show();
$('.col-regulatortype').show();
$('.col-extendedInfoLogActor').show();
$('.col-ExtHandlingActorAckWaitTime').show();
$('.col-ExtHandlingActorRepTime').show();
elementPageActors.classList.remove("hide");
}
else {
console.log('hide actor settings');
$('.col-useactorifnoheating').hide();
$('.col-useactorifnothermostat').hide();
$('.col-ActorOnDelay').hide();
$('.col-ActorOffDelay').hide();
$('.col-InterActorDelay').hide();
$('.col-regulatortype').hide();
$('.col-extendedInfoLogActor').hide();
$('.col-ExtHandlingActorAckWaitTime').hide();
$('.col-ExtHandlingActorRepTime').hide();
elementPageActors.classList.add("hide");
}
var $useSensors = $('#UseSensors');
if ($useSensors.prop('checked')) {
console.log('show sensor settings');
elementPageSensors.classList.remove("hide");
$('.col-SensorOpenDelay').show();
$('.col-SensorCloseDelay').show();
$('.col-extendedInfoLogWindow').show();
}
else {
console.log('hide sensors settings');
elementPageSensors.classList.add("hide");
$('.col-SensorOpenDelay').hide();
$('.col-SensorCloseDelay').hide();
$('.col-extendedInfoLogWindow').hide();
}
var $UseAddTempSensors = $('#UseAddTempSensors');
if ($UseAddTempSensors.prop('checked')) {
console.log('show additional sensor settings');
elementPageAddTempSensors.classList.remove("hide");
$('.col-AddTempSensorsTempLimit').show();
$('.col-AddTempSensorsTempLimit-descr').show();
$('.col-AddTempSensorsMaxTimeDiff').show();
$('.col-AddTempSensorsMaxTimeDiff-descr').show();
$('.col-AddTempSensorsUseEveryOffsetChange').show();
$('.col-AddTempSensorsUseEveryOffsetChange-descr').show();
}
else {
console.log('hide additional sensors settings');
elementPageAddTempSensors.classList.add("hide");
$('.col-AddTempSensorsTempLimit').hide();
$('.col-AddTempSensorsTempLimit-descr').hide();
$('.col-AddTempSensorsMaxTimeDiff').hide();
$('.col-AddTempSensorsMaxTimeDiff-descr').hide();
$('.col-AddTempSensorsUseEveryOffsetChange').hide();
$('.col-AddTempSensorsUseEveryOffsetChange-descr').hide();
}
var $useFixHeatingPeriod = $('#UseFixHeatingPeriod');
if ($useFixHeatingPeriod.prop('checked')) {
console.log('show sensor fix heating period settings');
$('.col-FixHeatingPeriod-Start').show();
$('.col-FixHeatingPeriod-End').show();
}
else {
console.log('hide sensor fix heating period settings');
$('.col-FixHeatingPeriod-Start').hide();
$('.col-FixHeatingPeriod-End').hide();
}
var $useVisFromPittini = $('#UseVisFromPittini');
if ($useVisFromPittini.prop('checked')) {
console.log('show settings for Pittini vis');
$('.col-PittiniPathImageWindowOpen').show();
$('.col-PittiniPathImageWindowClosed').show();
$('.col-VisMinProfilTemp').show();
$('.col-VisMaxProfilTemp').show();
$('.col-VisStepWidthProfilTemp').show();
}
else {
console.log('hide settings for Pittini vis');
$('.col-PittiniPathImageWindowOpen').hide();
$('.col-PittiniPathImageWindowClosed').hide();
$('.col-VisMinProfilTemp').hide();
$('.col-VisMaxProfilTemp').hide();
$('.col-VisStepWidthProfilTemp').hide();
}
//first col of device tables
show_hide_column("table_thermostats", "thermostat_col_0", 0, false);
show_hide_column("table_actors", "actor_col_0", 0, false);
show_hide_column("table_sensors", "sensor_col_0", 0, false);
show_hide_column("table_addtempsensors", "addtempsensor_col_0", 0, false);
var $ThermostatHandlesWindowOpen = $('#ThermostatHandlesWindowOpen');
if ($ThermostatHandlesWindowOpen.prop('checked')) {
console.log('show settings ThermostatHandlesWindowOpen');
$('.col-WaitForTempIfWindowOpen').show();
}
else {
console.log('hide settings ThermostatHandlesWindowOpen');
$('.col-WaitForTempIfWindowOpen').hide();
}
show_hide_column("table_rooms", "rooms_col_3", 2, false);
ShowHideNotificationSettings($('#notificationsType').val());
ShowHideNotificationDiscordSettings($('#discordTarget').val());
ShowHideCustumizedNotifications($('#useCustumizedNotifications').prop('checked'));
}
function ShowHideCustumizedNotifications(current) {
console.log("ShowHideCustumizedNotifications " + current);
if (current) {
$('.useCustumizedNotificationsWithInstanceName').show();
$('.useCustumizedNotificationsNewTargetTemp').show();
if ($('#UseActors').prop('checked')) {
$('.useCustumizedNotificationsActorOn').show();
$('.useCustumizedNotificationsActorOff').show();
}
$('.useCustumizedNotificationsWindowOpen').show();
$('.useCustumizedNotificationsWindowClose').show();
}
else {
$('.useCustumizedNotificationsWithInstanceName').hide();
$('.useCustumizedNotificationsNewTargetTemp').hide();
$('.useCustumizedNotificationsActorOn').hide();
$('.useCustumizedNotificationsActorOff').hide();
$('.useCustumizedNotificationsWindowOpen').hide();
$('.useCustumizedNotificationsWindowClose').hide();
}
// alles hide, wenn Benachrichtigung off
console.log("ShowHideCustumizedNotifications notification enabled " + $('#notificationEnabled').prop('checked'));
if ($('#notificationEnabled').prop('checked')) {
$('.customizedNotifications').show();
}
else {
$('.customizedNotifications').hide();
}
}
function ShowHideNotificationDiscordSettings(current) {
console.log("ShowHideNotificationDiscordSettings " + current);
if ($('#notificationEnabled').prop('checked')) {
if (current === 'UserId') {
$('.discordUserId').show();
$('.discordUserTag').hide();
$('.discordServerChannel').hide();
}
else if (current === 'UserTag') {
$('.discordUserId').hide();
$('.discordUserTag').show();
$('.discordServerChannel').hide();
}
else if (current === 'ServerChannel') {
$('.discordUserId').hide();
$('.discordUserTag').hide();
$('.discordServerChannel').show();
}
}
else {
$('.discordUserId').hide();
$('.discordUserTag').hide();
$('.discordServerChannel').hide();
}
}
function ShowHideNotificationSettings(current) {
console.log("ShowHideNotificationSettings " + current + " " + $('#notificationEnabled').prop('checked'));
if ($('#notificationEnabled').prop('checked')) {
$('.notificationsType').show();
$('.col-notificationsTemperature').show();
if ($('#UseActors').prop('checked')) {
$('.col-notificationsActor').show();
}
$('.col-notificationsWindow').show();
if (current === 'Telegram') {
$('.email').hide();
$('.pushover').hide();
$('.whatsapp').hide();
$('.signal').hide();
$('.telegram').show();
$('.discord').hide();
} else if (current === 'E-Mail') {
$('.telegram').hide();
$('.pushover').hide();
$('.whatsapp').hide();
$('.signal').hide();
$('.email').show();
$('.discord').hide();
} else if (current === 'Pushover') {
$('.telegram').hide();
$('.email').hide();
$('.whatsapp').hide();
$('.signal').hide();
$('.pushover').show();
$('.discord').hide();
} else if (current === 'WhatsApp') {
$('.telegram').hide();
$('.email').hide();
$('.pushover').hide();
$('.signal').hide();
$('.whatsapp').show();
$('.discord').hide();
} else if (current === 'Signal') {
$('.telegram').hide();
$('.email').hide();
$('.pushover').hide();
$('.whatsapp').hide();
$('.signal').show();
$('.discord').hide();
} else if (current === 'Discord') {
$('.telegram').hide();
$('.email').hide();
$('.pushover').hide();
$('.whatsapp').hide();
$('.signal').hide();
$('.discord').show();
}
}
else {
$('.notificationsType').hide();
$('.col-notificationsTemperature').hide();
$('.col-notificationsActor').hide();
$('.col-notificationsWindow').hide();
$('.telegram').hide();
$('.email').hide();
$('.pushover').hide();
$('.whatsapp').hide();
$('.signal').hide();
$('.discord').hide();
}
}
var DeviceList = [];
var timeout2;
function getFunctions(actualValue, onChange, instance) {
timeout2 = setTimeout(function () {
getFunctions(actualValue, onChange, instance);
}, 4000);
//function sendTo(_adapter_instance, command, message, callback)
sendTo(instance, 'listFunctions', null, function (list) {
if (timeout2) {
clearTimeout(timeout2);
timeout2 = null;
}
AdapterIsOnline = true;
console.log('got functions ' + JSON.stringify(list));
var $sel = $('#Gewerk');
for (var i = 0; i < list.length; i++) {
$sel.append('<option value="' + list[i].name + '" ' + ((actualValue == list[i].name) ? 'selected' : '') + '>' + list[i].name + '</option>');
}
$sel.select();
showHideSettings()
});
}
var timeout3;
function getRooms(onChange, instance) {
timeout3 = setTimeout(function () {
getRooms(onChange, instance);
}, 4000);
//function sendTo(_adapter_instance, command, message, callback)
sendTo(instance, 'listRooms', true, function (obj) {
if (timeout3) {
clearTimeout(timeout3);
timeout3 = null;
}
console.log('got rooms ' + JSON.stringify(obj));
values2table('rooms', obj.list, onChange, tableRoomsOnReady);
newRooms = obj.newRooms;
$('#checkResultRooms').html(newRooms + ' new room(s) ');
if (newRooms > 0) {
onChange(true);
}
});
}
var timeout4;
function getThermostats(onChange, instance, room) {
timeout4 = setTimeout(function () {
getThermostats(onChange, instance, room);
}, 4000);
var gewerk = $("#Gewerk option:selected").text();
const data = {
room: room,
gewerk: gewerk
};
console.log('get thermostats for ' + room + " with " + gewerk + " " + JSON.stringify(data));
//function sendTo(_adapter_instance, command, message, callback)
sendTo(instance, 'listThermostats', data, function (result) {
if (timeout4) {
clearTimeout(timeout4);
timeout4 = null;
}
console.log('got thermostats for ' + room + " " + JSON.stringify(result));
if (result.list.length > 0) {
var newThermostats = table2values('thermostats');
for (let i = 0; i < result.list.length; i++) {
const device = {
name: result.list[i].Name,
OID_Current: result.list[i].OID_Current,
OID_Target: result.list[i].OID_Target,
id: -1, //new
isActive: true,
room: result.room,
type: 1
}
newThermostats.push(device);
console.log('newThermostats ' + JSON.stringify(newThermostats));
}
values2table('thermostats', newThermostats, OnChange, tableDevicesOnReady);
onChange(true);
}
$('#checkResultThermostats').html(result.status);
});
}
var timeout5;
function getActors(onChange, instance, room) {
timeout5 = setTimeout(function () {
getActors(onChange, instance, room);
}, 4000);
var gewerk = $("#Gewerk option:selected").text();
const data = {
room: room,
gewerk: gewerk
};
console.log('get actors for ' + room + " with " + gewerk + " " + JSON.stringify(data));
//function sendTo(_adapter_instance, command, message, callback)
sendTo(instance, 'listActors', data, function (result) {
if (timeout5) {
clearTimeout(timeout5);
timeout5 = null;
}
console.log('got actors for ' + room + " " + JSON.stringify(result));
if (result.list.length > 0) {
var newActors = table2values('actors');
for (let i = 0; i < result.list.length; i++) {
const device = {
name: result.list[i].Name,
OID_Target: result.list[i].OID,
id: -1, //new
isActive: true,
room: result.room,
type: 1
}
newActors.push(device);
console.log('newActors ' + JSON.stringify(newActors));
}
values2table('actors', newActors, OnChange, tableDevicesOnReady);
onChange(true);
}
$('#checkResultActors').html(result.status);
});
}
var timeout6;
function getSensors(onChange, instance, room) {
timeout6 = setTimeout(function () {
getSensors(onChange, instance, room);
}, 4000);
var gewerk = $("#Gewerk option:selected").text();
const data = {
room: room,
gewerk: gewerk
};
console.log('get sensors for ' + room + " with " + gewerk + " " + JSON.stringify(data));
//function sendTo(_adapter_instance, command, message, callback)
sendTo(instance, 'listSensors', data, function (result) {
if (timeout6) {
clearTimeout(timeout6);
timeout6 = null;
}
console.log('got sensors for ' + room + " " + JSON.stringify(result));
if (result.list.length > 0) {
var newSensors = table2values('sensors');
for (let i = 0; i < result.list.length; i++) {
const device = {
name: result.list[i].Name,
OID_Current: result.list[i].OID,
id: -1, //new
isActive: true,
room: result.room,
type: 1
}
newSensors.push(device);
console.log('newSensors ' + JSON.stringify(newSensors));
}
values2table('sensors', newSensors, OnChange, tableDevicesOnReady);
onChange(true);
}
$('#checkResultSensors').html(result.status);
});
}
var timeout7;
function getAddTempSensors(onChange, instance, room) {
timeout7 = setTimeout(function () {
getAddTempSensors(onChange, instance, room);
}, 4000);
var gewerk = $("#Gewerk option:selected").text();
const data = {
room: room,
gewerk: gewerk
};
console.log('get add temp sensors for ' + room + " with " + gewerk + " " + JSON.stringify(data));
//function sendTo(_adapter_instance, command, message, callback)
sendTo(instance, 'listAddTempSensors', data, function (result) {
if (timeout7) {
clearTimeout(timeout7);
timeout7 = null;
}
console.log('got add temp sensors for ' + room + " " + JSON.stringify(result));
if (result.list.length > 0) {
var newAddTempSensors = table2values('addtempsensors');
for (let i = 0; i < result.list.length; i++) {
const device = {
name: result.list[i].Name,
OID_Current: result.list[i].OID,
id: -1, //new
isActive: true,
room: result.room,
type: 4
}
newAddTempSensors.push(device);
console.log('newAddTempSensors ' + JSON.stringify(newAddTempSensors));
}
values2table('addtempsensors', newAddTempSensors, OnChange, tableDevicesOnReady);
onChange(true);
}
$('#checkResultAddTempSensors').html(result.status);
});
}
var timeout8;
function getTelegramUser(onChange, instance, currentVal) {
timeout8 = setTimeout(function () {
getTelegramUser(onChange, instance);
}, 4000);
let telegraminstance = $(telegramInstance).val()
console.log('get TelegramUser ' + telegraminstance + " HC instance " + instance);
const data = {
telegraminstance: telegraminstance
};
//function sendTo(_adapter_instance, command, message, callback)
sendTo(instance, 'getTelegramUser', data, function (result) {
if (timeout8) {
clearTimeout(timeout8);
timeout8 = null;
}
console.log('got telegram user ' + JSON.stringify(result));
//got telegram user "Error: No instanceName provided or not a string"
let actualValue = "";
if (currentVal != null) {
actualValue = currentVal;
}
//fill select box
var $sel = $('#telegramUser');
//remove old ones
$sel.children().remove().end().append('<option value="allTelegramUsers"' + ((actualValue == "allTelegramUsers") ? 'selected' : '') + '>All Receiver</option>');
for (var i = 0; i < result.length; i++) {
//console.log('user ' + i + " " + JSON.stringify(result[i]));
if (result[i].firstName != null && typeof result[i].firstName != undefined && result[i].firstName.length > 0) {
console.log('append ' + result[i].id + " " + result[i].firstName);
$sel.append('<option value="' + result[i].id + '" ' + ((actualValue == result[i].id) ? 'selected' : '') + '>' + result[i].firstName + '</option>');
}
}
$sel.select();
console.log("12345");
});
}
var myOnChange = null;
function OnChange() {
//do nothing
console.log('on change called');
if (myOnChange != null) {
myOnChange();
}
}
function initDialogRoom(room, callback) {
console.log('initDialogRoom');
var $editDialog = $('#dialog-room-edit');
if (!$editDialog.data('inited')) {
$editDialog.data('inited', true);
$editDialog.modal({
dismissible: false
});
$editDialog.find('.btn-set').on('click', function () {
var $editDialog = $('#dialog-room-edit');
var callback = $editDialog.data('callback');
if (typeof callback === 'function') callback();
$editDialog.data('callback', null);
});
}
//to do fill table
var ThermostatList4Room = [];
var ActorList4Room = [];
var SensorList4Room = [];
var AddTempSensorList4Room = [];
if (DeviceList != null) {
console.log('fill table for ' + room + " " + DeviceList.length);
for (let i = 0; i < DeviceList.length; i++) {
//console.log('list entry ' + DeviceList[i].room);
if (DeviceList[i].room === room) {
if (DeviceList[i].type === 1) {
ThermostatList4Room.push(DeviceList[i]);
}
if (DeviceList[i].type === 2) {
ActorList4Room.push(DeviceList[i]);
}
if (DeviceList[i].type === 3) {
const sensor = DeviceList[i];
console.log(JSON.stringify(sensor));
//just make it compatibel
if (typeof sensor.DataType == undefined || sensor.DataType == null) {
console.log("change sensor to boolean");
sensor.DataType = "boolean";
sensor.valueOpen = true;
sensor.valueClosed = false;
console.log(JSON.stringify(sensor));
}
SensorList4Room.push(sensor);
}
if (DeviceList[i].type === 4) {
AddTempSensorList4Room.push(DeviceList[i]);
}
}
}
}
console.log('Thermostatlist ' + JSON.stringify(ThermostatList4Room));
console.log('Actorlist ' + JSON.stringify(ActorList4Room));
console.log('Sensorlist ' + JSON.stringify(SensorList4Room));
console.log('AddTempSensorlist ' + JSON.stringify(AddTempSensorList4Room));
values2table('thermostats', ThermostatList4Room, OnChange, tableDevicesOnReady);
values2table('actors', ActorList4Room, OnChange, tableDevicesOnReady);
values2table('sensors', SensorList4Room, OnChange, tableDevicesOnReady);
values2table('addtempsensors', AddTempSensorList4Room, OnChange, tableDevicesOnReady);
$editDialog.data('callback', callback);
$editDialog.modal('open');
showHideSettings();
}
// the function loadSettings has to exist ...
function load(settings, onChange) {
if (!settings) return;
console.log('##on change');
// example: select elements with id=key and class=value and insert value
for (var key in settings) {
if (!settings.hasOwnProperty(key)) continue;
var $value = $('#' + key + '.value');
if ($value.attr('type') === 'checkbox') {
$value.prop('checked', settings[key]).on('change', function () {
console.log('on change checked');
showHideSettings();
onChange();
});
} else {
$value.val(settings[key]).on('change', function () {
console.log('on change');
showHideSettings();
onChange();
}).on('keyup', function () {
$(this).trigger('change');
});
}
}
var $btn_check4newrooms = $('#btn_check4newrooms');
$btn_check4newrooms.click(function () {
console.log('check 4 new rooms');
var _id = 'heatingcontrol.' + instance;
console.log('my instance ' + _id);
getRooms(onChange, _id, true);
});
var $btnsave_profile = $('#btn_save_profile');
$btnsave_profile.click(function () {
console.log('btn save profile');
var _id = 'heatingcontrol.' + instance;
console.log('my instance ' + _id);
SaveProfile(_id);
});
var $btnload_profile = $('#btn_load_profile');
$btnload_profile.click(function () {
console.log('btn load profile');
var _id = 'heatingcontrol.' + instance;
console.log('my instance ' + _id);
LoadProfile(_id);
});
myOnChange = onChange;
// Signal to admin, that no changes yet
onChange(false);
$('.timepicker').timepicker({
"twelveHour": false
});
showHideSettings();
M.updateTextFields();
var _id = 'heatingcontrol.' + instance;
console.log('my instance ' + _id);
getFunctions(settings.Gewerk, onChange, _id);
if (typeof settings.devices !== 'undefined' && settings.devices != null && settings.devices.length > 0) {
DeviceList = settings.devices;
console.log('using devices from settings ' + JSON.stringify(DeviceList));
}
if (typeof settings.rooms !== 'undefined' && settings.rooms != null && settings.rooms.length > 0) {
values2table('rooms', settings.rooms, onChange, tableRoomsOnReady);
console.log('using rooms from settings ' + JSON.stringify(settings.rooms));
}
else {
//see issue #356, no rooms can be added if room list is empty, only after search for rooms it is possible
//solution: add a empty list to table
values2table('rooms', null, onChange, tableRoomsOnReady);
console.log('create an empty list for rooms');
}
//===========================================
//OID selecters
$('#OID_Path2FeiertagAdapter').on('click', function () {
initSelectId(function (sid) {
sid.selectId('show', $('#Path2FeiertagAdapter').val(), function (newId) {
if (newId) {
$('#Path2FeiertagAdapter').val(newId).trigger('change');
}
});
});
});
$('#OID_Path2PresentDP').on('click', function () {
initSelectId(function (sid) {
sid.selectId('show', $('#Path2PresentDP').val(), function (newId) {
if (newId) {
$('#Path2PresentDP').val(newId).trigger('change');
}
});
});
});
$('#OID_Path2VacationDP').on('click', function () {
initSelectId(function (sid) {
sid.selectId('show', $('#Path2VacationDP').val(), function (newId) {
if (newId) {
$('#Path2VacationDP').val(newId).trigger('change');
}
});
});
});
$('#OID_Path2HolidayPresentDP').on('click', function () {
initSelectId(function (sid) {
sid.selectId('show', $('#Path2HolidayPresentDP').val(), function (newId) {
if (newId) {
$('#Path2HolidayPresentDP').val(newId).trigger('change');
}
});
});
});
$('#OID_Path2GuestsPresentDP').on('click', function () {
initSelectId(function (sid) {
sid.selectId('show', $('#Path2GuestsPresentDP').val(), function (newId) {
if (newId) {
$('#Path2GuestsPresentDP').val(newId).trigger('change');
}
});
});
});
$('#OID_Path2PartyNowDP').on('click', function () {
initSelectId(function (sid) {
sid.selectId('show', $('#Path2PartyNowDP').val(), function (newId) {
if (newId) {
$('#Path2PartyNowDP').val(newId).trigger('change');
}
});
});
});
//===========================================================================
//maintanance functions
console.log('aaa');
$('#btn_deleteunusedDP').on('click', function () {
sendTo(_id, 'deleteUnusedDP', null, function (result) {
console.log('deleteUnusedDP done ');
$('#result_deleteunusedDP').html(result);
});
});
$('#btn_deleteunusedConfig').on('click', function () {
DeleteUnusedConfig();
});
$('#notificationsType').on('change', function () {
console.log('bbb ' + $(this).val());
ShowHideNotificationSettings($(this).val());
});
$('#discordTarget').on('change', function () {
console.log('b1b1b1 ' + $(this).val());
ShowHideNotificationDiscordSettings($(this).val());
});
getAdapterInstances('telegram', function (instances) {
fillInstances('telegramInstance', instances, settings['telegramInstance'], 'telegram');
});
getAdapterInstances('whatsapp-cmb', function (instances) {
fillInstances('whatsappInstance', instances, settings['whatsappInstance'], 'whatsapp-cmb');
});
getAdapterInstances('signal-cmb', function (instances) {
fillInstances('signalInstance', instances, settings['signalInstance'], 'signal-cmb');
});
getAdapterInstances('email', function (instances) {
fillInstances('emailInstance', instances, settings['emailInstance'], 'email');
});
getAdapterInstances('pushover', function (instances) {
fillInstances('pushoverInstance', instances, settings['pushoverInstance'], 'pushover');
});
getAdapterInstances('discord', function (instances) {
fillInstances('discordInstance', instances, settings['discordInstance'], 'discord');
});
$('#telegramInstance').on('change', function () {
getTelegramUser(onChange, instance, "allTelegramUsers");
});
//initil set data
console.log("telegram " + settings['telegramUser']);
getTelegramUser(onChange, instance, settings['telegramUser'] );
//===========================================================================
//power interruptions
values2table('PowerInterruptions', settings.PowerInterruptions, onChange, tablePowerInterruptionsOnReady);
//++++++++++ TABS ++++++++++
//Enhance Tabs with onShow-Function
$('ul.tabs li a').on('click', function () { onTabShow($(this).attr('href')); });
function onTabShow(tabId) {
console.log('onTabShow');
switch (tabId) {
case "#tab-main":
loadOptions();
break;
}
}
function loadOptions() {
$('.collapsible').collapsible();
}
loadOptions();
}
function tablePowerInterruptionsOnReady() {
console.log('tablePowerInterruptionsOnReady, do nothing');
}
function fillInstances(id, arr, val, name) {
var $sel = $('#' + id);
$sel.html('<option value="">' + _('none') + '</option>');
for (var i = 0; i < arr.length; i++) {
var _id = arr[i]._id.replace('system.adapter.', '');
$sel.append('<option value="' + _id + '"' + (_id === val ? ' selected' : '') + '>' + _id + '</option>');
}
$sel.select();
}
// ... and the function save has to exist.
// you have to make sure the callback is called with the settings object as first param!
function save(callback) {
var obj = {};
$('.value').each(function () {
var $this = $(this);
var id = $this.attr('id');
if ($this.attr('type') === 'checkbox') {
obj[$this.attr('id')] = $this.prop('checked');
} else {
obj[$this.attr('id')] = $this.val();
}
});
obj.rooms = table2values('rooms');
if (obj != null && obj.rooms != null) {
for (let i = 0; i < obj.rooms.length; i++) {
console.log('check room ' + obj.rooms[i].name);
obj.rooms[i].name = obj.rooms[i].name.replace('.', '_');
}
}
if (DeviceList != null) {
obj.devices = DeviceList;
}
//===========================================================================
//power interruptions
obj.PowerInterruptions = table2values('PowerInterruptions');
callback(obj);
}
function tableRoomsOnReady() {
console.log('tableRoomsOnReady');
$('#rooms .table-values-div .table-values .values-buttons[data-command="edit"]').on('click', function () {
let id = $(this).data('index');
let room = $('#rooms .values-input[data-name="name"][data-index="' + id + '"]').val();
$('#dialogDeviceEditRoom').html(room);
let val1 = $('#rooms .values-input[data-name="WaitForTempIfWindowOpen"][data-index="' + id + '"]').val();
$('#WaitForTempIfWindowOpen').val(val1);
console.log('set val1 ' + val1);
setTimeout(function () {
initDialogRoom(room, function () {
//this is reached when dialog is closing
let room = $('#dialogDeviceEditRoom')[0].innerHTML;
console.log('closing for ' + room);
//xxx
//find room data in table and update
let WaitForTempIfWindowOpen = $('#WaitForTempIfWindowOpen').val();
console.log('WaitForTempIfWindowOpen ' + WaitForTempIfWindowOpen);
if (WaitForTempIfWindowOpen >= 0) {
$('#rooms .values-input[data-name="WaitForTempIfWindowOpen"][data-index="' + id + '"]').val(WaitForTempIfWindowOpen).trigger('change');
}
let thermostats = table2values('thermostats');
let actors = table2values('actors');
let sensors = table2values('sensors');
let addtempsensors = table2values('addtempsensors');
console.log('Thermostatlist ' + JSON.stringify(thermostats));
console.log('Actorlist ' + JSON.stringify(actors));
console.log('Sensorlist ' + JSON.stringify(sensors));
console.log('AddTempSensorlist ' + JSON.stringify(addtempsensors));
//now update DeviceList
if (thermostats != null) {
for (let i = 0; i < thermostats.length; i++) {
//if exist, only update
if (thermostats[i].id > 0) {
console.log("update thermostats " + JSON.stringify(thermostats[i]));
DeviceList[thermostats[i].id - 1].name = thermostats[i].name;
DeviceList[thermostats[i].id - 1].isActive = thermostats[i].isActive;
DeviceList[thermostats[i].id - 1].OID_Target = thermostats[i].OID_Target;
DeviceList[thermostats[i].id - 1].OID_Current = thermostats[i].OID_Current;
DeviceList[thermostats[i].id - 1].useExtHandling = thermostats[i].useExtHandling;
}
else {
//if not exist, add at the end of list
thermostats[i].id = DeviceList.length + 1;
thermostats[i].type = 1;
thermostats[i].room = room;
console.log("add thermostats " + JSON.stringify(thermostats[i]));
DeviceList.push(thermostats[i]);
}
}