Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
flatsiedatsie authored Feb 5, 2022
1 parent 6d303cc commit 0eb4f9c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 37 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"author": "Kabbi",
"author": "Kabbi & CandleSmartHome.com",
"description": "Connect to your Zigbee devices. Builds on the open source Zigbee2MQTT project.",
"content_scripts": [
{
Expand Down Expand Up @@ -144,7 +144,7 @@
}
},
"short_name": "zigbee2mqtt",
"version": "1.0.12",
"version": "1.0.13",
"web_accessible_resources": [
"css/*.css",
"images/*.svg",
Expand Down
85 changes: 50 additions & 35 deletions zigbee2mqtt-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ class ZigbeeMqttAdapter extends Adapter {

this.persistent_data = {'devices_overview':{},'virtual_brightness_alternatives': {}}

// try to load persistent data

//
// LOAD PERSISTENT
//

try {
fs.access(this.persistent_data_file_path, (err) => {
if (err && err.code === 'ENOENT') {
Expand All @@ -245,7 +249,7 @@ class ZigbeeMqttAdapter extends Adapter {

fs.readFile(this.persistent_data_file_path, 'utf8', (error, data) => {
if (error){
console.log("Error reading security file: " + error);
console.log("Error reading persistent data file: " + error);
}
//console.log("READING PERSISTENT DATA NOW from data: ", data);
this.persistent_data = JSON.parse(data);
Expand All @@ -260,7 +264,10 @@ class ZigbeeMqttAdapter extends Adapter {
console.error("Error while checking/opening security file: " + error.message);
}

// Restore barometer measurements if available.

//
// RESTORE BAROMETER
//

if( typeof this.persistent_data['barometer_measurements'] != 'undefined'){
console.log("barometer values were present in persistent data: ", this.persistent_data['barometer_measurements']);
Expand All @@ -281,17 +288,53 @@ class ZigbeeMqttAdapter extends Adapter {
});
}


//
// EXTRA SECURITY
//

this.improve_security = false;




// Check security file
try {
fs.access(this.zigbee2mqtt_configuration_security_file_path, (err) => {
if (err && err.code === 'ENOENT') {
if (this.config.debug) {
console.log('zigbee2mqtt security file did not exist.');
}

this.security = {
pan_id: rand_hex(4),
network_key: generate_security_key()
};
if (this.config.debug) {
console.log("new security details: ", this.security);
}

fs.writeFile( this.zigbee2mqtt_configuration_security_file_path, JSON.stringify( this.security ), "utf8", function(err, result) {
if(err){
console.log('security file write error:', err);
this.improve_security = false;
}
else{
// Security file now exists. But do we use it?
if(this.config.disable_improved_security == true){
console.log('WARNING: (extra) security has been manually disabled.');
this.improve_security = false;
}
else {
this.improve_security = true;
}
}

});


} else {
}
else {
if (this.config.debug) {
console.log('zigbee2mqtt security file existed:');
}
Expand All @@ -311,6 +354,7 @@ class ZigbeeMqttAdapter extends Adapter {
// adding extra security
if(this.config.disable_improved_security == true){
console.log('WARNING: (extra) security has been manually disabled.');
this.improve_security = false;
}
else {
this.improve_security = true;
Expand All @@ -323,7 +367,7 @@ class ZigbeeMqttAdapter extends Adapter {
});
}
catch (error) {
console.error("Error while checking/opening persistent data file: " + error.message);
console.error("Error while checking/opening security file: " + error.message);
}


Expand Down Expand Up @@ -921,36 +965,7 @@ class ZigbeeMqttAdapter extends Adapter {
if (this.config.debug) {
console.log(stdout);
}
console.log("-----DOWNLOAD COMPLETE, STARTING INSTALL-----");

// Create new security file
try {
fs.access(this.zigbee2mqtt_configuration_security_file_path, (err) => {
if (err && err.code === 'ENOENT') {
if (this.config.debug) {
console.log('zigbee2mqtt security file did not exist yet.');
}

this.security = {
pan_id: rand_hex(4),
network_key: generate_security_key()
};
if (this.config.debug) {
console.log("new security details: ", this.security);
}

fs.writeFile( this.zigbee2mqtt_configuration_security_file_path, JSON.stringify( this.security ), "utf8", function(err, result) {
if(err) console.log('file write error:', err);
});

}

});
}
catch (error) {
console.error("Error while checking/opening security file: " + error.message);
}

console.log("-----DOWNLOAD COMPLETE, STARTING INSTALL-----");

const command_to_run = `cd ${this.zigbee2mqtt_dir_path}; npm install -g typescript; npm i --save-dev @types/node; npm ci`; //npm ci --production
if (this.config.debug) {
Expand Down

0 comments on commit 0eb4f9c

Please sign in to comment.