Skip to content

Commit

Permalink
better handling of bad JSON comms species
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronRP committed Sep 24, 2024
1 parent 866d6c9 commit 9a43fe5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion html/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ <h3>Comms port<br></h3>
<td><input type="text" id="input-comms-protect-species"></td>
</tr>
<tr>
<td>Protect Species</td>
<td>Protect Duration</td>
<td><input type="text" id="input-comms-protect-duration"></td>
</tr>
</tbody>
Expand Down
16 changes: 14 additions & 2 deletions static/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,28 @@ async function saveThermalMotionConfig() {
}

async function saveCommsConfig() {

try {
var protectSpecies = JSON.parse(document.querySelector("#input-comms-protect-species").value) || undefined;
console.log("protectSpecies", protectSpecies);
var trapSpecies = JSON.parse(document.querySelector("#input-comms-trap-species").value) || undefined;
console.log("TrapSpecies", trapSpecies);
} catch (error) {
console.error("Error parsing JSON:", error);
alert("Error parsing JSON for trap or protect species");
return;
}

const data = {
"enable": document.querySelector("#input-comms-enable").checked,
"trap-enabled-by-default": document.querySelector("#input-comms-trap-default").checked,
"comms-out": document.querySelector("#input-comms-type-select").value || undefined,
"bluetooth": document.querySelector("#input-comms-bluetooth").checked,
"power-output": document.querySelector("#input-comms-power-output").value || undefined,
"power-up-duration": document.querySelector("#input-comms-power-up-duration").value || undefined,
"trap-species": JSON.parse(document.querySelector("#input-comms-trap-species").value) || undefined,
"trap-species": trapSpecies,
"trap-duration": document.querySelector("#input-comms-trap-duration").value || undefined,
"protect-species": JSON.parse(document.querySelector("#input-comms-protect-species").value) || undefined,
"protect-species": protectSpecies,
"protect-duration": document.querySelector("#input-comms-protect-duration").value || undefined,
};

Expand Down

0 comments on commit 9a43fe5

Please sign in to comment.