forked from FOSS/BangleApps
hasensors: cleanup: use double quotes everywhere
parent
b500e96b36
commit
b79a1caae6
|
@ -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);
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue