|
|
|
@ -2,18 +2,20 @@ import { TempstreamJSX, Templatable } from "tempstream";
|
|
|
|
|
import { BaseContext } from "koa";
|
|
|
|
|
import { StatefulPage } from "@sealcode/sealgen";
|
|
|
|
|
import html from "../html.js";
|
|
|
|
|
import { get_state, HA_RESPONSE } from "../ha_api.js";
|
|
|
|
|
import { sleep } from "../util.js";
|
|
|
|
|
import { call_service, get_state, HA_RESPONSE } from "../ha_api.js";
|
|
|
|
|
|
|
|
|
|
export const actionName = "Dashboard";
|
|
|
|
|
|
|
|
|
|
//{"type":"call_service","domain":"automation","service":"trigger","service_data":{"entity_id":"automation.force_heating_at_20c_in_strych_for_1h","skip_condition":true},"id":41}
|
|
|
|
|
|
|
|
|
|
const actions = {
|
|
|
|
|
add: (state: State, inputs: Record<string, string>) => {
|
|
|
|
|
console.log({ inputs });
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
elements: [...state.elements, inputs.element_to_add || "new element"],
|
|
|
|
|
};
|
|
|
|
|
activateStrychHeating: (state: State, inputs: Record<string, string>) => {
|
|
|
|
|
call_service(
|
|
|
|
|
"automation",
|
|
|
|
|
"trigger",
|
|
|
|
|
"automation.force_heating_at_20c_in_strych_for_1h"
|
|
|
|
|
);
|
|
|
|
|
return state;
|
|
|
|
|
},
|
|
|
|
|
remove: (state: State, _: unknown, index_to_remove: number) => {
|
|
|
|
|
return {
|
|
|
|
@ -78,25 +80,10 @@ export default new (class DashboardPage extends StatefulPage<State, typeof actio
|
|
|
|
|
))}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
{ctx.headers["just-data"]
|
|
|
|
|
? ""
|
|
|
|
|
: /* HTML */ `<script>
|
|
|
|
|
function refresh() {
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
|
xhr.withCredentials = true;
|
|
|
|
|
xhr.open("GET", "/dashboard");
|
|
|
|
|
xhr.setRequestHeader("just-data", "true");
|
|
|
|
|
|
|
|
|
|
xhr.onload = function () {
|
|
|
|
|
document.querySelector("body").innerHTML =
|
|
|
|
|
xhr.response;
|
|
|
|
|
};
|
|
|
|
|
xhr.send();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setInterval(refresh, 15 * 1000);
|
|
|
|
|
</script>`}
|
|
|
|
|
{this.makeActionButton(state, {
|
|
|
|
|
action: "activateStrychHeating",
|
|
|
|
|
label: "Włącz-ogrzewanie-na-strychu-na-1h",
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|