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 14, 2023
1 parent fd162a3 commit c79e1d6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 31 deletions.
56 changes: 34 additions & 22 deletions js/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

this.id = 'matter-adapter';

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

this.discovered = null;
Expand Down Expand Up @@ -75,7 +75,7 @@
//
// 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("matter-adapter show called");

try{
clearInterval(window.matter_adapter_poll_interval);
Expand Down Expand Up @@ -128,7 +128,8 @@
});
*/

// commission_with_code

// Commission_with_code
// Start pairing button press
document.getElementById('extension-matter-adapter-start-normal-pairing-button').addEventListener('click', (event) => {
if(this.debug){
Expand All @@ -138,17 +139,20 @@
const wifi_password = document.getElementById('extension-matter-adapter-wifi-password').value;
const wifi_remember = document.getElementById('extension-matter-adapter-wifi-remember-checkbox').value;

if(wifi_ssid.length < 2){
console.log("Wifi name is too short");
alert("That wifi name is too short");
return;
}
if(wifi_password.length < 8){
console.log("Wifi password is too short");
alert("That wifi password is too short");
return;
}
document.getElementById('extension-matter-adapter-pairing-failed-hint').classList.add('extension-matter-adapter-hidden');

if(this.wifi_credentials_available == false){
if(wifi_ssid.length < 2){
console.log("Wifi name is too short");
alert("That wifi name is too short");
return;
}
if(wifi_password.length < 8){
console.log("Wifi password is too short");
alert("That wifi password is too short");
return;
}
}

const code = this.pairing_code;
if(this.debug){
Expand Down Expand Up @@ -189,8 +193,9 @@
'pairing_type':'commission_with_code',
'code':code}
).then((body) => {
console.log("pair device via commission_with_code response: ", body);

if(this.debug){
console.log("pair device via commission_with_code response: ", body);
}


}).catch((e) => {
Expand All @@ -201,14 +206,16 @@
});


// commission_on_network
// Commission_on_network
// Start pairing via commission_on_network button press
document.getElementById('extension-matter-adapter-start-network-pairing-button').addEventListener('click', (event) => {
if(this.debug){
console.log("Start network pairing button clicked");
}
const code = document.getElementById('extension-matter-adapter-network-pairing-code-input').value; //this.pairing_code;//document.getElementById('extension-matter-adapter-pairing-code').value;

document.getElementById('extension-matter-adapter-pairing-failed-hint').classList.add('extension-matter-adapter-hidden');

if(code.length < 4){
console.log("code was too short");
alert("That code is too short");
Expand Down Expand Up @@ -266,7 +273,7 @@
// Pairing failed, try again button

document.getElementById('extension-matter-adapter-pairing-failed-try-again-button').addEventListener('click', (event) => {
this.set_pairing_page();
this.show_pairing_page();
});


Expand Down Expand Up @@ -584,7 +591,7 @@
// Show pairing page, triggered by opening the pairing page, or pressing the retry button if pairing failed
show_pairing_page(){
if(this.debug){
console.log("Matter adapter debug: in set_pairing_page");
console.log("Matter adapter debug: in show_pairing_page");
}
this.generate_qr();

Expand All @@ -600,9 +607,11 @@
document.getElementById('extension-matter-adapter-second-page').classList.add('extension-matter-adapter-pairing-questioning');
document.getElementById('extension-matter-adapter-second-page').classList.remove('extension-matter-adapter-pairing-normal');
document.getElementById('extension-matter-adapter-second-page').classList.remove('extension-matter-adapter-pairing-network');
document.getElementById('extension-matter-adapter-second-page').classList.remove('extension-matter-adapter-busy-pairing');
document.getElementById('extension-matter-adapter-pairing-step-qr').classList.remove('extension-matter-adapter-hidden');
document.getElementById('extension-matter-adapter-save-manual-input-pairing-code-button').classList.remove('extension-matter-adapter-hidden');
document.getElementById('extension-matter-adapter-pairing-failed-hint').classList.add('extension-matter-adapter-hidden');

}


Expand Down Expand Up @@ -806,7 +815,7 @@

if(typeof this.nodez[thing_id] == 'undefined'){
if(this.debug){
console.error("Matter adapter debug: ERROR, THING ID NOT PRESENT IN NODEZ: ", thing_id);
console.warning("Matter adapter debug: WARNING, THING ID NOT PRESENT IN NODEZ. user should delete thing: ", thing_id);
}
continue;
}
Expand Down Expand Up @@ -1098,6 +1107,8 @@
console.log("Matter adapter debug: delete confirm button clicked");
}

delete_confirm_button.classList.add('extension-matter-adapter-hidden');

let item_el = event.currentTarget.closest(".extension-matter-adapter-item");
item_el.classList.add("extension-matter-adapter-delete");

Expand Down Expand Up @@ -1246,6 +1257,10 @@
if(list.innerHTML == ""){
list.innerHTML = '<div style="margin:10rem auto;padding:2rem;max-width:40rem;text-align:center; background-color:rgba(0,0,0,.1);border-radius:10px"><h2>No Matter devices paired yet</h2><p>Click on the (+) button in the bottom right corner if you want to connect a new Matter device.</p></div>';
}
else{
// Show refresh button
document.getElementById('extension-matter-adapter-refresh-paired-list-button').classList.remove('extension-matter-adapter-hidden');
}

if(this.updating_firmware){
// Disable all update buttons an update is in progress
Expand Down Expand Up @@ -1276,9 +1291,6 @@
catch (e) {
console.log("Matter adapter: general error while generating items: ", e);
}

// Show refresh button
document.getElementById('extension-matter-adapter-refresh-paired-list-button').classList.remove('extension-matter-adapter-hidden');

}

Expand Down
22 changes: 16 additions & 6 deletions pkg/matter_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self, verbose=False):
verbose -- whether or not to enable verbose logging
"""

print("Starting adapter init")
print("Starting Matter adapter init")

self.ready = False # set this to True once the init process is complete.
self.addon_id = 'matter-adapter'
Expand Down Expand Up @@ -158,7 +158,7 @@ def __init__(self, verbose=False):
self.device_was_deleted = False # set to True is a device is deleted from the Matter fabric

pwd = run_command('pwd')
print("\n\n\n\n\n\n\n\n\n\n\n\n\n" + str(pwd))
print("PWD:" + str(pwd))



Expand Down Expand Up @@ -347,12 +347,14 @@ def __init__(self, verbose=False):
os.mkdir(self.data_path)

if not os.path.isdir(self.certs_dir_path):
print("making certificates directory")
os.system('mkdir -p ' + self.certs_dir_path)

# /data
if not os.path.isdir("/data"):
print("Error! Could not find /data, which the server will be looking for")

time.sleep(30)
exit()

# Download the latest certificates
self.download_certs()
Expand Down Expand Up @@ -866,6 +868,8 @@ def download_certs(self):
if self.DEBUG:
print("download_certs_output: " + str(download_certs_output))

self.certificates_updated = True

if len(download_certs_output) < 5:
self.certificates_updated = True
#self.last_certificates_download_time = time.time()
Expand Down Expand Up @@ -1225,8 +1229,7 @@ def unload(self):
#if self.client != None:
# self.client.stop()

if self.server != None:
self.server.stop()


# loop = asyncio.get_event_loop()
# loop.stop()
Expand All @@ -1242,7 +1245,14 @@ def unload(self):

# A final chance to save the data.
self.save_persistent_data()
#if self.DEBUG:


if self.server != None:
self.server.stop()
time.sleep(5)
exit()

# does it reach this?
if self.DEBUG:
print("goodbye")
return
Expand Down
6 changes: 3 additions & 3 deletions views/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h4>Provide WiFi credentials</h4>
<p>If it's a WiFi based device you will also need to provide the WiFi name and password.</p>
<div id="extension-matter-adapter-current-wifi-ssid-container" class="extension-matter-adapter-hidden">
<p>Wifi credentials will be shared for: <span id="extension-matter-adapter-current-wifi-ssid">...</span><p>
<button id="extension-matter-adapter-reveal-wifi-setup-button">Change</button>
<button id="extension-matter-adapter-reveal-wifi-setup-button" class="text-button">Change</button>
</div>
<div id="extension-matter-adapter-provide-wifi-container">
<input type="text" id="extension-matter-adapter-wifi-ssid" placeholder="WiFi name"/>
Expand Down Expand Up @@ -183,11 +183,11 @@ <h4>Please enter the pairing pin code</h4>
<h4>Ready to pair</h4>

<p>Using pairing code: <span id="extension-matter-adapter-pairing-start-area-pairing-code">Error!</span></p>
<div id="extension-matter-adapter-busy-updating-certificates" class="extension-matter-adapter-hidden">
<div id="extension-matter-adapter-busy-updating-certificates" class="extension-matter-adapter-hidden extension-matter-adapter-area">
<div class="extension-matter-adapter-spinner">
<div></div><div></div><div></div><div></div>
</div>
<p style"text-align:center">Updating certificates... please wait</p>
<p style="text-align:center">Updating certificates... please wait</p>
</div>

<div id="extension-matter-adapter-pairing-bluetooth-hint">
Expand Down

0 comments on commit c79e1d6

Please sign in to comment.