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 Jan 31, 2023
1 parent b60e1ed commit 5263864
Show file tree
Hide file tree
Showing 6 changed files with 1,227 additions and 103 deletions.
3 changes: 1 addition & 2 deletions css/extension.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension-matter-adapter-
background-repeat: no-repeat;
background-position: 0;
background-image: url('../images/menu-icon.svg');
width:16rem; /* You might want to change this if you have a longer or shorter addon name */
width:7rem; /* You might want to change this if you have a longer or shorter addon name */
margin:0 auto;
}

Expand Down Expand Up @@ -101,7 +101,6 @@ extension-matter-adapter-




/* MAIN PAGE */


Expand Down
139 changes: 67 additions & 72 deletions js/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@

this.debug = false; // if enabled, show more output in the console

// We'll try and get this data from the addon backend
this.a_number_setting = null;
this.items = [];
this.id = 'matter-adapter';

console.log("Adding matter-adapter addon to main menu");
this.addMenuEntry('Matter');


this.hotspot_addon_installed = false;
this.use_hotspot = false;
this.wifi_credentials_available = false;

// We'll try and get this data from the addon backend
//this.items = [];


// Load the html
this.content = ''; // The html from the view will be loaded into this variable
Expand Down Expand Up @@ -43,9 +50,6 @@
// This is called then the user clicks on the addon in the main menu, or when the page loads and is already on this addon's location.
show() {
console.log("matter-adapter show called");
//console.log("this.content:");
//console.log(this.content);


const main_view = document.getElementById('extension-matter-adapter-view');

Expand All @@ -59,61 +63,44 @@

try{

// ADD button press
document.getElementById('extension-matter-adapter-add-item-button').addEventListener('click', (event) => {
console.log("first button clicked. Event: ", event);

const new_name = document.getElementById('extension-matter-adapter-add-item-name').value;
const new_value = document.getElementById('extension-matter-adapter-add-item-value').value;

if(new_name == ""){
alert("Please provide a name");
return;
}
// Start pairing button press
document.getElementById('extension-matter-adapter-start-pairing-button').addEventListener('click', (event) => {
console.log("Start pairing button clicked");
document.getElementById('extension-matter-adapter-start-pairing-button').classList.add('extension-matter-adapter-hidden');

// isNaN is short for "is not a number"
if(isNaN(new_value)){
alert("Please provide a valid number");
return;
}

// If we end up here, then a name and number were present in the input fields. We can now ask the backend to save the new item.
window.API.postJson(
`/extensions/${this.id}/api/ajax`,
{'action':'add', 'name':new_name ,'value':new_value}
{'action':'start_pairing'}
//{'action':'start_pairing', 'name':new_name ,'value':new_value}

).then((body) => {
console.log("add item response: ", body);
console.log("start pairing response: ", body);
if(body.state == true){
console.log("adding a new item went ok");
document.getElementById('extension-matter-adapter-add-item-name').value = "";
document.getElementById('extension-matter-adapter-add-item-value').value = null;
console.log("new item was saved");
console.log("start pairing response was OK");
//document.getElementById('extension-matter-adapter-add-item-name').value = "";
//document.getElementById('extension-matter-adapter-add-item-value').value = null;
//console.log("new item was saved");
document.getElementById('extension-matter-adapter-pairing-step2').style.display = 'block';

}
else{
console.log("saving new item failed!");
alert("sorry, saving new item failed.");
console.log("start pairing failed?");
document.getElementById('extension-matter-adapter-start-pairing-button').classList.remove('extension-matter-adapter-hidden');
}

}).catch((e) => {
console.log("matter-adapter: connnection error after add new item button press: ", e);
alert("failed to add new item: connection error");
console.log("matter-adapter: connnection error after start pairing button press: ", e);
document.getElementById('extension-matter-adapter-start-pairing-button').classList.remove('extension-matter-adapter-hidden');
});

});





// Easter egg when clicking on the title
document.getElementById('extension-matter-adapter-title').addEventListener('click', (event) => {
alert("You found an easter egg!");
this.show();
});




// Button to show the second page
document.getElementById('extension-matter-adapter-show-second-page-button').addEventListener('click', (event) => {
console.log("clicked on + button");
Expand Down Expand Up @@ -175,45 +162,50 @@
{'action':'init'}

).then((body) => {
console.log("init response: ", body);

// We have now received initial data from the addon, so we can hide the loading spinner by adding the 'hidden' class to it.
document.getElementById('extension-matter-adapter-loading').classList.add('extension-matter-adapter-hidden');
try{
if(this.debug){
console.log("Matter adapter debug: init response: ", body);
}

// We have now received initial data from the addon, so we can hide the loading spinner by adding the 'hidden' class to it.
document.getElementById('extension-matter-adapter-loading').classList.add('extension-matter-adapter-hidden');

// If debug is available in the init data, set the debug value and output the init data to the console
if(typeof body.debug != 'undefined'){
this.debug = body.debug;
if(body.debug == true){
console.log("example addon 1: debugging enabled. Init API result: ", body);
// If debug is available in the init data, set the debug value and output the init data to the console
if(typeof body.debug != 'undefined'){
this.debug = body.debug;
if(this.debug){
console.log("Matter adapter debugging: Init response: ", body);

// If debugging is enabled, please show a big warning that this is the case.
// Debugging can be a privacy risk, since lots of data will be stored in the internal logs. Showing this warning helps avoid abuse.
// Here we just manipulate the element style directly, instead of using the 'hidden' class.
if(document.getElementById('extension-matter-adapter-debug-warning') != null){
document.getElementById('extension-matter-adapter-debug-warning').style.display = 'block';
if(document.getElementById('extension-matter-adapter-debug-warning') != null){
document.getElementById('extension-matter-adapter-debug-warning').style.display = 'block';
}
}
}
}

// Show the value of the number from the addon's settings
if(typeof body.a_number_setting != 'undefined'){
this.a_number_setting = body['a_number_setting'];
console.log("this.a_number_setting: ", this.a_number_setting);
document.getElementById('extension-matter-adapter-number-setting-output').innerText = body.a_number_setting; // body['a_number_setting'] and body.a_number_setting are two ways of writing the same thing
}
if(typeof body.use_hotspot != 'undefined' && typeof body.hotspot_addon_installed != 'undefined' && typeof body.wifi_credentials_available != 'undefined'){
this.hotspot_addon_installed = body.hotspot_addon_installed;
this.use_hotspot = body.use_hotspot;
this.wifi_credentials_available = body.wifi_credentials_available;
if(this.use_hotspot && !this.hotspot_addon_installed){
document.getElementById('extension-matter-adapter-install-hotspot-hint').classList.remove('extension-matter-adapter-hidden');
}
else if(!this.wifi_credentials_available){
document.getElementById('extension-matter-adapter-missing-wifi-credentials-hint').classList.remove('extension-matter-adapter-hidden');
}
}

// Show the value of the slider
if(typeof body.slider_value != 'undefined'){
document.getElementById('extension-matter-adapter-slider-value-output').innerText = body.slider_value;
/*
// Generate the list of items
if(typeof body.items_list != 'undefined'){
this.items = body['items_list'];
this.regenerate_items(body['items_list']);
}
*/
}


// Generate the list of items
if(typeof body.items_list != 'undefined'){
this.items = body['items_list'];
this.regenerate_items(body['items_list']);
catch(e){
console.log("Error parsing matter init response: ", e);
}


}).catch((e) => {
console.log("Error getting MatterAdapter init data: ", e);
Expand Down Expand Up @@ -242,7 +234,7 @@
console.log("I am only here because debugging is enabled");
}

let list_el = document.getElementById('extension-matter-adapter-main-items-list'); // list element
let list_el = document.getElementById('extension-matter-adapter-paired-devices-list'); // list element
if(list_el == null){
console.log("Error, the main list container did not exist yet");
return;
Expand Down Expand Up @@ -317,6 +309,9 @@

} // end of for loop

// Hide the loading spinner and show the paired devices list
document.getElementById('extension-matter-adapter-loading').classList.add('extension-matter-adapter-hidden');
list_el.classList.remove('extension-matter-adapter-hidden');


}
Expand Down
9 changes: 7 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
"name": "Matter adapter",
"options": {
"default": {
"Debugging": false
"Debugging": false,
"Use Hotspot addon as WiFi network for devices": true
},
"schema": {
"properties": {
"Use Hotspot addon as WiFi network for devices":{
"type": "boolean",
"description": "It is recommended to use the Hotspot addon to generate a separate guest WiFi network for smart devices that connect using Wi-Fi. Doing so will give you more control over the communication habits of your Matter devices."
},
"Debugging": {
"type": "boolean",
"description": "Advanced. Will generate details about the addon's processes in the internal log."
Expand All @@ -40,7 +45,7 @@
}
},
"short_name": "matter",
"version": "0.0.7",
"version": "0.0.8",
"web_accessible_resources": [
"css/*.css",
"images/*.svg",
Expand Down
Loading

0 comments on commit 5263864

Please sign in to comment.