mirror of https://github.com/espruino/BangleApps
hasensors: cleanup: use double quotes everywhere
parent
b500e96b36
commit
b79a1caae6
|
@ -1,5 +1,5 @@
|
||||||
(function () {
|
(function () {
|
||||||
const sb = () => require('hasensors').sendBattery();
|
const sb = () => require("hasensors").sendBattery();
|
||||||
Bangle.on("charging", sb);
|
Bangle.on("charging", sb);
|
||||||
NRF.on("connect", () => setTimeout(sb, 2000));
|
NRF.on("connect", () => setTimeout(sb, 2000));
|
||||||
setInterval(sb, 10 * 60 * 1000);
|
setInterval(sb, 10 * 60 * 1000);
|
||||||
|
|
|
@ -43,19 +43,19 @@
|
||||||
</p>
|
</p>
|
||||||
<script src="../../core/lib/customize.js"></script>
|
<script src="../../core/lib/customize.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const STORAGE_KEY = 'hasensors-config';
|
const STORAGE_KEY = "hasensors-config";
|
||||||
const fields = ['id', 'name', 'url', 'token'];
|
const fields = ["id", "name", "url", "token"];
|
||||||
const form = document.getElementById('sensorform');
|
const form = document.getElementById("sensorform");
|
||||||
const LIBRARY_URL = './lib.js';
|
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;
|
let libTpl;
|
||||||
fetch(LIBRARY_URL).then(response=>{
|
fetch(LIBRARY_URL).then(response=>{
|
||||||
if (! response.ok) return;
|
if (! response.ok) return;
|
||||||
console.log(response);
|
console.log(response);
|
||||||
response.text().then(code=>{
|
response.text().then(code=>{
|
||||||
libTpl = 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));
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(config));
|
||||||
// replace {placeholders} in library code template
|
// replace {placeholders} in library code template
|
||||||
const lib = libTpl.replace(/\{(\w+)\}/g, (_,f) => config[f]);
|
const lib = libTpl.replace(/\{(\w+)\}/g, (_,f) => config[f]);
|
||||||
console.log('config:', config, JSON.stringify(config));
|
console.log("config:", config, JSON.stringify(config));
|
||||||
sendCustomizedApp({
|
sendCustomizedApp({
|
||||||
id: "hasensors",
|
id: "hasensors",
|
||||||
storage: [
|
storage: [
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
// split out into a separate file to keep bootcode short.
|
// split out into a separate file to keep bootcode short.
|
||||||
// placeholders are replaced by custom.html before upload
|
// placeholders are replaced by custom.html before upload
|
||||||
function post(sensor, data) {
|
function post(sensor, data) {
|
||||||
const url = '{url}/api/states/sensor.{id}_' + sensor;
|
const url = "{url}/api/states/sensor.{id}_" + sensor;
|
||||||
Bangle.http(url, {
|
Bangle.http(url, {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
"Content-Type": "application/json",
|
||||||
Authorization: 'Bearer {token}',
|
Authorization: "Bearer {token}",
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ exports.sendBattery = function () {
|
||||||
let i = "mdi:battery";
|
let i = "mdi:battery";
|
||||||
if (c) i += "-charging";
|
if (c) i += "-charging";
|
||||||
|
|
||||||
post('battery_state', {
|
post("battery_state", {
|
||||||
state: c ? 'charging' : 'discharging',
|
state: c ? "charging" : "discharging",
|
||||||
attributes: {
|
attributes: {
|
||||||
friendly_name: "{name} Battery State",
|
friendly_name: "{name} Battery State",
|
||||||
icon: i + (c ? "" : "-minus"),
|
icon: i + (c ? "" : "-minus"),
|
||||||
|
@ -30,7 +30,7 @@ exports.sendBattery = function () {
|
||||||
if (b<10) i += "-outline"; // there is no battery-0
|
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
|
else if (b<100 || c) i += "-" + Math.floor(b/10)*10; // no battery-100 either
|
||||||
|
|
||||||
post('battery_level', {
|
post("battery_level", {
|
||||||
state: b,
|
state: b,
|
||||||
attributes: {
|
attributes: {
|
||||||
friendly_name: "{name} Battery Level",
|
friendly_name: "{name} Battery Level",
|
||||||
|
|
Loading…
Reference in New Issue