Skip to content

Commit

Permalink
add list when multiple bridges are founds
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane committed Aug 17, 2021
1 parent 474090e commit c1fb9f1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
42 changes: 40 additions & 2 deletions octoprint_phom/templates/ophom_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,33 @@ Hue Bridge Status: <span id="ophom_generalstatus" class="badge badge-danger" sty
fetch(API_BASEURL + "plugin/ophom?action=discover").then(function(response) {
response.json().then(function(data) {
console.log(data);
if(data.length == 0)
{
search_button.innerHTML = '<i class="fa fa-search"></i> Search my bridge';
search_button.disabled = false;
document.getElementById("ophom_searchbridgestatus").style.display = "";
document.getElementById("ophom_searchbridgestatus").innerHTML = "<font color='red'>Unable to find your Hue Bridge. Are you on the same network ?</font>";
}
else if(data.length > 1)
{
search_button.innerHTML = '<i class="fa fa-search"></i> Search my bridge';
search_button.disabled = false;
document.getElementById("ophom_searchbridgestatus").style.display = "";
document.getElementById("ophom_searchbridgestatus").innerHTML = "<font color='blue'>Multiple bridges founds !</font><br />Select the correct bridge in the list below:<br />";
var select = document.createElement("select");
select.addEventListener("change", function() {
bridge_ip_address = select.value
})
document.getElementById("ophom_searchbridgestatus").appendChild(select);
data.forEach(element => {
var option = document.createElement("option");
option.value = element.internalipaddress;
option.text = element.internalipaddress;
select.appendChild(option);
})
document.getElementById("ophom_bridgefound").style.display = "";
}
else
{
bridge_ip_address = data[0].internalipaddress;
Expand Down Expand Up @@ -421,14 +440,33 @@ Hue Bridge Status: <span id="ophom_generalstatus" class="badge badge-danger" sty
fetch(API_BASEURL + "plugin/ophom?action=discover").then(function(response) {
response.json().then(function(data) {
console.log(data);
if(data.length == 0)
{
search_button.innerHTML = '<i class="fa fa-search"></i> Search my bridge';
search_button.disabled = false;
document.getElementById("ophom_researchbridgestatus").style.display = "";
document.getElementById("ophom_researchbridgestatus").innerHTML = "<font color='red'>Unable to find your Hue Bridge. Are you on the same network ?</font>";
}
else if(data.length > 1)
{
search_button.innerHTML = '<i class="fa fa-search"></i> Search my bridge';
search_button.disabled = false;
document.getElementById("ophom_researchbridgestatus").style.display = "";
document.getElementById("ophom_researchbridgestatus").innerHTML = "<font color='blue'>Multiple bridges founds !</font><br />Select the correct bridge in the list below:<br />";
var select = document.createElement("select");
select.addEventListener("change", function() {
bridge_ip_address = select.value
})
document.getElementById("ophom_researchbridgestatus").appendChild(select);
data.forEach(element => {
var option = document.createElement("option");
option.value = element.internalipaddress;
option.text = element.internalipaddress;
select.appendChild(option);
})
document.getElementById("ophom_bridgerefound").style.display = "";
}
else
{
bridge_ip_address = data[0].internalipaddress;
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "Ophom"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.3.5"
plugin_version = "1.4.0"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit c1fb9f1

Please sign in to comment.