mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-01 22:04:15 +01:00
added zwave model
more cleanups
This commit is contained in:
@@ -38,17 +38,17 @@ FHEM_update(inform_id, value, no_update) {
|
|||||||
|| FHEM_cached[inform_id] === value )
|
|| FHEM_cached[inform_id] === value )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//if( FHEM_internal['.'+subscription.accessory.device+'-homekitID'] == undefined ) {
|
//if( FHEM_internal['.'+subscription.accessory.device+'-homekitID'] == undefined ) {
|
||||||
// var info = subscription.characteristic.accessoryController.tcpServer.accessoryInfo;
|
// var info = subscription.characteristic.accessoryController.tcpServer.accessoryInfo;
|
||||||
|
|
||||||
// if( info.username ) {
|
// if( info.username ) {
|
||||||
// var accessory = subscription.accessory;
|
// var accessory = subscription.accessory;
|
||||||
// var cmd = '{$defs{'+ accessory.device +'}->{homekitID} = "'+info.username+'" if(defined($defs{'+ accessory.device +'}));;}';
|
// var cmd = '{$defs{'+ accessory.device +'}->{homekitID} = "'+info.username+'" if(defined($defs{'+ accessory.device +'}));;}';
|
||||||
// //accessory.execute( cmd );
|
// //accessory.execute( cmd );
|
||||||
|
|
||||||
// FHEM_internal['.'+accessory.device+'-homekitID'] = info.username;
|
// FHEM_internal['.'+accessory.device+'-homekitID'] = info.username;
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
FHEM_cached[inform_id] = value;
|
FHEM_cached[inform_id] = value;
|
||||||
//FHEM_cached[inform_id] = { 'value': value, 'timestamp': Date.now() };
|
//FHEM_cached[inform_id] = { 'value': value, 'timestamp': Date.now() };
|
||||||
@@ -60,9 +60,9 @@ FHEM_update(inform_id, value, no_update) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var FHEM_lastEventTimestamp;
|
var FHEM_lastEventTime;
|
||||||
var FHEM_longpoll_running = false;
|
var FHEM_longpoll_running = false;
|
||||||
//FIXME: force reconnect on xxx bytes received ?, add filter, add since
|
//FIXME: add filter
|
||||||
function FHEM_startLongpoll(connection) {
|
function FHEM_startLongpoll(connection) {
|
||||||
if( FHEM_longpoll_running )
|
if( FHEM_longpoll_running )
|
||||||
return;
|
return;
|
||||||
@@ -70,6 +70,8 @@ function FHEM_startLongpoll(connection) {
|
|||||||
|
|
||||||
var filter = ".*";
|
var filter = ".*";
|
||||||
var since = "null";
|
var since = "null";
|
||||||
|
if( FHEM_lastEventTime )
|
||||||
|
since = FHEM_lastEventTime/1000;
|
||||||
var query = "/fhem.pl?XHR=1"+
|
var query = "/fhem.pl?XHR=1"+
|
||||||
"&inform=type=status;filter="+filter+";since="+since+";fmt=JSON"+
|
"&inform=type=status;filter="+filter+";since="+since+";fmt=JSON"+
|
||||||
"×tamp="+Date.now()
|
"×tamp="+Date.now()
|
||||||
@@ -85,8 +87,9 @@ function FHEM_startLongpoll(connection) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
input += data;
|
input += data;
|
||||||
|
var lastEventTime = Date.now();
|
||||||
for(;;) {
|
for(;;) {
|
||||||
var nOff = input.indexOf("\n", FHEM_longpollOffset);
|
var nOff = input.indexOf('\n', FHEM_longpollOffset);
|
||||||
if(nOff < 0)
|
if(nOff < 0)
|
||||||
break;
|
break;
|
||||||
var l = input.substr(FHEM_longpollOffset, nOff-FHEM_longpollOffset);
|
var l = input.substr(FHEM_longpollOffset, nOff-FHEM_longpollOffset);
|
||||||
@@ -113,7 +116,7 @@ function FHEM_startLongpoll(connection) {
|
|||||||
var subscription = FHEM_subscriptions[d[0]];
|
var subscription = FHEM_subscriptions[d[0]];
|
||||||
if( subscription != undefined ) {
|
if( subscription != undefined ) {
|
||||||
//console.log( "Rcvd: "+(l.length>132 ? l.substring(0,132)+"...("+l.length+")":l) );
|
//console.log( "Rcvd: "+(l.length>132 ? l.substring(0,132)+"...("+l.length+")":l) );
|
||||||
FHEM_lastEventTimestamp = Date.now();
|
FHEM_lastEventTime = lastEventTime;
|
||||||
var accessory = subscription.accessory;
|
var accessory = subscription.accessory;
|
||||||
|
|
||||||
var value = d[1];
|
var value = d[1];
|
||||||
@@ -393,11 +396,12 @@ FHEMPlatform.prototype = {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( accessory )
|
if( accessory && Object.getOwnPropertyNames(accessory).length )
|
||||||
foundAccessories.push(accessory);
|
foundAccessories.push(accessory);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(foundAccessories);
|
callback(foundAccessories);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -417,6 +421,20 @@ FHEMAccessory(log, connection, s) {
|
|||||||
//log("got json: " + util.inspect(s) );
|
//log("got json: " + util.inspect(s) );
|
||||||
//log("got json: " + util.inspect(s.Internals) );
|
//log("got json: " + util.inspect(s.Internals) );
|
||||||
|
|
||||||
|
if( !(this instanceof FHEMAccessory) )
|
||||||
|
return new FHEMAccessory(log, connection, s);
|
||||||
|
|
||||||
|
if( s.Attributes.disable == 1 ) {
|
||||||
|
that.log( s.Internals.NAME + ' is disabled');
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} else if( s.Internals.TYPE == 'structure' ) {
|
||||||
|
that.log( s.Internals.NAME + ' is a structure');
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this.mappings = {};
|
this.mappings = {};
|
||||||
|
|
||||||
var match;
|
var match;
|
||||||
@@ -570,12 +588,14 @@ FHEMAccessory(log, connection, s) {
|
|||||||
log( s.Internals.NAME + ' is dimable [0-'+ s.pctMax +']' );
|
log( s.Internals.NAME + ' is dimable [0-'+ s.pctMax +']' );
|
||||||
else if( s.isLight )
|
else if( s.isLight )
|
||||||
log( s.Internals.NAME + ' is light' );
|
log( s.Internals.NAME + ' is light' );
|
||||||
else
|
else if( this.mappings.onOff || s.isSwitch )
|
||||||
log( s.Internals.NAME + ' is switchable' );
|
log( s.Internals.NAME + ' is switchable' );
|
||||||
|
else
|
||||||
|
return {};
|
||||||
|
|
||||||
if( this.hasOnOff )
|
|
||||||
log( s.Internals.NAME + ' has OnOff [' + this.hasOnOff + ']' );
|
|
||||||
|
|
||||||
|
if( this.mappings.onOff )
|
||||||
|
log( s.Internals.NAME + ' has onOff [' + this.mappings.onOff + ']' );
|
||||||
if( this.mappings.hue )
|
if( this.mappings.hue )
|
||||||
log( s.Internals.NAME + ' has hue [0-' + this.mappings.hue.max +']' );
|
log( s.Internals.NAME + ' has hue [0-' + this.mappings.hue.max +']' );
|
||||||
if( this.mappings.sat )
|
if( this.mappings.sat )
|
||||||
@@ -594,7 +614,7 @@ FHEMAccessory(log, connection, s) {
|
|||||||
this.alias = s.Attributes.alias ? s.Attributes.alias : s.Internals.NAME;
|
this.alias = s.Attributes.alias ? s.Attributes.alias : s.Internals.NAME;
|
||||||
this.device = s.Internals.NAME;
|
this.device = s.Internals.NAME;
|
||||||
this.type = s.Internals.TYPE;
|
this.type = s.Internals.TYPE;
|
||||||
this.model = s.Attributes.model ? s.Attributes.model : s.Internals.model;
|
this.model = s.Attributes.model ? s.Attributes.model : (s.Internals.model ? s.Internals.model : s.Readings.model.Value);
|
||||||
this.PossibleSets = s.PossibleSets;
|
this.PossibleSets = s.PossibleSets;
|
||||||
|
|
||||||
if( this.type == 'CUL_HM' ) {
|
if( this.type == 'CUL_HM' ) {
|
||||||
@@ -635,6 +655,7 @@ FHEMAccessory(log, connection, s) {
|
|||||||
if( value != undefined ) {
|
if( value != undefined ) {
|
||||||
var inform_id = that.device +'-'+ reading;
|
var inform_id = that.device +'-'+ reading;
|
||||||
that.mappings[key].informId = inform_id;
|
that.mappings[key].informId = inform_id;
|
||||||
|
|
||||||
if( !that.mappings[key].nocache )
|
if( !that.mappings[key].nocache )
|
||||||
FHEM_cached[inform_id] = value;
|
FHEM_cached[inform_id] = value;
|
||||||
}
|
}
|
||||||
@@ -643,6 +664,10 @@ FHEMAccessory(log, connection, s) {
|
|||||||
|
|
||||||
this.log = log;
|
this.log = log;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
|
|
||||||
|
this.onRegister = function(accessory) {
|
||||||
|
console.log( ">>>>>>>>>>>>:" + util.inspect(accessory) );
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
FHEM_dim_values = [ 'dim06%', 'dim12%', 'dim18%', 'dim25%', 'dim31%', 'dim37%', 'dim43%', 'dim50%', 'dim56%', 'dim62%', 'dim68%', 'dim75%', 'dim81%', 'dim87%', 'dim93%' ];
|
FHEM_dim_values = [ 'dim06%', 'dim12%', 'dim18%', 'dim25%', 'dim31%', 'dim37%', 'dim43%', 'dim50%', 'dim56%', 'dim62%', 'dim68%', 'dim75%', 'dim81%', 'dim87%', 'dim93%' ];
|
||||||
@@ -732,7 +757,7 @@ FHEMAccessory.prototype = {
|
|||||||
value = 0;
|
value = 0;
|
||||||
else if( value == '000000' )
|
else if( value == '000000' )
|
||||||
value = 0;
|
value = 0;
|
||||||
else if( value.match( /^[A-D]0$/ ) ) // FIXME: should be handled by event_map now
|
else if( value.match( /^[A-D]0$/ ) ) //FIXME: is handled by event_map now
|
||||||
value = 0;
|
value = 0;
|
||||||
else
|
else
|
||||||
value = 1;
|
value = 1;
|
||||||
@@ -760,7 +785,7 @@ FHEMAccessory.prototype = {
|
|||||||
if( this.type == 'HUEDevice' )
|
if( this.type == 'HUEDevice' )
|
||||||
cmd = "set " + this.device + "alert select";
|
cmd = "set " + this.device + "alert select";
|
||||||
else
|
else
|
||||||
cmd = "set " + this.device + " toggle;; sleep 1;; set "+ this.device + " toggle";
|
cmd = "set " + this.device + " toggle; sleep 1; set "+ this.device + " toggle";
|
||||||
|
|
||||||
} else if( c == 'set' ) {
|
} else if( c == 'set' ) {
|
||||||
cmd = "set " + this.device + " " + value;
|
cmd = "set " + this.device + " " + value;
|
||||||
@@ -971,7 +996,7 @@ FHEMAccessory.prototype = {
|
|||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
|
|
||||||
informationCharacteristics: function() {
|
informationCharacteristics: function(that) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
cType: types.NAME_CTYPE,
|
cType: types.NAME_CTYPE,
|
||||||
@@ -1016,7 +1041,7 @@ FHEMAccessory.prototype = {
|
|||||||
},{
|
},{
|
||||||
cType: types.IDENTIFY_CTYPE,
|
cType: types.IDENTIFY_CTYPE,
|
||||||
onUpdate: function(value) {
|
onUpdate: function(value) {
|
||||||
if( this.mappings.onOff )
|
if( that.mappings.onOff )
|
||||||
that.command( 'identify' );
|
that.command( 'identify' );
|
||||||
},
|
},
|
||||||
perms: ["pw"],
|
perms: ["pw"],
|
||||||
@@ -1244,7 +1269,6 @@ FHEMAccessory.prototype = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME: use mapping.volume
|
|
||||||
if( this.mappings.volume ) {
|
if( this.mappings.volume ) {
|
||||||
cTypes.push({
|
cTypes.push({
|
||||||
cType: types.OUTPUTVOLUME_CTYPE,
|
cType: types.OUTPUTVOLUME_CTYPE,
|
||||||
@@ -1658,7 +1682,7 @@ FHEMAccessory.prototype = {
|
|||||||
var that = this;
|
var that = this;
|
||||||
var services = [{
|
var services = [{
|
||||||
sType: types.ACCESSORY_INFORMATION_STYPE,
|
sType: types.ACCESSORY_INFORMATION_STYPE,
|
||||||
characteristics: this.informationCharacteristics(),
|
characteristics: this.informationCharacteristics(that),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sType: this.sType(),
|
sType: this.sType(),
|
||||||
@@ -1684,8 +1708,8 @@ function FHEMdebug_handleRequest(request, response){
|
|||||||
|
|
||||||
if( request.url == "/cached" ) {
|
if( request.url == "/cached" ) {
|
||||||
response.write( "<a href='/'>home</a><br><br>" );
|
response.write( "<a href='/'>home</a><br><br>" );
|
||||||
if( FHEM_lastEventTimestamp )
|
if( FHEM_lastEventTime )
|
||||||
response.write( "FHEM_lastEventTime: "+ new Date(FHEM_lastEventTimestamp) +"<br><br>" );
|
response.write( "FHEM_lastEventTime: "+ new Date(FHEM_lastEventTime) +"<br><br>" );
|
||||||
response.end( "cached: " + util.inspect(FHEM_cached).replace(/\n/g, '<br>') );
|
response.end( "cached: " + util.inspect(FHEM_cached).replace(/\n/g, '<br>') );
|
||||||
|
|
||||||
} else if( request.url == "/subscriptions" ) {
|
} else if( request.url == "/subscriptions" ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user