1
0
Fork 0

hasensors: cleanup: use double quotes everywhere

master
Richard de Boer 2023-05-16 23:04:08 +02:00
parent b500e96b36
commit b79a1caae6
No known key found for this signature in database
3 changed files with 15 additions and 15 deletions

View File

@ -1,5 +1,5 @@
(function () {
const sb = () => require('hasensors').sendBattery();
const sb = () => require("hasensors").sendBattery();
Bangle.on("charging", sb);
NRF.on("connect", () => setTimeout(sb, 2000));
setInterval(sb, 10 * 60 * 1000);

View File

@ -43,19 +43,19 @@
</p>
<script src="../../core/lib/customize.js"></script>
<script>
const STORAGE_KEY = 'hasensors-config';
const fields = ['id', 'name', 'url', 'token'];
const form = document.getElementById('sensorform');
const LIBRARY_URL = './lib.js';
const STORAGE_KEY = "hasensors-config";
const fields = ["id", "name", "url", "token"];
const form = document.getElementById("sensorform");
const LIBRARY_URL = "./lib.js";
// fetch library code template, enable upload button once we've got it
// fetch library code template, enable upload button once we"ve got it
let libTpl;
fetch(LIBRARY_URL).then(response=>{
if (! response.ok) return;
console.log(response);
response.text().then(code=>{
libTpl = code;
document.getElementById('upload').disabled = false;
document.getElementById("upload").disabled = false;
});
});
@ -91,7 +91,7 @@ console.log(response);
localStorage.setItem(STORAGE_KEY, JSON.stringify(config));
// replace {placeholders} in library code template
const lib = libTpl.replace(/\{(\w+)\}/g, (_,f) => config[f]);
console.log('config:', config, JSON.stringify(config));
console.log("config:", config, JSON.stringify(config));
sendCustomizedApp({
id: "hasensors",
storage: [

View File

@ -1,13 +1,13 @@
// split out into a separate file to keep bootcode short.
// placeholders are replaced by custom.html before upload
function post(sensor, data) {
const url = '{url}/api/states/sensor.{id}_' + sensor;
const url = "{url}/api/states/sensor.{id}_" + sensor;
Bangle.http(url, {
method: 'POST',
method: "POST",
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer {token}',
"Content-Type": "application/json",
Authorization: "Bearer {token}",
}
});
}
@ -19,8 +19,8 @@ exports.sendBattery = function () {
let i = "mdi:battery";
if (c) i += "-charging";
post('battery_state', {
state: c ? 'charging' : 'discharging',
post("battery_state", {
state: c ? "charging" : "discharging",
attributes: {
friendly_name: "{name} Battery State",
icon: i + (c ? "" : "-minus"),
@ -30,7 +30,7 @@ exports.sendBattery = function () {
if (b<10) i += "-outline"; // there is no battery-0
else if (b<100 || c) i += "-" + Math.floor(b/10)*10; // no battery-100 either
post('battery_level', {
post("battery_level", {
state: b,
attributes: {
friendly_name: "{name} Battery Level",