Skip to content

Commit

Permalink
WIP - Pre migratration to hap-client
Browse files Browse the repository at this point in the history
  • Loading branch information
NorthernMan54 committed Nov 23, 2024
1 parent 1a1d8d6 commit bf1ecac
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 259 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
],
"ext": "js,html",
"ignore": [],
"exec": "DEBUG=hapNodeRed ~/npm/bin/node-red -u test/node-red",
"exec": "DEBUG=hapNodeRed* ~/npm/bin/node-red -u test/node-red",
"signal": "SIGTERM",
"env": {
"NODE_OPTIONS": "--trace-warnings"
Expand Down
134 changes: 67 additions & 67 deletions src/HAP-NodeRed.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@
// var pass = $('#node-config-input-password').val();
// console.log("pass: ", pass);
// if (pass != '_PWD_') {
// var account = {
// var configNode = {
// id: node.id,
// user: user,
// pass: pass
// }
// $.ajax({
// data: JSON.stringify(account),
// url: 'alexa-home/new-account',
// data: JSON.stringify(configNode),
// url: 'alexa-home/new-configNode',
// contentType: 'application/json',
// type: 'POST',
// processData: false
Expand Down Expand Up @@ -167,14 +167,14 @@ <h3>Details</h3>
oneditprepare: function() {
var node = this;
// console.log("foo " + node.device);
if (typeof node.acknoledge === 'undefined') {
$('#node-input-acknoledge').prop('checked', true);
if (typeof node.acknowledge === 'undefined') {
$('#node-input-acknowledge').prop('checked', true);
}
$('#node-input-device').change(function() {
$('#node-input-name').val($('#node-input-device option:selected').text());
});
var getDevs = function(account) {
$.getJSON('hap-device/evDevices/' + account, function(data) {
var getDevs = function(configNode) {
$.getJSON('hap-device/evDevices/' + configNode, function(data) {
$('#node-input-device').find('option').remove().end();
for (d in data) {
$('<option/>', {
Expand All @@ -196,32 +196,32 @@ <h3>Details</h3>

}
if (node.conf) {
var account = $('#node-input-conf').val();
// console.log("account: ", account);
if (account != '_ADD_') {
getDevs(account);
var configNode = $('#node-input-conf').val();
// console.log("configNode: ", configNode);
if (configNode != '_ADD_') {
getDevs(configNode);
}
}
$('#node-input-conf').change(function() {
var account = $('#node-input-conf').val();
// console.log("account changed: ", account);
if (account != '_ADD_') {
getDevs(account);
var configNode = $('#node-input-conf').val();
// console.log("configNode changed: ", configNode);
if (configNode != '_ADD_') {
getDevs(configNode);
} else {
// console.log("new account");
// console.log("new configNode");
$('#node-input-device').find('option').remove().end();
$('#node-input-device').val("");
}
});
$('#node-input-device-refresh').click(function() {
$('#node-input-device-refresh').addClass('disabled');
var account = $('#node-input-conf').val();
var configNode = $('#node-input-conf').val();
$.ajax({
url: 'hap-device/refresh/' + account,
url: 'hap-device/refresh/' + configNode,
type: 'POST'
}).done(function(data) {
setTimeout(function() {
getDevs(account);
getDevs(configNode);
$('#node-input-device-refresh').removeClass('disabled');
}, 3000);
});
Expand Down Expand Up @@ -317,15 +317,15 @@ <h3>Where and why would you use this node?</h3>
oneditprepare: function() {
var node = this;
// console.log("foo " + node.device);
if (typeof node.acknoledge === 'undefined') {
if (typeof node.acknowledge === 'undefined') {
// console.log("ben");
$('#node-input-acknoledge').prop('checked', true);
$('#node-input-acknowledge').prop('checked', true);
}
$('#node-input-device').change(function() {
$('#node-input-name').val($('#node-input-device option:selected').text());
});
var getDevs = function(account) {
$.getJSON('hap-device/evDevices/' + account, function(data) {
var getDevs = function(configNode) {
$.getJSON('hap-device/evDevices/' + configNode, function(data) {
$('#node-input-device').find('option').remove().end();
for (d in data) {
$('<option/>', {
Expand All @@ -348,32 +348,32 @@ <h3>Where and why would you use this node?</h3>

}
if (node.conf) {
var account = $('#node-input-conf').val();
// console.log("account: ", account);
if (account != '_ADD_') {
getDevs(account);
var configNode = $('#node-input-conf').val();
// console.log("configNode: ", configNode);
if (configNode != '_ADD_') {
getDevs(configNode);
}
}
$('#node-input-conf').change(function() {
var account = $('#node-input-conf').val();
// console.log("account changed: ", account);
if (account != '_ADD_') {
getDevs(account);
var configNode = $('#node-input-conf').val();
// console.log("configNode changed: ", configNode);
if (configNode != '_ADD_') {
getDevs(configNode);
} else {
// console.log("new account");
// console.log("new configNode");
$('#node-input-device').find('option').remove().end();
$('#node-input-device').val("");
}
});
$('#node-input-device-refresh').click(function() {
$('#node-input-device-refresh').addClass('disabled');
var account = $('#node-input-conf').val();
var configNode = $('#node-input-conf').val();
$.ajax({
url: 'hap-device/refresh/' + account,
url: 'hap-device/refresh/' + configNode,
type: 'POST'
}).done(function(data) {
setTimeout(function() {
getDevs(account);
getDevs(configNode);
$('#node-input-device-refresh').removeClass('disabled');
}, 3000);
});
Expand Down Expand Up @@ -467,15 +467,15 @@ <h3>Details</h3>
oneditprepare: function() {
var node = this;
// console.log("foo " + node.device);
if (typeof node.acknoledge === 'undefined') {
if (typeof node.acknowledge === 'undefined') {
// console.log("ben");
$('#node-input-acknoledge').prop('checked', true);
$('#node-input-acknowledge').prop('checked', true);
}
$('#node-input-device').change(function() {
$('#node-input-name').val($('#node-input-device option:selected').text());
});
var getDevs = function(account) {
$.getJSON('hap-device/evDevices/' + account, function(data) {
var getDevs = function(configNode) {
$.getJSON('hap-device/evDevices/' + configNode, function(data) {
$('#node-input-device').find('option').remove().end();
for (d in data) {
$('<option/>', {
Expand All @@ -498,32 +498,32 @@ <h3>Details</h3>

}
if (node.conf) {
var account = $('#node-input-conf').val();
// console.log("account: ", account);
if (account != '_ADD_') {
getDevs(account);
var configNode = $('#node-input-conf').val();
// console.log("configNode: ", configNode);
if (configNode != '_ADD_') {
getDevs(configNode);
}
}
$('#node-input-conf').change(function() {
var account = $('#node-input-conf').val();
// console.log("account changed: ", account);
if (account != '_ADD_') {
getDevs(account);
var configNode = $('#node-input-conf').val();
// console.log("configNode changed: ", configNode);
if (configNode != '_ADD_') {
getDevs(configNode);
} else {
// console.log("new account");
// console.log("new configNode");
$('#node-input-device').find('option').remove().end();
$('#node-input-device').val("");
}
});
$('#node-input-device-refresh').click(function() {
$('#node-input-device-refresh').addClass('disabled');
var account = $('#node-input-conf').val();
var configNode = $('#node-input-conf').val();
$.ajax({
url: 'hap-device/refresh/' + account,
url: 'hap-device/refresh/' + configNode,
type: 'POST'
}).done(function(data) {
setTimeout(function() {
getDevs(account);
getDevs(configNode);
$('#node-input-device-refresh').removeClass('disabled');
}, 3000);
});
Expand Down Expand Up @@ -620,15 +620,15 @@ <h3>Details</h3>
oneditprepare: function() {
var node = this;
// console.log("foo " + node.device);
if (typeof node.acknoledge === 'undefined') {
if (typeof node.acknowledge === 'undefined') {
// console.log("ben");
$('#node-input-acknoledge').prop('checked', true);
$('#node-input-acknowledge').prop('checked', true);
}
$('#node-input-device').change(function() {
$('#node-input-name').val($('#node-input-device option:selected').text());
});
var getDevs = function(account) {
$.getJSON('hap-device/ctDevices/' + account, function(data) {
var getDevs = function(configNode) {
$.getJSON('hap-device/ctDevices/' + configNode, function(data) {
$('#node-input-device').find('option').remove().end();
for (d in data) {
$('<option/>', {
Expand All @@ -651,32 +651,32 @@ <h3>Details</h3>

}
if (node.conf) {
var account = $('#node-input-conf').val();
// console.log("account: ", account);
if (account != '_ADD_') {
getDevs(account);
var configNode = $('#node-input-conf').val();
// console.log("configNode: ", configNode);
if (configNode != '_ADD_') {
getDevs(configNode);
}
}
$('#node-input-conf').change(function() {
var account = $('#node-input-conf').val();
// console.log("account changed: ", account);
if (account != '_ADD_') {
getDevs(account);
var configNode = $('#node-input-conf').val();
// console.log("configNode changed: ", configNode);
if (configNode != '_ADD_') {
getDevs(configNode);
} else {
// console.log("new account");
// console.log("new configNode");
$('#node-input-device').find('option').remove().end();
$('#node-input-device').val("");
}
});
$('#node-input-device-refresh').click(function() {
$('#node-input-device-refresh').addClass('disabled');
var account = $('#node-input-conf').val();
var configNode = $('#node-input-conf').val();
$.ajax({
url: 'hap-device/refresh/' + account,
url: 'hap-device/refresh/' + configNode,
type: 'POST'
}).done(function(data) {
setTimeout(function() {
getDevs(account);
getDevs(configNode);
$('#node-input-device-refresh').removeClass('disabled');
}, 3000);
});
Expand Down
66 changes: 30 additions & 36 deletions src/HAP-NodeRed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var debug = require('debug')('hapNodeRed');

// var register = require('./lib/register.js');

const HBConfNode = require('./hbConfigNode');
const HBConfigNode = require('./hbConfigNode');
const HbEventNode = require('./hbEventNode'); // Import the class
const HbResumeNode = require('./hbResumeNode'); // Import the class
const HbControlNode = require('./hbControlNode');
Expand All @@ -23,19 +23,15 @@ module.exports = function (RED) {
* @return {type} description
*/

function hbConfNode(config) {
console.log('hbConfNode', config, this);
RED.nodes.createNode(this, config);
this.username = config.username;
this.macAddress = config.macAddress || '';
this.password = this.password;
this.hbConfNode = new HBConfNode(config, RED);
this.on('close', function () {
this.hbConf.close(); // Close any open connections
});
class hbConfigNode extends HBConfigNode {
constructor(config) {
debug('hbConfigNode', config);
super(config, RED);
}
}
console.log('Registering node types', "hb-conf", hbConfNode);
RED.nodes.registerType("hb-conf", hbConfNode, {

// console.log('Registering node types', "hb-conf", hbConfigNode);
RED.nodes.registerType("hb-conf", hbConfigNode, {
credentials: {
password: {
type: "password"
Expand All @@ -48,32 +44,32 @@ module.exports = function (RED) {
* hbEventNode - description
* @param {*} n
*/
function hbEventNode(n) {
RED.nodes.createNode(this, n);

// Create instance of HbEventNode class to handle events
new HbEventNode(this, n); // Pass current node and config object
class hbEventNode extends HbEventNode {
constructor(config) {
debug('hbEventNode', config);
super(config, RED);
}
}

RED.nodes.registerType("hb-event", hbEventNode);

/**
* hbResumeNode - description
*/
function hbResumeNode(n) {
RED.nodes.createNode(this, n);

// Create instance of HbEventNode class to handle events
new HbResumeNode(this, n); // Pass current node and config object
class hbResumeNode extends HbResumeNode {
constructor(config) {
debug('hbResumeNode', config);
super(config, RED);
}
}

RED.nodes.registerType("hb-resume", hbResumeNode);

function hbControlNode(n) {
RED.nodes.createNode(this, n);

// Create instance of HbEventNode class to handle events
new HbControlNode(this, n); // Pass current node and config object
class hbControlNode extends HbControlNode {
constructor(config) {
debug('hbControlNode', config);
super(config, RED);
}
}

RED.nodes.registerType("hb-control", hbControlNode);
Expand All @@ -84,18 +80,16 @@ module.exports = function (RED) {
* @param {type} n description
* @return {type} description
*/


function hbStatusNode(n) {
RED.nodes.createNode(this, n);

// Create instance of HbEventNode class to handle events
new HbStatusNode(this, n); // Pass current node and config object
class hbStatusNode extends HbStatusNode {
constructor(config) {
debug('hbStatusNode', config);
super(config, RED);
}
}

RED.nodes.registerType("hb-status", hbStatusNode);

const hapDeviceRoutes = new HapDeviceRoutes(RED, hbDevices, debug);
const hapDeviceRoutes = new HapDeviceRoutes(RED, hbDevices);
hapDeviceRoutes.registerRoutes();

};
Loading

0 comments on commit bf1ecac

Please sign in to comment.