Skip to content

Commit

Permalink
Remove some unneeded comments and dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
Caprico85 committed Feb 20, 2024
1 parent e302d38 commit ed681c8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
17 changes: 0 additions & 17 deletions devices/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -2053,13 +2053,6 @@ module.exports = function (RED) {
});
}

// Copy the command original params to the payload
/*Object.keys(original_params).forEach(function (key) {
if (!Object.prototype.hasOwnProperty.call(msg.payload, key)) {
msg.payload[key] = original_params[key];
}
});*/

me.send(msg);
}

Expand Down Expand Up @@ -2859,19 +2852,15 @@ module.exports = function (RED) {
updateState(from_states) {
const me = this;
let modified = [];
// me._debug("CCHI updateState state_types " + JSON.stringify(me.state_types));
me._debug('updateState current state ' + JSON.stringify(me.states));
Object.keys(me.state_types).forEach(key => {
if (Object.prototype.hasOwnProperty.call(from_states, key)) {
// console.log("CCHI found key " + key);
let o_modified = me.setState(key, from_states[key], me.states, me.state_types[key]);
if (o_modified) {
me._debug('.updateState set "' + key + '" to ' + JSON.stringify(from_states[key]));
modified.push(o_modified);
}
// console.log("CCHI set " + key + " val " + JSON.stringify(current_state[key]));
}
// else console.log("CCHI NOT found key " + key);
});
let thermostat_modified = false;
if (modified.includes("thermostatTemperatureSetpoint")) {
Expand Down Expand Up @@ -2948,8 +2937,6 @@ module.exports = function (RED) {
};
}
const exclusive_states = state_type.exclusiveStates || [];
// console.log("CCHI ---> setState key " + JSON.stringify(key) + " v " + JSON.stringify(value) + " ov " + JSON.stringify(old_state) + " st " + JSON.stringify(state_type) + " ex " + JSON.stringify(exclusive_states));

if (value == null) {
if (state_type.type & Formats.MANDATORY) {
me.error("key " + key + " is mandatory.");
Expand Down Expand Up @@ -3099,7 +3086,6 @@ module.exports = function (RED) {
}
});
mandatory_to_delete.forEach(ikey => {
// console.log("CCHI try removing " + ikey);
let exclusive_state_found = false;
exclusive_states.forEach(e_state => {
if (typeof state[e_state] !== 'undefined') {
Expand Down Expand Up @@ -3134,7 +3120,6 @@ module.exports = function (RED) {
}
} else {
new_state = Formats.formatValue(key, value, state_type.type & Formats.PRIMITIVE, state_type.defaultValue);
// console.log("CCHI checking new_state " + key + " " + new_state + " type " + JSON.stringify(state_type));
if (state_type.min !== undefined && new_state < state_type.min) {
me.error('key "' + key + '" must be greather or equal than ' + state_type.min);
new_state = undefined;
Expand All @@ -3153,7 +3138,6 @@ module.exports = function (RED) {
}
}
if (new_state !== undefined && !(state_type.type & (Formats.OBJECT | Formats.ARRAY))) {
// console.log("CCHI Update state for " + key + " to " + new_state);
if (old_state !== new_state) {
differs = key;
}
Expand All @@ -3162,7 +3146,6 @@ module.exports = function (RED) {
if (new_state !== undefined && exclusive_states.length > 0) {
exclusive_states.forEach(rkey => delete state[rkey]);
}
// console.log("CCHI END ----> " + key + " = " + JSON.stringify(state[key]));
if (Array.isArray(differs)) {
let o_differs = {};
o_differs[key] = differs;
Expand Down
12 changes: 1 addition & 11 deletions lib/SmartHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class GoogleSmartHome {
let all_urls = [me.Path_join(me._httpPath, 'token')];

let to_remove = [];
REDapp._router.stack.forEach(function (route, i/*, routes*/) {
REDapp._router.stack.forEach(function (route, i) {
if (route.route && (
(route.route.methods['get'] && get_urls.includes(route.route.path)) ||
(route.route.methods['post'] && post_urls.includes(route.route.path)) ||
Expand All @@ -193,7 +193,6 @@ class GoogleSmartHome {
)) {
me.debug('SmartHome:Stop(): removing url: ' + route.route.path + " registered for " + me.GetRouteType(route));
to_remove.unshift(i);
// routes.splice(i, 1);
}
});
to_remove.forEach(i => REDapp._router.stack.splice(i, 1));
Expand Down Expand Up @@ -246,34 +245,25 @@ class GoogleSmartHome {

me._localUDPServer.on('message',function(msg,info){
const data = msg.toString();
// me.debug('Sevice Scan UDP server received ' + msg.length + ' bytes from ' + info.address + ':' + info.port );

if (data === me._localScanPacket) {
//
const sync_res = Buffer.from(JSON.stringify({clientId: me._nodeId}), 'utf8');
// const sync_res = JSON.stringify({clientId: me._nodeId});
// me.debug("Sending response message " + sync_res);

me._localUDPServer.send(sync_res, info.port, info.address, function(error){
if(error){
me.debug("Sevice Scan UDP server error sending message " + error);
// }else{
// me.debug('Sevice Scan UDP server data sent');
}
});
} else {
// me.debug('Sevice Scan UDP server data received : ' + data);
me.debug("Sevice Scan UDP server error wrong message received!");
}
});

me._localUDPServer.on('listening',function(){
const address = me._localUDPServer.address();
const port = address.port;
// const family = address.family;
const ipaddr = address.address;
me.debug('Sevice Scan UDP server listening on: ' + ipaddr + ':' + port);
// me.debug('Sevice Scan UDP server family: ' + family);
});

me._localUDPServer.on('close',function(){
Expand Down

0 comments on commit ed681c8

Please sign in to comment.