@ -336,60 +336,43 @@ function toggleMenu() {
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Templates
// Domoticz
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function createRelays ( count ) {
function createRelayIdxs ( data ) {
var current = $ ( "#r elays > div" ) . length ;
var current = $ ( "#domoticzR elays > div" ) . length ;
if ( current > 0 ) return ;
if ( current > 0 ) return ;
var template = $ ( "#relayTemplate .pure-g" ) [ 0 ] ;
for ( var relayID = 0 ; relayID < count ; relayID ++ ) {
var template = $ ( "#relayIdx Template .pure-g" ) [ 0 ] ;
for ( var i = 0 ; i < data . length ; i ++ ) {
var line = $ ( template ) . clone ( ) ;
var line = $ ( template ) . clone ( ) ;
$ ( line ) . find ( "input" ) . each ( function ( ) {
$ ( this ) . attr ( "data" , relayID ) ;
} ) ;
if ( count > 1 ) $ ( ".relay_id" , line ) . html ( " " + ( relayID + 1 ) ) ;
line . appendTo ( "#relays" ) ;
$ ( ":checkbox" , line ) . iphoneStyle ( {
onChange : doToggle ,
resizeContainer : true ,
resizeHandle : true ,
checkedLabel : 'ON' ,
uncheckedLabel : 'OFF'
} ) ;
if ( data . length > 1 ) $ ( "label" , line ) . html ( "Switch #" + i ) ;
$ ( "input" , line ) . attr ( "name" , "dczRelayIdx" + i ) . attr ( "tabindex" , 40 + i ) . val ( data [ i ] ) ;
line . appendTo ( "#domoticzRelays" ) ;
}
}
}
}
function createIdxs ( count ) {
function createSensorIdxs ( data ) {
var current = $ ( "#idx s > div" ) . length ;
var current = $ ( "#domoticzSensors > div" ) . length ;
if ( current > 0 ) return ;
if ( current > 0 ) return ;
var template = $ ( "#i dxTemplate .pure-g" ) [ 0 ] ;
for ( var id = 0 ; id < count ; id ++ ) {
var template = $ ( "#sensorIdxTemplate .pure-g" ) [ 0 ] ;
for ( var i = 0 ; i < data . length ; i ++ ) {
var line = $ ( template ) . clone ( ) ;
var line = $ ( template ) . clone ( ) ;
$ ( line ) . find ( "input" ) . each ( function ( ) {
$ ( this ) . attr ( "data" , id ) . attr ( "tabindex" , 40 + id ) ;
} ) ;
if ( count > 1 ) $ ( ".id" , line ) . html ( " " + id ) ;
line . appendTo ( "#idxs" ) ;
$ ( "label" , line ) . html ( sensorType ( data [ i ] . type ) ) ;
$ ( "div.hint" , line ) . html ( data [ i ] . name ) ;
$ ( "input" , line ) . attr ( "name" , "dczSensor" + i ) . attr ( "tabindex" , 40 + i ) . val ( data [ i ] . idx ) ;
line . appendTo ( "#domoticzSensors" ) ;
}
}
}
}
function delNetwork ( ) {
var parent = $ ( this ) . parents ( ".pure-g" ) ;
$ ( parent ) . remove ( ) ;
}
function moreNetwork ( ) {
var parent = $ ( this ) . parents ( ".pure-g" ) ;
$ ( "div.more" , parent ) . toggle ( ) ;
}
// -----------------------------------------------------------------------------
// Wifi
// -----------------------------------------------------------------------------
function addNetwork ( ) {
function addNetwork ( ) {
@ -413,6 +396,43 @@ function addNetwork() {
}
}
function delNetwork ( ) {
var parent = $ ( this ) . parents ( ".pure-g" ) ;
$ ( parent ) . remove ( ) ;
}
function moreNetwork ( ) {
var parent = $ ( this ) . parents ( ".pure-g" ) ;
$ ( "div.more" , parent ) . toggle ( ) ;
}
// -----------------------------------------------------------------------------
// Relays
// -----------------------------------------------------------------------------
function initRelays ( data ) {
var current = $ ( "#relays > div" ) . length ;
if ( current > 0 ) return ;
var template = $ ( "#relayTemplate .pure-g" ) [ 0 ] ;
for ( var i = 0 ; i < data . length ; i ++ ) {
var line = $ ( template ) . clone ( ) ;
if ( data . length > 1 ) $ ( ".relay_id" , line ) . html ( " " + ( i + 1 ) ) ;
$ ( "input" , line ) . attr ( "data" , i ) . prop ( "checked" , data [ i ] ) ;
line . appendTo ( "#relays" ) ;
$ ( ":checkbox" , line ) . iphoneStyle ( {
onChange : doToggle ,
resizeContainer : true ,
resizeHandle : true ,
checkedLabel : 'ON' ,
uncheckedLabel : 'OFF'
} ) . iphoneStyle ( "refresh" ) ;
}
}
function addRelayGroup ( ) {
function addRelayGroup ( ) {
var numGroups = $ ( "#relayGroups > div" ) . length ;
var numGroups = $ ( "#relayGroups > div" ) . length ;
@ -430,6 +450,10 @@ function addRelayGroup() {
}
}
// -----------------------------------------------------------------------------
// Sensors
// -----------------------------------------------------------------------------
function initSensors ( data ) {
function initSensors ( data ) {
// check if already initialized
// check if already initialized
@ -448,6 +472,10 @@ function initSensors(data) {
}
}
// -----------------------------------------------------------------------------
// Lights
// -----------------------------------------------------------------------------
function initColorRGB ( ) {
function initColorRGB ( ) {
// check if already initialized
// check if already initialized
@ -538,6 +566,10 @@ function initChannels(num) {
}
}
// -----------------------------------------------------------------------------
// RFBridge
// -----------------------------------------------------------------------------
function addRfbNode ( ) {
function addRfbNode ( ) {
var numNodes = $ ( "#rfbNodes > fieldset" ) . length ;
var numNodes = $ ( "#rfbNodes > fieldset" ) . length ;
@ -583,8 +615,6 @@ function rfbSend() {
function processData ( data ) {
function processData ( data ) {
console . log ( data ) ;
// title
// title
if ( "app_name" in data ) {
if ( "app_name" in data ) {
var title = data . app_name ;
var title = data . app_name ;
@ -600,32 +630,31 @@ function processData(data) {
Object . keys ( data ) . forEach ( function ( key ) {
Object . keys ( data ) . forEach ( function ( key ) {
// Web Modes
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Web mode
// ---------------------------------------------------------------------
if ( key == "webMode" ) {
if ( key == "webMode" ) {
password = data . webMode == 1 ;
password = data . webMode == 1 ;
$ ( "#layout" ) . toggle ( data . webMode == 0 ) ;
$ ( "#layout" ) . toggle ( data . webMode == 0 ) ;
$ ( "#password" ) . toggle ( data . webMode == 1 ) ;
$ ( "#password" ) . toggle ( data . webMode == 1 ) ;
}
}
// ---------------------------------------------------------------------
// Actions
// Actions
if ( key == "action" ) {
if ( data . action == "reload" ) {
doReload ( 1000 ) ;
}
if ( data . action == "rfbLearn" ) {
// Nothing to do?
}
if ( data . action == "rfbTimeout" ) {
// Nothing to do?
}
// ---------------------------------------------------------------------
if ( key == "action" ) {
if ( data . action == "reload" ) doReload ( 1000 ) ;
return ;
return ;
}
}
// ---------------------------------------------------------------------
// RFBridge
// ---------------------------------------------------------------------
if ( key == "rfbCount" ) {
if ( key == "rfbCount" ) {
for ( var i = 0 ; i < data . rfbCount ; i ++ ) addRfbNode ( ) ;
for ( var i = 0 ; i < data . rfbCount ; i ++ ) addRfbNode ( ) ;
return ;
return ;
@ -641,6 +670,10 @@ function processData(data) {
return ;
return ;
}
}
// ---------------------------------------------------------------------
// Lights
// ---------------------------------------------------------------------
if ( key == "rgb" ) {
if ( key == "rgb" ) {
initColorRGB ( ) ;
initColorRGB ( ) ;
$ ( "input[name='color']" ) . wheelColorPicker ( 'setValue' , data [ key ] , true ) ;
$ ( "input[name='color']" ) . wheelColorPicker ( 'setValue' , data [ key ] , true ) ;
@ -679,35 +712,32 @@ function processData(data) {
return ;
return ;
}
}
if ( key == "uptime" ) {
var uptime = parseInt ( data [ key ] ) ;
var seconds = uptime % 60 ; uptime = parseInt ( uptime / 60 ) ;
var minutes = uptime % 60 ; uptime = parseInt ( uptime / 60 ) ;
var hours = uptime % 24 ; uptime = parseInt ( uptime / 24 ) ;
var days = uptime ;
data [ key ] = days + 'd ' + zeroPad ( hours , 2 ) + 'h ' + zeroPad ( minutes , 2 ) + 'm ' + zeroPad ( seconds , 2 ) + 's' ;
}
if ( key == "useWhite" ) {
if ( key == "useWhite" ) {
useWhite = data [ key ] ;
useWhite = data [ key ] ;
}
}
if ( key == "maxNetworks" ) {
maxNetworks = parseInt ( data . maxNetworks ) ;
return ;
}
// ---------------------------------------------------------------------
// Sensors
// Sensors
// ---------------------------------------------------------------------
if ( key == "sensors" ) {
if ( key == "sensors" ) {
initSensors ( data [ key ] ) ;
initSensors ( data [ key ] ) ;
for ( var i = 0 ; i < data [ key ] . length ; i ++ ) {
for ( var i = 0 ; i < data [ key ] . length ; i ++ ) {
var element = $ ( "input[data=" + i + "]" ) ;
var element = $ ( "input[name=sensor][ data=" + i + "]" ) ;
if ( element . length ) element . val ( data [ key ] [ i ] . value + data [ key ] [ i ] . units ) ;
if ( element . length ) element . val ( data [ key ] [ i ] . value + data [ key ] [ i ] . units ) ;
}
}
return ;
return ;
}
}
// Wifi
// ---------------------------------------------------------------------
// WiFi
// ---------------------------------------------------------------------
if ( key == "maxNetworks" ) {
maxNetworks = parseInt ( data . maxNetworks ) ;
return ;
}
if ( key == "wifi" ) {
if ( key == "wifi" ) {
var networks = data . wifi ;
var networks = data . wifi ;
@ -730,23 +760,13 @@ function processData(data) {
}
}
// Relay status
if ( key == "relayStatus" ) {
var relays = data . relayStatus ;
createRelays ( relays . length ) ;
for ( var relayID in relays ) {
var element = $ ( ".relayStatus[data=" + relayID + "]" ) ;
if ( element . length > 0 ) {
element
. prop ( "checked" , relays [ relayID ] )
. iphoneStyle ( "refresh" ) ;
}
}
// ---------------------------------------------------------------------
// Relays
// ---------------------------------------------------------------------
if ( key == "relayStatus" ) {
initRelays ( data [ key ] ) ;
return ;
return ;
}
}
// Relay groups
// Relay groups
@ -771,19 +791,25 @@ function processData(data) {
return ;
return ;
}
}
// ---------------------------------------------------------------------
// Domoticz
// Domoticz
if ( key == "dczRelayIdx" ) {
var idxs = data . dczRelayIdx ;
createIdxs ( idxs . length ) ;
// ---------------------------------------------------------------------
for ( var i in idxs ) {
var element = $ ( ".dczRelayIdx[data=" + i + "]" ) ;
if ( element . length > 0 ) element . val ( idxs [ i ] ) ;
}
// Domoticz - Relays
if ( key == "dczRelayIdx" ) {
createRelayIdxs ( data [ key ] ) ;
return ;
}
// Domoticz - Sensors
if ( key == "dczSensors" ) {
createSensorIdxs ( data [ key ] ) ;
return ;
return ;
}
}
// ---------------------------------------------------------------------
// General
// ---------------------------------------------------------------------
// Messages
// Messages
if ( key == "message" ) {
if ( key == "message" ) {
@ -808,17 +834,19 @@ function processData(data) {
if ( key == "ntpStatus" ) {
if ( key == "ntpStatus" ) {
data . ntpStatus = data . ntpStatus ? "SYNC'D" : "NOT SYNC'D" ;
data . ntpStatus = data . ntpStatus ? "SYNC'D" : "NOT SYNC'D" ;
}
}
if ( key == "tmpUnits" ) {
$ ( "span[name='tmpUnits']" ) . html ( data [ key ] == 1 ? "ºF" : "ºC" ) ;
}
if ( key == "dhtConnected" && ! data [ key ] ) {
$ ( "input[name='dhtTmp']" ) . val ( "NOT CONNECTED" ) ;
$ ( "input[name='dhtHum']" ) . val ( "NOT CONNECTED" ) ;
}
if ( key == "dsConnected" && ! data [ key ] ) {
$ ( "input[name='dsTmp']" ) . val ( "NOT CONNECTED" ) ;
if ( key == "uptime" ) {
var uptime = parseInt ( data [ key ] ) ;
var seconds = uptime % 60 ; uptime = parseInt ( uptime / 60 ) ;
var minutes = uptime % 60 ; uptime = parseInt ( uptime / 60 ) ;
var hours = uptime % 24 ; uptime = parseInt ( uptime / 24 ) ;
var days = uptime ;
data [ key ] = days + 'd ' + zeroPad ( hours , 2 ) + 'h ' + zeroPad ( minutes , 2 ) + 'm ' + zeroPad ( seconds , 2 ) + 's' ;
}
}
// ---------------------------------------------------------------------
// Matching
// ---------------------------------------------------------------------
// Look for INPUTs
// Look for INPUTs
var element = $ ( "input[name=" + key + "]" ) ;
var element = $ ( "input[name=" + key + "]" ) ;
if ( element . length > 0 ) {
if ( element . length > 0 ) {