Linting and remove duplicate code
This commit is contained in:
1 parent
f342c20b91
commit
f4ca95d436
14 files changed
+1356
-3754
No files matched your search
@@ -1,149 +1,284 @@
|
||||
!function(e){var t={};function o(s){if(t[s])return t[s].exports;var i=t[s]={i:s,l:!1,exports:{}};return e[s].call(i.exports,i,i.exports,o),i.l=!0,i.exports}o.m=e,o.c=t,o.d=function(e,t,s){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(o.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)o.d(s,i,function(t){return e[t]}.bind(null,i));return s},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=1)}([function(e){e.exports=JSON.parse('{"name":"browser_mod","private":true,"version":"1.3.0","description":"","scripts":{"build":"webpack","watch":"webpack --watch --mode=development","update-card-tools":"npm uninstall card-tools && npm install thomasloven/lovelace-card-tools"},"keywords":[],"author":"Thomas Lovén","license":"MIT","devDependencies":{"webpack":"^4.46.0","webpack-cli":"^3.3.12"},"dependencies":{"card-tools":"github:thomasloven/lovelace-card-tools"}}')},function(e,t,o){"use strict";o.r(t);const s="lovelace-player-device-id";function i(){if(!localStorage[s]){const e=()=>Math.floor(1e5*(1+Math.random())).toString(16).substring(1);window.fully&&"function"==typeof fully.getDeviceId?localStorage[s]=fully.getDeviceId():localStorage[s]=`${e()}${e()}-${e()}${e()}`}return localStorage[s]}let a=i();const n=e=>{null!==e&&("clear"===e?localStorage.removeItem(s):localStorage[s]=e,a=i())},r=new URLSearchParams(window.location.search);function l(){return document.querySelector("hc-main")?document.querySelector("hc-main").hass:document.querySelector("home-assistant")?document.querySelector("home-assistant").hass:void 0}function c(e){return document.querySelector("hc-main")?document.querySelector("hc-main").provideHass(e):document.querySelector("home-assistant")?document.querySelector("home-assistant").provideHass(e):void 0}function d(){var e,t=document.querySelector("hc-main");return t?((e=t._lovelaceConfig).current_view=t._lovelacePath,e):(t=(t=(t=(t=(t=(t=(t=(t=(t=document.querySelector("home-assistant"))&&t.shadowRoot)&&t.querySelector("home-assistant-main"))&&t.shadowRoot)&&t.querySelector("app-drawer-layout partial-panel-resolver"))&&t.shadowRoot||t)&&t.querySelector("ha-panel-lovelace"))&&t.shadowRoot)&&t.querySelector("hui-root"))?((e=t.lovelace).current_view=t.___curView,e):null}function u(){var e=document.querySelector("hc-main");return e=e?(e=(e=(e=e&&e.shadowRoot)&&e.querySelector("hc-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-view")||e.querySelector("hui-panel-view"):(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=document.querySelector("home-assistant"))&&e.shadowRoot)&&e.querySelector("home-assistant-main"))&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver"))&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-root"))&&e.shadowRoot)&&e.querySelector("ha-app-layout"))&&e.querySelector("#view"))&&e.firstElementChild}async function h(){if(customElements.get("hui-view"))return!0;await customElements.whenDefined("partial-panel-resolver");const e=document.createElement("partial-panel-resolver");if(e.hass={panels:[{url_path:"tmp",component_name:"lovelace"}]},e._updateRoutes(),await e.routerOptions.routes.tmp.load(),!customElements.get("ha-panel-lovelace"))return!1;const t=document.createElement("ha-panel-lovelace");return t.hass=l(),void 0===t.hass&&(await new Promise(e=>{window.addEventListener("connection-status",t=>{console.log(t),e()},{once:!0})}),t.hass=l()),t.panel={config:{mode:null}},t._fetchConfig(),!0}async function p(e,t,o=!1){let s=e;"string"==typeof t&&(t=t.split(/(\$| )/)),""===t[t.length-1]&&t.pop();for(const[e,i]of t.entries())if(i.trim().length){if(!s)return null;s.localName&&s.localName.includes("-")&&await customElements.whenDefined(s.localName),s.updateComplete&&await s.updateComplete,s="$"===i?o&&e==t.length-1?[s.shadowRoot]:s.shadowRoot:o&&e==t.length-1?s.querySelectorAll(i):s.querySelector(i)}return s}async function m(e,t,o=!1,s=1e4){return Promise.race([p(e,t,o),new Promise((e,t)=>setTimeout(()=>t(new Error("timeout")),s))]).catch(e=>{if(!e.message||"timeout"!==e.message)throw e;return null})}function w(e,t,o=null){if((e=new Event(e,{bubbles:!0,cancelable:!1,composed:!0})).detail=t||{},o)o.dispatchEvent(e);else{var s=u();s&&s.dispatchEvent(e)}}r.get("deviceID")&&n(r.get("deviceID"));let y=window.cardHelpers;new Promise(async(e,t)=>{y&&e();const o=async()=>{y=await window.loadCardHelpers(),window.cardHelpers=y,e()};window.loadCardHelpers?o():window.addEventListener("load",async()=>{h(),window.loadCardHelpers&&o()})});async funcLine truncated
|
||||
<ha-dialog
|
||||
open
|
||||
@closed=${this.closeDialog}
|
||||
.heading=${!0}
|
||||
hideActions
|
||||
@ll-rebuild=${this._makeCard}
|
||||
>
|
||||
${this.fullscreen?t`<div slot="heading"></div>`:t`
|
||||
<app-toolbar slot="heading">
|
||||
<mwc-icon-button
|
||||
.label=${"dismiss"}
|
||||
dialogAction="cancel"
|
||||
>
|
||||
<ha-icon
|
||||
.icon=${"mdi:close"}
|
||||
></ha-icon>
|
||||
</mwc-icon-button>
|
||||
<div class="main-title" @click=${this._enlarge}>
|
||||
${this.title}
|
||||
</div>
|
||||
</app-toolbar>
|
||||
`}
|
||||
<div class="content">
|
||||
${this.card}
|
||||
</div>
|
||||
</ha-dialog>
|
||||
`:t``}static get styles(){return o`
|
||||
ha-dialog {
|
||||
--mdc-dialog-min-width: 400px;
|
||||
--mdc-dialog-max-width: 600px;
|
||||
--mdc-dialog-heading-ink-color: var(--primary-text-color);
|
||||
--mdc-dialog-content-ink-color: var(--primary-text-color);
|
||||
--justify-action-buttons: space-between;
|
||||
}
|
||||
@media all and (max-width: 450px), all and (max-height: 500px) {
|
||||
ha-dialog {
|
||||
--mdc-dialog-min-width: 100vw;
|
||||
--mdc-dialog-max-width: 100vw;
|
||||
--mdc-dialog-min-height: 100%;
|
||||
--mdc-dialog-max-height: 100%;
|
||||
--mdc-shape-medium: 0px;
|
||||
--vertial-align-dialog: flex-end;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
||||
* This devtool is neither made for production nor for readable output files.
|
||||
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
||||
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
||||
* or disable the default devtool with "devtool: false".
|
||||
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
||||
*/
|
||||
/******/ (() => { // webpackBootstrap
|
||||
/******/ var __webpack_modules__ = ({
|
||||
|
||||
app-toolbar {
|
||||
flex-shrink: 0;
|
||||
color: var(--primary-text-color);
|
||||
background-color: var(--secondary-background-color);
|
||||
}
|
||||
/***/ "./js/browser-player-editor.js":
|
||||
/*!*************************************!*\
|
||||
!*** ./js/browser-player-editor.js ***!
|
||||
\*************************************/
|
||||
/***/ (() => {
|
||||
|
||||
.main-title {
|
||||
margin-left: 16px;
|
||||
line-height: 1.3em;
|
||||
max-height: 2.6em;
|
||||
overflow: hidden;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.content {
|
||||
margin: -20px -24px;
|
||||
}
|
||||
eval("const bases = [\n customElements.whenDefined(\"home-assistant-main\"),\n customElements.whenDefined(\"hui-view\"),\n];\nPromise.race(bases).then(() => {\n const LitElement = customElements.get(\"home-assistant-main\")\n ? Object.getPrototypeOf(customElements.get(\"home-assistant-main\"))\n : Object.getPrototypeOf(customElements.get(\"hui-view\"));\n const html = LitElement.prototype.html;\n const css = LitElement.prototype.css;\n\n class BrowserPlayerEditor extends LitElement {\n setConfig(config) {}\n render() {\n return html` <div>Nothing to configure.</div> `;\n }\n }\n\n if (!customElements.get(\"browser-player-editor\")) {\n customElements.define(\"browser-player-editor\", BrowserPlayerEditor);\n window.customCards = window.customCards || [];\n window.customCards.push({\n type: \"browser-player\",\n name: \"Browser Player\",\n preview: true,\n });\n }\n});\n\n\n//# sourceURL=webpack://browser_mod/./js/browser-player-editor.js?");
|
||||
|
||||
@media all and (max-width: 450px), all and (max-height: 500px) {
|
||||
app-toolbar {
|
||||
background-color: var(--app-header-background-color);
|
||||
color: var(--app-header-text-color, white);
|
||||
}
|
||||
}
|
||||
/***/ }),
|
||||
|
||||
@media all and (min-width: 451px) and (min-height: 501px) {
|
||||
ha-dialog {
|
||||
--mdc-dialog-max-width: 90vw;
|
||||
}
|
||||
/***/ "./js/browser-player.js":
|
||||
/*!******************************!*\
|
||||
!*** ./js/browser-player.js ***!
|
||||
\******************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
.content {
|
||||
width: 400px;
|
||||
}
|
||||
:host([large]) .content {
|
||||
width: calc(90vw - 48px);
|
||||
}
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! card-tools/src/deviceID */ \"./node_modules/card-tools/src/deviceID.js\");\n/* harmony import */ var card_tools_src_more_info__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! card-tools/src/more-info */ \"./node_modules/card-tools/src/more-info.js\");\n/* harmony import */ var _browser_player_editor_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./browser-player-editor.js */ \"./js/browser-player-editor.js\");\n/* harmony import */ var _browser_player_editor_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_browser_player_editor_js__WEBPACK_IMPORTED_MODULE_2__);\n\n\n\n\nconst bases = [\n customElements.whenDefined(\"home-assistant-main\"),\n customElements.whenDefined(\"hui-view\"),\n];\nPromise.race(bases).then(() => {\n const LitElement = customElements.get(\"home-assistant-main\")\n ? Object.getPrototypeOf(customElements.get(\"home-assistant-main\"))\n : Object.getPrototypeOf(customElements.get(\"hui-view\"));\n const html = LitElement.prototype.html;\n const css = LitElement.prototype.css;\n\n class BrowserPlayer extends LitElement {\n static get properties() {\n return {\n hass: {},\n };\n }\n\n static getConfigElement() {\n return document.createElement(\"browser-player-editor\");\n }\n static getStubConfig() {\n return {};\n }\n\n setConfig(config) {\n this._config = config;\n for (const event of [\n \"play\",\n \"pause\",\n \"ended\",\n \"volumechange\",\n \"canplay\",\n \"loadeddata\",\n ])\n window.browser_mod.player.addEventListener(event, () =>\n this.requestUpdate()\n );\n }\n handleMute(ev) {\n window.browser_mod.player_mute();\n }\n handleVolumeChange(ev) {\n const vol = parseFloat(ev.target.value);\n window.browser_mod.player_set_volume(vol);\n }\n handleMoreInfo(ev) {\n (0,card_tools_src_more_info__WEBPACK_IMPORTED_MODULE_1__.moreInfo)(\"media_player.\" + window.browser_mod.entity_id);\n }\n handlePlayPause(ev) {\n if (window.browser_mod.player.paused) window.browser_mod.player_play();\n else window.browser_mod.player_pause();\n }\n setDeviceID() {\n const newID = prompt(\"Set deviceID\", card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__.deviceID);\n if (newID !== card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__.deviceID) {\n (0,card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__.setDeviceID)(newID);\n this.requestUpdate();\n }\n }\n\n render() {\n if (!window.browser_mod) {\n window.setTimeout(() => this.requestUpdate(), 100);\n return html``;\n }\n const player = window.browser_mod.player;\n return html`\n <ha-card>\n <div class=\"card-content\">\n <ha-icon-button\n .icon=${player.muted ? \"mdi:volume-off\" : \"mdi:volume-high\"}\n @click=${this.handleMute}\n ></ha-icon-button>\n <ha-slider\n min=\"0\"\n max=\"1\"\n step=\"0.01\"\n ?disabled=${player.muted}\n value=${player.volume}\n @change=${this.handleVolumeChange}\n ></ha-slider>\n\n ${window.browser_mod.player_state === \"stopped\"\n ? html`<div class=\"placeholder\"></div>`\n : html`\n <ha-icon-button\n .icon=${player.paused ? \"mdi:play\" : \"mdi:pause\"}\n @click=${this.handlePlayPause}\n highlight\n ></ha-icon-button>\n `}\n <ha-icon-button\n .icon=${\"mdi:cog\"}\n @click=${this.handleMoreInfo}\n ></ha-icon-button>\n </div>\n\n <div class=\"device-id\" @click=${this.setDeviceID}>${card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__.deviceID}</div>\n </ha-card>\n `;\n }\n\n static get styles() {\n return css`\n paper-icon-button[highlight] {\n color: var(--accent-color);\n }\n .card-content {\n display: flex;\n justify-content: center;\n }\n .placeholder {\n width: 24px;\n padding: 8px;\n }\n .device-id {\n opacity: 0.7;\n font-size: xx-small;\n margin-top: -10px;\n user-select: all;\n -webkit-user-select: all;\n -moz-user-select: all;\n -ms-user-select: all;\n }\n `;\n }\n }\n\n if (!customElements.get(\"browser-player\"))\n customElements.define(\"browser-player\", BrowserPlayer);\n});\n\n\n//# sourceURL=webpack://browser_mod/./js/browser-player.js?");
|
||||
|
||||
:host([large]) app-toolbar {
|
||||
max-width: calc(90vw - 32px);
|
||||
}
|
||||
}
|
||||
`}}customElements.define("card-tools-popup",s)}const a=document.querySelector("home-assistant")||document.querySelector("hc-root");if(!a)return;let n=await m(a,"$ card-tools-popup");if(!n){n=document.createElement("card-tools-popup");const e=a.shadowRoot.querySelector("ha-more-info-dialog");e?a.shadowRoot.insertBefore(n,e):a.shadowRoot.appendChild(n),c(n)}if(!window._moreInfoDialogListener){const e=async e=>{if(e.state&&"cardToolsPopup"in e.state)if(e.state.cardToolsPopup){const{title:t,card:o,large:s,style:i,fullscreen:a}=e.state.params;v(t,o,s,i,a)}else n.closeDialog()};window.addEventListener("popstate",e),window._moreInfoDialogListener=!0}history.replaceState({cardToolsPopup:!1},""),history.pushState({cardToolsPopup:!0,params:{title:e,card:t,large:o,style:s,fullscreen:i}},""),n.showDialog(e,t,o,s,i)}async function g(e,t=!1){const o=document.querySelector("hc-main")||document.querySelector("home-assistant");w("hass-more-info",{entityId:e},o);const s=await m(o,"$ ha-more-info-dialog");return s&&(s.large=t),s}const f=[customElements.whenDefined("home-assistant-main"),customElements.whenDefined("hui-view")];Promise.race(f).then(()=>{const e=customElements.get("home-assistant-main")?Object.getPrototypeOf(customElements.get("home-assistant-main")):Object.getPrototypeOf(customElements.get("hui-view")),t=e.prototype.html;e.prototype.css;class o extends e{setConfig(e){}render(){return t`
|
||||
<div>
|
||||
Nothing to configure.
|
||||
</div>
|
||||
`}}customElements.get("browser-player-editor")||(customElements.define("browser-player-editor",o),window.customCards=window.customCards||[],window.customCards.push({type:"browser-player",name:"Browser Player",preview:!0}))});const b=[customElements.whenDefined("home-assistant-main"),customElements.whenDefined("hui-view")];Promise.race(b).then(()=>{const e=customElements.get("home-assistant-main")?Object.getPrototypeOf(customElements.get("home-assistant-main")):Object.getPrototypeOf(customElements.get("hui-view")),t=e.prototype.html,o=e.prototype.css;customElements.get("browser-player")||customElements.define("browser-player",class extends e{static get properties(){return{hass:{}}}static getConfigElement(){return document.createElement("browser-player-editor")}static getStubConfig(){return{}}setConfig(e){this._config=e;for(const e of["play","pause","ended","volumechange","canplay","loadeddata"])window.browser_mod.player.addEventListener(e,()=>this.requestUpdate())}handleMute(e){window.browser_mod.player_mute()}handleVolumeChange(e){const t=parseFloat(e.target.value);window.browser_mod.player_set_volume(t)}handleMoreInfo(e){g("media_player."+window.browser_mod.entity_id)}handlePlayPause(e){window.browser_mod.player.paused?window.browser_mod.player_play():window.browser_mod.player_pause()}setDeviceID(){const e=prompt("Set deviceID",a);e!==a&&(n(e),this.requestUpdate())}render(){if(!window.browser_mod)return window.setTimeout(()=>this.requestUpdate(),100),t``;const e=window.browser_mod.player;return t`
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<ha-icon-button
|
||||
.icon=${e.muted?"mdi:volume-off":"mdi:volume-high"}
|
||||
@click=${this.handleMute}
|
||||
></ha-icon-button>
|
||||
<ha-slider
|
||||
min=0
|
||||
max=1
|
||||
step=0.01
|
||||
?disabled=${e.muted}
|
||||
value=${e.volume}
|
||||
@change=${this.handleVolumeChange}
|
||||
></ha-slider>
|
||||
/***/ }),
|
||||
|
||||
${"stopped"===window.browser_mod.player_state?t`<div class="placeholder"></div>`:t`
|
||||
<ha-icon-button
|
||||
.icon=${e.paused?"mdi:play":"mdi:pause"}
|
||||
@click=${this.handlePlayPause}
|
||||
highlight
|
||||
></ha-icon-button>
|
||||
`}
|
||||
<ha-icon-button
|
||||
.icon=${"mdi:cog"}
|
||||
@click=${this.handleMoreInfo}
|
||||
></ha-icon-button>
|
||||
</div>
|
||||
/***/ "./js/browser.js":
|
||||
/*!***********************!*\
|
||||
!*** ./js/browser.js ***!
|
||||
\***********************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
<div class="device-id" @click=${this.setDeviceID}>
|
||||
${a}
|
||||
</div>
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BrowserModBrowserMixin\": () => (/* binding */ BrowserModBrowserMixin)\n/* harmony export */ });\n/* harmony import */ var card_tools_src_event__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! card-tools/src/event */ \"./node_modules/card-tools/src/event.js\");\n\n\nconst BrowserModBrowserMixin = (C) =>\n class extends C {\n constructor() {\n super();\n document.addEventListener(\"visibilitychange\", () => this.sensor_update());\n window.addEventListener(\"location-changed\", () => this.sensor_update());\n\n window.setInterval(() => this.sensor_update(), 10000);\n }\n\n sensor_update() {\n const update = async () => {\n const battery = navigator.getBattery\n ? await navigator.getBattery()\n : undefined;\n this.sendUpdate({\n browser: {\n path: window.location.pathname,\n visibility: document.visibilityState,\n userAgent: navigator.userAgent,\n currentUser: this._hass && this._hass.user && this._hass.user.name,\n fullyKiosk: this.isFully,\n width: window.innerWidth,\n height: window.innerHeight,\n battery_level: this.isFully\n ? window.fully.getBatteryLevel()\n : battery\n ? battery.level * 100\n : undefined,\n charging: this.isFully\n ? window.fully.isPlugged()\n : battery\n ? battery.charging\n : undefined,\n },\n });\n };\n update();\n }\n\n do_navigate(path) {\n if (!path) return;\n history.pushState(null, \"\", path);\n (0,card_tools_src_event__WEBPACK_IMPORTED_MODULE_0__.fireEvent)(\n \"location-changed\",\n {},\n document.querySelector(\"home-assistant\")\n );\n }\n };\n\n\n//# sourceURL=webpack://browser_mod/./js/browser.js?");
|
||||
|
||||
</ha-card>
|
||||
`}static get styles(){return o`
|
||||
paper-icon-button[highlight] {
|
||||
color: var(--accent-color);
|
||||
}
|
||||
.card-content {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.placeholder {
|
||||
width: 24px;
|
||||
padding: 8px;
|
||||
}
|
||||
.device-id {
|
||||
opacity: 0.7;
|
||||
font-size: xx-small;
|
||||
margin-top: -10px;
|
||||
user-select: all;
|
||||
-webkit-user-select: all;
|
||||
-moz-user-select: all;
|
||||
-ms-user-select: all;
|
||||
}
|
||||
`}})});class S{async connect(){if(null!==document.querySelector("hc-main"))this._connection=l().connection;else{if(!window.hassConnection)return void window.setTimeout(()=>this.connect(),100);this._connection=(await window.hassConnection).conn}this._connection.subscribeMessage(e=>this.msg_callback(e),{type:"browser_mod/connect",deviceID:a}),this._hass_patched=!1,c(this)}set hass(e){this._hass=e}get connected(){return void 0!==this._connection}msg_callback(e){console.log(e)}sendUpdate(e){this.connected&&this._connection.sendMessage({type:"browser_mod/update",deviceID:a,data:e})}}const k=e=>class extends e{constructor(){super(),this.player=new Audio;for(const e of["play","pause","ended","volumechange"])this.player.addEventListener(e,()=>this.player_update());window.addEventListener("click",()=>this.player.play(),{once:!0})}player_update(e){this.sendUpdate({player:{volume:this.player.volume,muted:this.player.muted,src:this.player.src,state:this.player_state}})}get player_state(){return this.player.src?this.player.ended?"stopped":this.player.paused?"paused":"playing":"stopped"}player_play(e){e&&(this.player.src=e),this.player.play()}player_pause(){this.player.pause()}player_stop(){this.player.pause(),this.player.src=null}player_set_volume(e){void 0!==e&&(this.player.volume=e)}player_mute(e){void 0===e&&(e=!this.player.muted),this.player.muted=Boolean(e)}},x=e=>class extends e{get isFully(){return void 0!==window.fully}constructor(){if(super(),this.isFully){this._fullyMotion=!1,this._motionTimeout=void 0;for(const e of["screenOn","screenOff","pluggedAC","pluggedUSB","onBatteryLevelChanged","unplugged","networkReconnect","onMotion"])window.fully.bind(e,`window.browser_mod.fully_update("${e}");`);this._keepingAlive=!1}}fully_update(e){this.isFully&&("screenOn"===e?(window.clearTimeout(this._keepAliveTimer),this._keepingAlive||this.screen_update()):"screenOff"===e?(this.screen_update(),this._keepingAlive=!1,this.config.force_stay_awake&&(this._keepAliveTimer=window.setTimeout(()=>{this._keepingAlive=!0,window.fully.turnScreenOn(),window.fully.turnScreenOff()},27e4))):"onMotion"===e&&this.fullyMotionTriggered(),this.sendUpdate({fully:{battery:window.fully.getBatteryLevel(),charging:window.fully.isPlugged(),motion:this._fullyMotion,ip:window.fully.getIp4Address()}}))}fullyMotionTriggered(){this._keepingAlive||(this._fullyMotion=!0,clearTimeout(this._motionTimeout),this._motionTimeout=setTimeout(()=>{this._fullyMotion=!1,this.fully_update()},5e3),this.fully_update())}},E=e=>class extends e{setup_camera(){console.log("Starting camera"),this._video||(this._video=document.createElement("video"),this._video.autoplay=!0,this._video.playsInline=!0,this._video.style.display="none",this._canvas=document.createElement("canvas"),this._canvas.style.display="none",document.body.appendChild(this._video),document.body.appendChild(this._canvas),navigator.mediaDevices&&(console.log("Starting devices"),navigator.mediaDevices.getUserMedia({video:!0,audio:!1}).then(e=>{this._video.srcObject=e,this._video.play(),this.update_camera()}),this._camera_framerate=2,window.addEventListener("click",()=>this._video.play(),{once:!0})))}update_camera(){this._canvas.width=this._video.videoWidth,this._canvas.height=this._video.videoHeight;this._canvas.getContext("2d").drawImage(this._video,0,0,this._video.videoWidth,this._video.videoHeight),this.sendUpdate({camera:this._canvas.toDataURL("image/jpeg")}),setTimeout(()=>this.update_camera(),Math.round(1e3/this._camera_framerate))}},q=e=>class extends e{constructor(){super(),this._blackout_panel=document.createElement("div"),this._screenSaver=void 0,this._screenSaverTimer=void 0,this._screenSaverTimeOut=0,this._screenSaver={fn:void 0,clearfn:void 0,timer:void 0,timeout:void 0,listeners:{},active:!1},this._blackout_panel.style.cssText="\n position: fixed;\n left: 0;\n top: 0;\n padding: 0;\n margin: 0;\n width: 100%;\n height: 100%;\n background: black;\n display: none;\n ",document.body.appendChild(this._blackout_panel)}screensaver_set(e,t,o){this._ss_clear(),this._screenSaver={fn:e,clearfn:t,timer:void 0,timeout:o,listeners:{},active:!1};const s=()=>this.screensaver_update();for(const e of["mousemove","mousedown","keydown","touchstart"])window.addEventListener(e,s),this._screenSaver.listeners[e]=s;this._screenSaver.timer=window.setTimeout(()=>this._ss_run(),1e3*o)}screensaver_update(){this._screenSaver.active?this.screensaver_stop():(window.clearTimeout(this._screenSaver.timer),this._screenSaver.timer=window.setTimeout(()=>this._ss_run(),1e3*this._screenSaver.timeout))}screensaver_stop(){this._ss_clear(),this._screenSaver.active=!1,this._screenSaver.clearfn&&this._screenSaver.clearfn(),this._screenSaver.timeout&&this.screensaver_set(this._screenSaver.fn,this._screenSaver.clearfn,this._screenSaver.timeout)}_ss_clear(){window.clearTimeout(this._screenSaverTimer);for(const[e,t]of Object.entries(th
Line truncated
|
||||
/***/ }),
|
||||
|
||||
/***/ "./js/camera.js":
|
||||
/*!**********************!*\
|
||||
!*** ./js/camera.js ***!
|
||||
\**********************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BrowserModCameraMixin\": () => (/* binding */ BrowserModCameraMixin)\n/* harmony export */ });\nconst BrowserModCameraMixin = (C) =>\n class extends C {\n setup_camera() {\n console.log(\"Starting camera\");\n\n if (this._video) return;\n this._video = document.createElement(\"video\");\n this._video.autoplay = true;\n this._video.playsInline = true;\n this._video.style.display = \"none\";\n\n this._canvas = document.createElement(\"canvas\");\n this._canvas.style.display = \"none\";\n\n document.body.appendChild(this._video);\n document.body.appendChild(this._canvas);\n\n if (!navigator.mediaDevices) return;\n\n console.log(\"Starting devices\");\n navigator.mediaDevices\n .getUserMedia({ video: true, audio: false })\n .then((stream) => {\n this._video.srcObject = stream;\n this._video.play();\n this.update_camera();\n });\n\n this._camera_framerate = 2;\n\n window.addEventListener(\"click\", () => this._video.play(), {\n once: true,\n });\n }\n\n update_camera() {\n this._canvas.width = this._video.videoWidth;\n this._canvas.height = this._video.videoHeight;\n\n const context = this._canvas.getContext(\"2d\");\n context.drawImage(\n this._video,\n 0,\n 0,\n this._video.videoWidth,\n this._video.videoHeight\n );\n\n this.sendUpdate({\n camera: this._canvas.toDataURL(\"image/jpeg\"),\n });\n setTimeout(\n () => this.update_camera(),\n Math.round(1000 / this._camera_framerate)\n );\n }\n };\n\n\n//# sourceURL=webpack://browser_mod/./js/camera.js?");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./js/connection.js":
|
||||
/*!**************************!*\
|
||||
!*** ./js/connection.js ***!
|
||||
\**************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BrowserModConnection\": () => (/* binding */ BrowserModConnection)\n/* harmony export */ });\n/* harmony import */ var card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! card-tools/src/deviceID */ \"./node_modules/card-tools/src/deviceID.js\");\n/* harmony import */ var card_tools_src_hass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! card-tools/src/hass */ \"./node_modules/card-tools/src/hass.js\");\n\n\n\nclass BrowserModConnection {\n async connect() {\n const isCast = document.querySelector(\"hc-main\") !== null;\n if (!isCast) {\n if (!window.hassConnection) {\n window.setTimeout(() => this.connect(), 100);\n return;\n } else {\n this._connection = (await window.hassConnection).conn;\n }\n } else {\n this._connection = (0,card_tools_src_hass__WEBPACK_IMPORTED_MODULE_1__.hass)().connection;\n }\n\n this._connection.subscribeMessage((msg) => this.msg_callback(msg), {\n type: \"browser_mod/connect\",\n deviceID: card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__.deviceID,\n });\n\n this._hass_patched = false;\n (0,card_tools_src_hass__WEBPACK_IMPORTED_MODULE_1__.provideHass)(this);\n }\n\n set hass(hass) {\n this._hass = hass;\n }\n\n get connected() {\n return this._connection !== undefined;\n }\n\n msg_callback(message) {\n console.log(message);\n }\n\n sendUpdate(data) {\n if (!this.connected) return;\n this._connection.sendMessage({\n type: \"browser_mod/update\",\n deviceID: card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__.deviceID,\n data,\n });\n }\n}\n\n\n//# sourceURL=webpack://browser_mod/./js/connection.js?");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./js/fullyKiosk.js":
|
||||
/*!**************************!*\
|
||||
!*** ./js/fullyKiosk.js ***!
|
||||
\**************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"FullyKioskMixin\": () => (/* binding */ FullyKioskMixin)\n/* harmony export */ });\nconst FullyKioskMixin = (C) =>\n class extends C {\n get isFully() {\n return window.fully !== undefined;\n }\n\n constructor() {\n super();\n\n if (!this.isFully) return;\n\n this._fullyMotion = false;\n this._motionTimeout = undefined;\n\n for (const ev of [\n \"screenOn\",\n \"screenOff\",\n \"pluggedAC\",\n \"pluggedUSB\",\n \"onBatteryLevelChanged\",\n \"unplugged\",\n \"networkReconnect\",\n \"onMotion\",\n ]) {\n window.fully.bind(ev, `window.browser_mod.fully_update(\"${ev}\");`);\n }\n\n this._keepingAlive = false;\n }\n\n fully_update(event) {\n if (!this.isFully) return;\n if (event === \"screenOn\") {\n window.clearTimeout(this._keepAliveTimer);\n if (!this._keepingAlive) this.screen_update();\n } else if (event === \"screenOff\") {\n this.screen_update();\n this._keepingAlive = false;\n if (this.config.force_stay_awake) {\n this._keepAliveTimer = window.setTimeout(() => {\n this._keepingAlive = true;\n window.fully.turnScreenOn();\n window.fully.turnScreenOff();\n }, 270000);\n }\n } else if (event === \"onMotion\") {\n this.fullyMotionTriggered();\n }\n\n this.sendUpdate({\n fully: {\n battery: window.fully.getBatteryLevel(),\n charging: window.fully.isPlugged(),\n motion: this._fullyMotion,\n ip: window.fully.getIp4Address(),\n },\n });\n }\n\n fullyMotionTriggered() {\n if (this._keepingAlive) return;\n this._fullyMotion = true;\n clearTimeout(this._motionTimeout);\n this._motionTimeout = setTimeout(() => {\n this._fullyMotion = false;\n this.fully_update();\n }, 5000);\n this.fully_update();\n }\n };\n\n\n//# sourceURL=webpack://browser_mod/./js/fullyKiosk.js?");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./js/main.js":
|
||||
/*!********************!*\
|
||||
!*** ./js/main.js ***!
|
||||
\********************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! card-tools/src/deviceID */ \"./node_modules/card-tools/src/deviceID.js\");\n/* harmony import */ var card_tools_src_hass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! card-tools/src/hass */ \"./node_modules/card-tools/src/hass.js\");\n/* harmony import */ var card_tools_src_popup__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! card-tools/src/popup */ \"./node_modules/card-tools/src/popup.js\");\n/* harmony import */ var card_tools_src_event__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! card-tools/src/event */ \"./node_modules/card-tools/src/event.js\");\n/* harmony import */ var _browser_player__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./browser-player */ \"./js/browser-player.js\");\n/* harmony import */ var _connection__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./connection */ \"./js/connection.js\");\n/* harmony import */ var _mediaPlayer__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./mediaPlayer */ \"./js/mediaPlayer.js\");\n/* harmony import */ var _fullyKiosk__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./fullyKiosk */ \"./js/fullyKiosk.js\");\n/* harmony import */ var _camera__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./camera */ \"./js/camera.js\");\n/* harmony import */ var _screensaver__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./screensaver */ \"./js/screensaver.js\");\n/* harmony import */ var _popups__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./popups */ \"./js/popups.js\");\n/* harmony import */ var _browser__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./browser */ \"./js/browser.js\");\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nconst ext = (baseClass, mixins) =>\n mixins.reduceRight((base, mixin) => mixin(base), baseClass);\n\nclass BrowserMod extends ext(_connection__WEBPACK_IMPORTED_MODULE_5__.BrowserModConnection, [\n _browser__WEBPACK_IMPORTED_MODULE_11__.BrowserModBrowserMixin,\n _popups__WEBPACK_IMPORTED_MODULE_10__.BrowserModPopupsMixin,\n _screensaver__WEBPACK_IMPORTED_MODULE_9__.BrowserModScreensaverMixin,\n _camera__WEBPACK_IMPORTED_MODULE_8__.BrowserModCameraMixin,\n _fullyKiosk__WEBPACK_IMPORTED_MODULE_7__.FullyKioskMixin,\n _mediaPlayer__WEBPACK_IMPORTED_MODULE_6__.BrowserModMediaPlayerMixin,\n]) {\n constructor() {\n super();\n this.entity_id = card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__.deviceID.replace(\"-\", \"_\");\n this.cast = document.querySelector(\"hc-main\") !== null;\n this.connect();\n\n document.body.addEventListener(\"ll-custom\", (ev) => {\n if (ev.detail.browser_mod) {\n this.msg_callback(ev.detail.browser_mod);\n }\n });\n\n const pjson = __webpack_require__(/*! ../package.json */ \"./package.json\");\n console.info(\n `%cBROWSER_MOD ${pjson.version} IS INSTALLED\n %cDeviceID: ${card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__.deviceID}`,\n \"color: green; font-weight: bold\",\n \"\"\n );\n }\n\n async msg_callback(msg) {\n const handlers = {\n update: (msg) => this.update(msg),\n debug: (msg) => this.debug(msg),\n\n play: (msg) => this.player_play(msg.media_content_id),\n pause: (msg) => this.player_pause(),\n stop: (msg) => this.player_stop(),\n \"set-volume\": (msg) => this.player_set_volume(msg.volume_level),\n mute: (msg) => this.player_mute(msg.mute),\n\n toast: (msg) => this.do_toast(msg.message, msg.duration),\n popup: (msg) => this.do_popup(msg),\n \"close-popup\": (msg) => this.do_close_popup(),\n \"more-info\": (msg) => this.do_more_info(msg.entity_id, msg.large),\n\n navigate: (msg) => this.do_navigate(msg.navigation_path),\n \"set-theme\": (msg) => this.set_theme(msg),\n \"lovelace-reload\": (msg) => this.lovelace_reload(msg),\n \"window-reload\": () => window.location.reload(),\n\n blackout: (msg) =>\n this.do_blackout(msg.time ? parseInt(msg.time) : undefined),\n \"no-blackout\": (msg) => {\n if (msg.brightness && this.isFully) {\n window.fully.setScreenBrightness(msg.brightness);\n }\n this.no_blackout();\n },\n\n \"call-service\": (msg) => this.call_service(msg),\n commands: async (msg) => {\n for (const m of msg.commands) {\n await this.msg_callback(m);\n }\n },\n delay: async (msg) =>\n await new Promise((resolve) => {\n window.setTimeout(resolve, msg.seconds * 1000);\n }),\n };\n\n await handlers[msg.command.replace(\"_\", \"-\")](msg);\n }\n\n debug(msg) {\n (0,card_tools_src_popup__WEBPACK_IMPORTED_MODULE_2__.popUp)(`deviceID`, { type: \"markdown\", content: `# ${card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__.deviceID}` });\n alert(card_tools_src_deviceID__WEBPACK_IMPORTED_MODULE_0__.deviceLine truncated
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./js/mediaPlayer.js":
|
||||
/*!***************************!*\
|
||||
!*** ./js/mediaPlayer.js ***!
|
||||
\***************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BrowserModMediaPlayerMixin\": () => (/* binding */ BrowserModMediaPlayerMixin)\n/* harmony export */ });\nconst BrowserModMediaPlayerMixin = (C) =>\n class extends C {\n constructor() {\n super();\n this.player = new Audio();\n\n for (const event of [\"play\", \"pause\", \"ended\", \"volumechange\"]) {\n this.player.addEventListener(event, () => this.player_update());\n }\n\n window.addEventListener(\"click\", () => this.player.play(), {\n once: true,\n });\n }\n\n player_update(ev) {\n this.sendUpdate({\n player: {\n volume: this.player.volume,\n muted: this.player.muted,\n src: this.player.src,\n state: this.player_state,\n },\n });\n }\n\n get player_state() {\n if (!this.player.src) return \"stopped\";\n if (this.player.ended) return \"stopped\";\n if (this.player.paused) return \"paused\";\n return \"playing\";\n }\n\n player_play(src) {\n if (src) this.player.src = src;\n this.player.play();\n }\n player_pause() {\n this.player.pause();\n }\n player_stop() {\n this.player.pause();\n this.player.src = null;\n }\n player_set_volume(level) {\n if (level === undefined) return;\n this.player.volume = level;\n }\n player_mute(mute) {\n if (mute === undefined) mute = !this.player.muted;\n this.player.muted = Boolean(mute);\n }\n };\n\n\n//# sourceURL=webpack://browser_mod/./js/mediaPlayer.js?");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./js/popups.js":
|
||||
/*!**********************!*\
|
||||
!*** ./js/popups.js ***!
|
||||
\**********************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BrowserModPopupsMixin\": () => (/* binding */ BrowserModPopupsMixin)\n/* harmony export */ });\n/* harmony import */ var card_tools_src_event__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! card-tools/src/event */ \"./node_modules/card-tools/src/event.js\");\n/* harmony import */ var card_tools_src_hass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! card-tools/src/hass */ \"./node_modules/card-tools/src/hass.js\");\n/* harmony import */ var card_tools_src_more_info__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! card-tools/src/more-info */ \"./node_modules/card-tools/src/more-info.js\");\n/* harmony import */ var card_tools_src_popup__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! card-tools/src/popup */ \"./node_modules/card-tools/src/popup.js\");\n\n\n\n\n\nconst BrowserModPopupsMixin = (C) =>\n class extends C {\n constructor() {\n super();\n if (document.querySelector(\"home-assistant\"))\n document\n .querySelector(\"home-assistant\")\n .addEventListener(\"hass-more-info\", (ev) => this._popup_card(ev));\n\n const isCast = document.querySelector(\"hc-main\") !== null;\n if (!isCast) (0,card_tools_src_hass__WEBPACK_IMPORTED_MODULE_1__.load_lovelace)();\n }\n\n _popup_card(ev) {\n if (!(0,card_tools_src_hass__WEBPACK_IMPORTED_MODULE_1__.lovelace)()) return;\n if (!ev.detail || !ev.detail.entityId) return;\n const data = {\n ...(0,card_tools_src_hass__WEBPACK_IMPORTED_MODULE_1__.lovelace)().config.popup_cards,\n ...(0,card_tools_src_hass__WEBPACK_IMPORTED_MODULE_1__.lovelace)().config.views[(0,card_tools_src_hass__WEBPACK_IMPORTED_MODULE_1__.lovelace)().current_view].popup_cards,\n };\n const d = data[ev.detail.entityId];\n if (!d) return;\n\n this.do_popup(d);\n window.setTimeout(() => {\n (0,card_tools_src_event__WEBPACK_IMPORTED_MODULE_0__.fireEvent)(\n \"hass-more-info\",\n { entityID: \".\" },\n document.querySelector(\"home-assistant\")\n );\n }, 50);\n }\n\n do_popup(cfg) {\n if (!(cfg.title || cfg.auto_close || cfg.hide_header)) {\n console.error(\n \"browser_mod: popup: Must specify title, auto_close or hide_header.\"\n );\n return;\n }\n if (!cfg.card) {\n console.error(\"browser_mod: popup: No card specified\");\n return;\n }\n\n const open = () => {\n (0,card_tools_src_popup__WEBPACK_IMPORTED_MODULE_3__.popUp)(\n cfg.title,\n cfg.card,\n cfg.large,\n cfg.style,\n cfg.auto_close || cfg.hide_header\n );\n };\n\n if (cfg.auto_close) {\n this.screensaver_set(open, card_tools_src_popup__WEBPACK_IMPORTED_MODULE_3__.closePopUp, cfg.time);\n } else {\n open();\n }\n }\n\n do_close_popup() {\n this.screensaver_stop();\n (0,card_tools_src_popup__WEBPACK_IMPORTED_MODULE_3__.closePopUp)();\n }\n\n do_more_info(entity_id, large) {\n if (!entity_id) return;\n (0,card_tools_src_more_info__WEBPACK_IMPORTED_MODULE_2__.moreInfo)(entity_id, large);\n }\n\n do_toast(message, duration) {\n if (!message) return;\n (0,card_tools_src_event__WEBPACK_IMPORTED_MODULE_0__.fireEvent)(\n \"hass-notification\",\n {\n message,\n duration: parseInt(duration),\n },\n document.querySelector(\"home-assistant\")\n );\n }\n };\n\n\n//# sourceURL=webpack://browser_mod/./js/popups.js?");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./js/screensaver.js":
|
||||
/*!***************************!*\
|
||||
!*** ./js/screensaver.js ***!
|
||||
\***************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BrowserModScreensaverMixin\": () => (/* binding */ BrowserModScreensaverMixin)\n/* harmony export */ });\nconst BrowserModScreensaverMixin = (C) =>\n class extends C {\n constructor() {\n super();\n this._blackout_panel = document.createElement(\"div\");\n\n this._screenSaver = undefined;\n this._screenSaverTimer = undefined;\n this._screenSaverTimeOut = 0;\n\n this._screenSaver = {\n fn: undefined,\n clearfn: undefined,\n timer: undefined,\n timeout: undefined,\n listeners: {},\n active: false,\n };\n\n this._blackout_panel.style.cssText = `\n position: fixed;\n left: 0;\n top: 0;\n padding: 0;\n margin: 0;\n width: 100%;\n height: 100%;\n background: black;\n display: none;\n `;\n document.body.appendChild(this._blackout_panel);\n }\n\n screensaver_set(fn, clearfn, time) {\n this._ss_clear();\n this._screenSaver = {\n fn,\n clearfn,\n timer: undefined,\n timeout: time,\n listeners: {},\n active: false,\n };\n const l = () => this.screensaver_update();\n for (const event of [\"mousemove\", \"mousedown\", \"keydown\", \"touchstart\"]) {\n window.addEventListener(event, l);\n this._screenSaver.listeners[event] = l;\n }\n this._screenSaver.timer = window.setTimeout(\n () => this._ss_run(),\n time * 1000\n );\n }\n\n screensaver_update() {\n if (this._screenSaver.active) {\n this.screensaver_stop();\n } else {\n window.clearTimeout(this._screenSaver.timer);\n this._screenSaver.timer = window.setTimeout(\n () => this._ss_run(),\n this._screenSaver.timeout * 1000\n );\n }\n }\n\n screensaver_stop() {\n this._ss_clear();\n this._screenSaver.active = false;\n if (this._screenSaver.clearfn) this._screenSaver.clearfn();\n if (this._screenSaver.timeout) {\n this.screensaver_set(\n this._screenSaver.fn,\n this._screenSaver.clearfn,\n this._screenSaver.timeout\n );\n }\n }\n\n _ss_clear() {\n window.clearTimeout(this._screenSaverTimer);\n for (const [k, v] of Object.entries(this._screenSaver.listeners)) {\n window.removeEventListener(k, v);\n }\n }\n\n _ss_run() {\n this._screenSaver.active = true;\n this._screenSaver.fn();\n }\n\n do_blackout(timeout) {\n this.screensaver_set(\n () => {\n if (this.isFully) window.fully.turnScreenOff(true);\n else this._blackout_panel.style.display = \"block\";\n this.screen_update();\n },\n () => {\n if ((this._blackout_panel.style.display = \"block\"))\n this._blackout_panel.style.display = \"none\";\n if (this.isFully && !window.fully.getScreenOn())\n window.fully.turnScreenOn();\n this.screen_update();\n },\n timeout || 0\n );\n }\n\n no_blackout() {\n if (this.isFully) window.fully.turnScreenOn();\n this.screensaver_stop();\n }\n\n screen_update() {\n this.sendUpdate({\n screen: {\n blackout: this.isFully\n ? !window.fully.getScreenOn()\n : Boolean(this._blackout_panel.style.display === \"block\"),\n brightness: this.isFully\n ? window.fully.getScreenBrightness()\n : undefined,\n },\n });\n }\n };\n\n\n//# sourceURL=webpack://browser_mod/./js/screensaver.js?");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./node_modules/card-tools/src/deviceID.js":
|
||||
/*!*************************************************!*\
|
||||
!*** ./node_modules/card-tools/src/deviceID.js ***!
|
||||
\*************************************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"deviceID\": () => (/* binding */ deviceID),\n/* harmony export */ \"setDeviceID\": () => (/* binding */ setDeviceID)\n/* harmony export */ });\nconst ID_STORAGE_KEY = 'lovelace-player-device-id';\nfunction _deviceID() {\n if(!localStorage[ID_STORAGE_KEY])\n {\n const s4 = () => {\n return Math.floor((1+Math.random())*100000).toString(16).substring(1);\n };\n if(window['fully'] && typeof fully.getDeviceId === \"function\")\n localStorage[ID_STORAGE_KEY] = fully.getDeviceId();\n else\n localStorage[ID_STORAGE_KEY] = `${s4()}${s4()}-${s4()}${s4()}`;\n }\n return localStorage[ID_STORAGE_KEY];\n};\n\nlet deviceID = _deviceID();\n\nconst setDeviceID = (id) => {\n if(id === null) return;\n if(id === \"clear\") {\n localStorage.removeItem(ID_STORAGE_KEY)\n } else {\n localStorage[ID_STORAGE_KEY] = id;\n }\n deviceID = _deviceID();\n}\n\nconst params = new URLSearchParams(window.location.search);\nif(params.get('deviceID')) {\n setDeviceID(params.get('deviceID'));\n}\n\n\n\n//# sourceURL=webpack://browser_mod/./node_modules/card-tools/src/deviceID.js?");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./node_modules/card-tools/src/event.js":
|
||||
/*!**********************************************!*\
|
||||
!*** ./node_modules/card-tools/src/event.js ***!
|
||||
\**********************************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"fireEvent\": () => (/* binding */ fireEvent)\n/* harmony export */ });\n/* harmony import */ var _hass__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hass */ \"./node_modules/card-tools/src/hass.js\");\n\n\nfunction fireEvent(ev, detail, entity=null) {\n ev = new Event(ev, {\n bubbles: true,\n cancelable: false,\n composed: true,\n });\n ev.detail = detail || {};\n if(entity) {\n entity.dispatchEvent(ev);\n } else {\n var root = (0,_hass__WEBPACK_IMPORTED_MODULE_0__.lovelace_view)();\n if (root) root.dispatchEvent(ev);\n }\n}\n\n\n//# sourceURL=webpack://browser_mod/./node_modules/card-tools/src/event.js?");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./node_modules/card-tools/src/hass.js":
|
||||
/*!*********************************************!*\
|
||||
!*** ./node_modules/card-tools/src/hass.js ***!
|
||||
\*********************************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"hass\": () => (/* binding */ hass),\n/* harmony export */ \"provideHass\": () => (/* binding */ provideHass),\n/* harmony export */ \"lovelace\": () => (/* binding */ lovelace),\n/* harmony export */ \"async_lovelace_view\": () => (/* binding */ async_lovelace_view),\n/* harmony export */ \"lovelace_view\": () => (/* binding */ lovelace_view),\n/* harmony export */ \"load_lovelace\": () => (/* binding */ load_lovelace)\n/* harmony export */ });\nfunction hass() {\n if(document.querySelector('hc-main'))\n return document.querySelector('hc-main').hass;\n\n if(document.querySelector('home-assistant'))\n return document.querySelector('home-assistant').hass;\n\n return undefined;\n};\n\nfunction provideHass(element) {\n if(document.querySelector('hc-main'))\n return document.querySelector('hc-main').provideHass(element);\n\n if(document.querySelector('home-assistant'))\n return document.querySelector(\"home-assistant\").provideHass(element);\n\n return undefined;\n}\n\nfunction lovelace() {\n var root = document.querySelector(\"hc-main\");\n if(root) {\n var ll = root._lovelaceConfig;\n ll.current_view = root._lovelacePath;\n return ll;\n }\n\n root = document.querySelector(\"home-assistant\");\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"home-assistant-main\");\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"app-drawer-layout partial-panel-resolver\");\n root = root && root.shadowRoot || root;\n root = root && root.querySelector(\"ha-panel-lovelace\")\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"hui-root\")\n if (root) {\n var ll = root.lovelace\n ll.current_view = root.___curView;\n return ll;\n }\n\n return null;\n}\n\nasync function await_el(el) {\n if(!el) return;\n await customElements.whenDefined(el.localName);\n if(el.updateComplete)\n await el.updateComplete;\n}\n\nasync function async_lovelace_view() {\n var root = document.querySelector(\"hc-main\");\n if(root) {\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"hc-lovelace\");\n await_el(root);\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"hui-view\") || root.querySelector(\"hui-panel-view\");\n await_el(root);\n return root;\n }\n\n root = document.querySelector(\"home-assistant\");\n await_el(root);\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"home-assistant-main\");\n await_el(root);\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"app-drawer-layout partial-panel-resolver\");\n await_el(root);\n root = root && root.shadowRoot || root;\n root = root && root.querySelector(\"ha-panel-lovelace\");\n await_el(root);\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"hui-root\");\n await_el(root);\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"ha-app-layout\")\n await_el(root);\n root = root && root.querySelector(\"#view\");\n root = root && root.firstElementChild;\n await_el(root);\n return root;\n}\nfunction lovelace_view() {\n var root = document.querySelector(\"hc-main\");\n if(root) {\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"hc-lovelace\");\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"hui-view\") || root.querySelector(\"hui-panel-view\");\n return root;\n }\n\n root = document.querySelector(\"home-assistant\");\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"home-assistant-main\");\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"app-drawer-layout partial-panel-resolver\");\n root = root && root.shadowRoot || root;\n root = root && root.querySelector(\"ha-panel-lovelace\");\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"hui-root\");\n root = root && root.shadowRoot;\n root = root && root.querySelector(\"ha-app-layout\")\n root = root && root.querySelector(\"#view\");\n root = root && root.firstElementChild;\n return root;\n}\n\nasync function load_lovelace() {\n if(customElements.get(\"hui-view\")) return true;\n\n await customElements.whenDefined(\"partial-panel-resolver\");\n const ppr = document.createElement(\"partial-panel-resolver\");\n ppr.hass = {panels: [{\n url_path: \"tmp\",\n \"component_name\": \"lovelace\",\n }]};\n ppr._updateRoutes();\n await ppr.routerOptions.routes.tmp.load();\n if(!customElements.get(\"ha-panel-lovelace\")) return false;\n const p = document.createElement(\"ha-panel-lovelace\");\n p.hass = hass();\n if(p.hass === undefined) {\n await new Promise(resolve => {\n window.addEventListener('connection-status', (ev) => {\n console.log(ev);\n resolve();\Line truncated
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./node_modules/card-tools/src/helpers.js":
|
||||
/*!************************************************!*\
|
||||
!*** ./node_modules/card-tools/src/helpers.js ***!
|
||||
\************************************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"selectTree\": () => (/* binding */ selectTree)\n/* harmony export */ });\nasync function _selectTree(root, path, all=false) {\n let el = root;\n if(typeof(path) === \"string\") {\n path = path.split(/(\\$| )/);\n }\n if(path[path.length-1] === \"\")\n path.pop();\n for(const [i, p] of path.entries()) {\n if(!p.trim().length) continue;\n if(!el) return null;\n if(el.localName && el.localName.includes(\"-\"))\n await customElements.whenDefined(el.localName);\n if(el.updateComplete)\n await el.updateComplete;\n if(p === \"$\")\n if(all && i == path.length-1)\n el = [el.shadowRoot];\n else\n el = el.shadowRoot;\n else\n if(all && i == path.length-1)\n el = el.querySelectorAll(p);\n else\n el = el.querySelector(p);\n }\n return el;\n}\n\nasync function selectTree(root, path, all=false, timeout=10000) {\n return Promise.race([\n _selectTree(root, path, all),\n new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout))\n ]).catch((err) => {\n if(!err.message || err.message !== \"timeout\")\n throw(err);\n return null;\n });\n}\n\n\n//# sourceURL=webpack://browser_mod/./node_modules/card-tools/src/helpers.js?");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./node_modules/card-tools/src/lovelace-element.js":
|
||||
/*!*********************************************************!*\
|
||||
!*** ./node_modules/card-tools/src/lovelace-element.js ***!
|
||||
\*********************************************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"CUSTOM_TYPE_PREFIX\": () => (/* binding */ CUSTOM_TYPE_PREFIX),\n/* harmony export */ \"DOMAINS_HIDE_MORE_INFO\": () => (/* binding */ DOMAINS_HIDE_MORE_INFO),\n/* harmony export */ \"createCard\": () => (/* binding */ createCard),\n/* harmony export */ \"createElement\": () => (/* binding */ createElement),\n/* harmony export */ \"createEntityRow\": () => (/* binding */ createEntityRow)\n/* harmony export */ });\n/* harmony import */ var _event__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./event */ \"./node_modules/card-tools/src/event.js\");\n/* harmony import */ var _hass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./hass */ \"./node_modules/card-tools/src/hass.js\");\n\n\n\nconst CUSTOM_TYPE_PREFIX = \"custom:\";\n\nconst DOMAINS_HIDE_MORE_INFO = [\n \"input_number\",\n \"input_select\",\n \"input_text\",\n \"scene\",\n \"weblink\",\n];\n\nlet helpers = window.cardHelpers;\nconst helperPromise = new Promise(async (resolve, reject) => {\n if(helpers) resolve();\n\n const updateHelpers = async () => {\n helpers = await window.loadCardHelpers();\n window.cardHelpers = helpers;\n resolve();\n }\n\n if(window.loadCardHelpers) {\n updateHelpers();\n } else {\n // If loadCardHelpers didn't exist, force load lovelace and try once more.\n window.addEventListener(\"load\", async () => {\n (0,_hass__WEBPACK_IMPORTED_MODULE_1__.load_lovelace)();\n if(window.loadCardHelpers) {\n updateHelpers();\n }\n });\n }\n});\n\nfunction errorElement(error, origConfig) {\n const cfg = {\n type: \"error\",\n error,\n origConfig,\n };\n const el = document.createElement(\"hui-error-card\");\n customElements.whenDefined(\"hui-error-card\").then(() => {\n const newel = document.createElement(\"hui-error-card\");\n newel.setConfig(cfg);\n if(el.parentElement)\n el.parentElement.replaceChild(newel, el);\n });\n helperPromise.then(() => {\n (0,_event__WEBPACK_IMPORTED_MODULE_0__.fireEvent)(\"ll-rebuild\", {}, el);\n });\n return el;\n}\n\nfunction _createElement(tag, config) {\n let el = document.createElement(tag);\n try {\n el.setConfig(JSON.parse(JSON.stringify(config)));\n } catch (err) {\n el = errorElement(err, config);\n }\n helperPromise.then(() => {\n (0,_event__WEBPACK_IMPORTED_MODULE_0__.fireEvent)(\"ll-rebuild\", {}, el);\n });\n return el;\n}\n\nfunction createLovelaceElement(thing, config) {\n if(!config || typeof config !== \"object\" || !config.type)\n return errorElement(`No ${thing} type configured`, config);\n\n let tag = config.type;\n if(tag.startsWith(CUSTOM_TYPE_PREFIX))\n tag = tag.substr(CUSTOM_TYPE_PREFIX.length);\n else\n tag = `hui-${tag}-${thing}`;\n\n if(customElements.get(tag))\n return _createElement(tag, config);\n\n const el = errorElement(`Custom element doesn't exist: ${tag}.`, config);\n el.style.display = \"None\";\n\n const timer = setTimeout(() => {\n el.style.display = \"\";\n }, 2000);\n\n customElements.whenDefined(tag).then(() => {\n clearTimeout(timer);\n (0,_event__WEBPACK_IMPORTED_MODULE_0__.fireEvent)(\"ll-rebuild\", {}, el);\n });\n\n return el;\n}\n\nfunction createCard(config) {\n if(helpers) return helpers.createCardElement(config);\n return createLovelaceElement('card', config);\n}\nfunction createElement(config) {\n if(helpers) return helpers.createHuiElement(config);\n return createLovelaceElement('element', config);\n}\nfunction createEntityRow(config) {\n if(helpers) return helpers.createRowElement(config);\n const SPECIAL_TYPES = new Set([\n \"call-service\",\n \"cast\",\n \"conditional\",\n \"divider\",\n \"section\",\n \"select\",\n \"weblink\",\n ]);\n const DEFAULT_ROWS = {\n alert: \"toggle\",\n automation: \"toggle\",\n climate: \"climate\",\n cover: \"cover\",\n fan: \"toggle\",\n group: \"group\",\n input_boolean: \"toggle\",\n input_number: \"input-number\",\n input_select: \"input-select\",\n input_text: \"input-text\",\n light: \"toggle\",\n lock: \"lock\",\n media_player: \"media-player\",\n remote: \"toggle\",\n scene: \"scene\",\n script: \"script\",\n sensor: \"sensor\",\n timer: \"timer\",\n switch: \"toggle\",\n vacuum: \"toggle\",\n water_heater: \"climate\",\n input_datetime: \"input-datetime\",\n none: undefined,\n };\n\n if(!config)\n return errorElement(\"Invalid configuration given.\", config);\n if(typeof config === \"string\")\n config = {entity: config};\n if(typeof config !== \"object\" || (!config.entity && !config.type))\n return errorElement(\"Invalid configuration given.\", config);\n\n const type = config.type || \"default\";\n if(SPECIAL_TYPES.has(type) || type.startsWith(CUSTOM_TYPE_PREFIX))\n return createLovelaceElement('roLine truncated
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./node_modules/card-tools/src/more-info.js":
|
||||
/*!**************************************************!*\
|
||||
!*** ./node_modules/card-tools/src/more-info.js ***!
|
||||
\**************************************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"moreInfo\": () => (/* binding */ moreInfo)\n/* harmony export */ });\n/* harmony import */ var _event__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./event */ \"./node_modules/card-tools/src/event.js\");\n/* harmony import */ var _helpers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers */ \"./node_modules/card-tools/src/helpers.js\");\n\n\n\nasync function moreInfo(entity, large=false) {\n const root = document.querySelector(\"hc-main\") || document.querySelector(\"home-assistant\");\n (0,_event__WEBPACK_IMPORTED_MODULE_0__.fireEvent)(\"hass-more-info\", {entityId: entity}, root);\n const el = await (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.selectTree)(root, \"$ ha-more-info-dialog\");\n if(el)\n el.large = large;\n return el;\n}\n\n\n//# sourceURL=webpack://browser_mod/./node_modules/card-tools/src/more-info.js?");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./node_modules/card-tools/src/popup.js":
|
||||
/*!**********************************************!*\
|
||||
!*** ./node_modules/card-tools/src/popup.js ***!
|
||||
\**********************************************/
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"closePopUp\": () => (/* binding */ closePopUp),\n/* harmony export */ \"popUp\": () => (/* binding */ popUp)\n/* harmony export */ });\n/* harmony import */ var _hass__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hass */ \"./node_modules/card-tools/src/hass.js\");\n/* harmony import */ var _helpers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers */ \"./node_modules/card-tools/src/helpers.js\");\n/* harmony import */ var _event__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./event */ \"./node_modules/card-tools/src/event.js\");\n/* harmony import */ var _lovelace_element__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./lovelace-element */ \"./node_modules/card-tools/src/lovelace-element.js\");\n\n\n\n\n\nasync function closePopUp() {\n const root = document.querySelector(\"home-assistant\") || document.querySelector(\"hc-root\");\n (0,_event__WEBPACK_IMPORTED_MODULE_2__.fireEvent)(\"hass-more-info\", {entityId: \".\"}, root);\n const el = await (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.selectTree)(root, \"$ card-tools-popup\");\n\n if(el)\n el.closeDialog();\n}\n\nasync function popUp(title, card, large=false, style={}, fullscreen=false) {\n if(!customElements.get(\"card-tools-popup\"))\n {\n const LitElement = customElements.get('home-assistant-main')\n ? Object.getPrototypeOf(customElements.get('home-assistant-main'))\n : Object.getPrototypeOf(customElements.get('hui-view'));\n const html = LitElement.prototype.html;\n const css = LitElement.prototype.css;\n\n class CardToolsPopup extends LitElement {\n\n static get properties() {\n return {\n open: {},\n large: {reflect: true, type: Boolean},\n hass: {},\n };\n }\n\n updated(changedProperties) {\n if(changedProperties.has(\"hass\")) {\n if(this.card)\n this.card.hass = this.hass;\n }\n }\n\n closeDialog() {\n this.open = false;\n }\n\n async _makeCard() {\n const helpers = await window.loadCardHelpers();\n this.card = await helpers.createCardElement(this._card);\n this.card.hass = this.hass;\n this.requestUpdate();\n }\n\n async _applyStyles() {\n let el = await (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.selectTree)(this, \"$ ha-dialog\");\n customElements.whenDefined(\"card-mod\").then(async () => {\n if(!el) return;\n const cm = customElements.get(\"card-mod\");\n cm.applyToElement(el, \"more-info\", this._style, {config: this._card}, [], false);\n });\n\n }\n\n async showDialog(title, card, large=false, style={}, fullscreen=false) {\n this.title = title;\n this._card = card;\n this.large = large;\n this._style = style;\n this.fullscreen = !!fullscreen;\n this._makeCard();\n await this.updateComplete;\n this.open = true;\n await this._applyStyles();\n }\n\n _enlarge() {\n this.large = !this.large;\n }\n\n render() {\n if(!this.open) {\n return html``;\n }\n\n return html`\n <ha-dialog\n open\n @closed=${this.closeDialog}\n .heading=${true}\n hideActions\n @ll-rebuild=${this._makeCard}\n >\n ${this.fullscreen\n ? html`<div slot=\"heading\"></div>`\n : html`\n <app-toolbar slot=\"heading\">\n <mwc-icon-button\n .label=${\"dismiss\"}\n dialogAction=\"cancel\"\n >\n <ha-icon\n .icon=${\"mdi:close\"}\n ></ha-icon>\n </mwc-icon-button>\n <div class=\"main-title\" @click=${this._enlarge}>\n ${this.title}\n </div>\n </app-toolbar>\n `}\n <div class=\"content\">\n ${this.card}\n </div>\n </ha-dialog>\n `\n }\n\n static get styles() {\n return css`\n ha-dialog {\n --mdc-dialog-min-width: 400px;\n --mdc-dialog-max-width: 600px;\n --mdc-dialog-heading-ink-color: var(--primary-text-color);\n --mdc-dialog-content-ink-color: var(--primary-text-color);\n --justify-action-buttons: space-between;\n }\n @media all and (max-width: 450px), all and (max-height: 500px) {\n ha-dialog {\n --mdc-dialog-min-width: 100vw;\n --mdc-dialog-max-width: 100vw;\n --mdc-dialog-mLine truncated
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./package.json":
|
||||
/*!**********************!*\
|
||||
!*** ./package.json ***!
|
||||
\**********************/
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
eval("module.exports = JSON.parse('{\"name\":\"browser_mod\",\"private\":true,\"version\":\"1.3.0\",\"description\":\"\",\"scripts\":{\"build\":\"webpack\",\"watch\":\"webpack --watch --mode=development\",\"update-card-tools\":\"npm uninstall card-tools && npm install thomasloven/lovelace-card-tools\"},\"keywords\":[],\"author\":\"Thomas Lovén\",\"license\":\"MIT\",\"devDependencies\":{\"webpack\":\"^5.36.2\",\"webpack-cli\":\"^4.7.0\"},\"dependencies\":{\"card-tools\":\"github:thomasloven/lovelace-card-tools\"}}');\n\n//# sourceURL=webpack://browser_mod/./package.json?");
|
||||
|
||||
/***/ })
|
||||
|
||||
/******/ });
|
||||
/************************************************************************/
|
||||
/******/ // The module cache
|
||||
/******/ var __webpack_module_cache__ = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/ // Check if module is in cache
|
||||
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
||||
/******/ if (cachedModule !== undefined) {
|
||||
/******/ return cachedModule.exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||||
/******/ // no module.id needed
|
||||
/******/ // no module.loaded needed
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/************************************************************************/
|
||||
/******/ /* webpack/runtime/compat get default export */
|
||||
/******/ (() => {
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = (module) => {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ () => (module['default']) :
|
||||
/******/ () => (module);
|
||||
/******/ __webpack_require__.d(getter, { a: getter });
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/ })();
|
||||
/******/
|
||||
/******/ /* webpack/runtime/define property getters */
|
||||
/******/ (() => {
|
||||
/******/ // define getter functions for harmony exports
|
||||
/******/ __webpack_require__.d = (exports, definition) => {
|
||||
/******/ for(var key in definition) {
|
||||
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
||||
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
||||
/******/ }
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/ })();
|
||||
/******/
|
||||
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
||||
/******/ (() => {
|
||||
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
||||
/******/ })();
|
||||
/******/
|
||||
/******/ /* webpack/runtime/make namespace object */
|
||||
/******/ (() => {
|
||||
/******/ // define __esModule on exports
|
||||
/******/ __webpack_require__.r = (exports) => {
|
||||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
/******/ }
|
||||
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||
/******/ };
|
||||
/******/ })();
|
||||
/******/
|
||||
/************************************************************************/
|
||||
/******/
|
||||
/******/ // startup
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ // This entry module can't be inlined because the eval devtool is used.
|
||||
/******/ var __webpack_exports__ = __webpack_require__("./js/main.js");
|
||||
/******/
|
||||
/******/ })()
|
||||
;
|
||||
+17
-19
@@ -1,30 +1,28 @@
|
||||
import { registerCard } from "card-tools/src/editor";
|
||||
|
||||
const bases = [customElements.whenDefined('home-assistant-main'), customElements.whenDefined('hui-view')];
|
||||
const bases = [
|
||||
customElements.whenDefined("home-assistant-main"),
|
||||
customElements.whenDefined("hui-view"),
|
||||
];
|
||||
Promise.race(bases).then(() => {
|
||||
|
||||
const LitElement = customElements.get('home-assistant-main')
|
||||
? Object.getPrototypeOf(customElements.get('home-assistant-main'))
|
||||
: Object.getPrototypeOf(customElements.get('hui-view'));
|
||||
const LitElement = customElements.get("home-assistant-main")
|
||||
? Object.getPrototypeOf(customElements.get("home-assistant-main"))
|
||||
: Object.getPrototypeOf(customElements.get("hui-view"));
|
||||
const html = LitElement.prototype.html;
|
||||
const css = LitElement.prototype.css;
|
||||
|
||||
class BrowserPlayerEditor extends LitElement {
|
||||
setConfig(config) {
|
||||
|
||||
}
|
||||
render() {
|
||||
return html`
|
||||
<div>
|
||||
Nothing to configure.
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
setConfig(config) {}
|
||||
render() {
|
||||
return html` <div>Nothing to configure.</div> `;
|
||||
}
|
||||
}
|
||||
|
||||
if(!customElements.get("browser-player-editor")) {
|
||||
if (!customElements.get("browser-player-editor")) {
|
||||
customElements.define("browser-player-editor", BrowserPlayerEditor);
|
||||
window.customCards = window.customCards || [];
|
||||
window.customCards.push({type:"browser-player", name: "Browser Player", preview: true});
|
||||
window.customCards.push({
|
||||
type: "browser-player",
|
||||
name: "Browser Player",
|
||||
preview: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
+126
-128
@@ -1,138 +1,136 @@
|
||||
import { deviceID, setDeviceID } from "card-tools/src/deviceId"
|
||||
import { moreInfo } from "card-tools/src/more-info"
|
||||
import "./browser-player-editor.js"
|
||||
import { deviceID, setDeviceID } from "card-tools/src/deviceID";
|
||||
import { moreInfo } from "card-tools/src/more-info";
|
||||
import "./browser-player-editor.js";
|
||||
|
||||
const bases = [customElements.whenDefined('home-assistant-main'), customElements.whenDefined('hui-view')];
|
||||
const bases = [
|
||||
customElements.whenDefined("home-assistant-main"),
|
||||
customElements.whenDefined("hui-view"),
|
||||
];
|
||||
Promise.race(bases).then(() => {
|
||||
const LitElement = customElements.get("home-assistant-main")
|
||||
? Object.getPrototypeOf(customElements.get("home-assistant-main"))
|
||||
: Object.getPrototypeOf(customElements.get("hui-view"));
|
||||
const html = LitElement.prototype.html;
|
||||
const css = LitElement.prototype.css;
|
||||
|
||||
const LitElement = customElements.get('home-assistant-main')
|
||||
? Object.getPrototypeOf(customElements.get('home-assistant-main'))
|
||||
: Object.getPrototypeOf(customElements.get('hui-view'));
|
||||
const html = LitElement.prototype.html;
|
||||
const css = LitElement.prototype.css;
|
||||
|
||||
class BrowserPlayer extends LitElement {
|
||||
|
||||
static get properties() {
|
||||
return {
|
||||
hass: {},
|
||||
};
|
||||
}
|
||||
|
||||
static getConfigElement() {
|
||||
return document.createElement("browser-player-editor");
|
||||
}
|
||||
static getStubConfig() {
|
||||
return {};
|
||||
}
|
||||
|
||||
setConfig(config) {
|
||||
this._config = config;
|
||||
for (const event of ["play", "pause", "ended", "volumechange", "canplay", "loadeddata"])
|
||||
window.browser_mod.player.addEventListener(event, () => this.requestUpdate());
|
||||
}
|
||||
handleMute(ev) {
|
||||
window.browser_mod.player_mute();
|
||||
}
|
||||
handleVolumeChange(ev) {
|
||||
const vol = parseFloat(ev.target.value);
|
||||
window.browser_mod.player_set_volume(vol);
|
||||
}
|
||||
handleMoreInfo(ev) {
|
||||
moreInfo("media_player."+window.browser_mod.entity_id);
|
||||
}
|
||||
handlePlayPause(ev) {
|
||||
if (window.browser_mod.player.paused)
|
||||
window.browser_mod.player_play();
|
||||
else
|
||||
window.browser_mod.player_pause();
|
||||
}
|
||||
setDeviceID() {
|
||||
const newID = prompt("Set deviceID", deviceID);
|
||||
if (newID !== deviceID) {
|
||||
setDeviceID(newID);
|
||||
this.requestUpdate();
|
||||
class BrowserPlayer extends LitElement {
|
||||
static get properties() {
|
||||
return {
|
||||
hass: {},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
if(!window.browser_mod) {
|
||||
window.setTimeout(() => this.requestUpdate(), 100);
|
||||
return html``;
|
||||
static getConfigElement() {
|
||||
return document.createElement("browser-player-editor");
|
||||
}
|
||||
const player = window.browser_mod.player;
|
||||
return html`
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<ha-icon-button
|
||||
.icon=${player.muted
|
||||
? "mdi:volume-off"
|
||||
: "mdi:volume-high"
|
||||
static getStubConfig() {
|
||||
return {};
|
||||
}
|
||||
|
||||
setConfig(config) {
|
||||
this._config = config;
|
||||
for (const event of [
|
||||
"play",
|
||||
"pause",
|
||||
"ended",
|
||||
"volumechange",
|
||||
"canplay",
|
||||
"loadeddata",
|
||||
])
|
||||
window.browser_mod.player.addEventListener(event, () =>
|
||||
this.requestUpdate()
|
||||
);
|
||||
}
|
||||
handleMute(ev) {
|
||||
window.browser_mod.player_mute();
|
||||
}
|
||||
handleVolumeChange(ev) {
|
||||
const vol = parseFloat(ev.target.value);
|
||||
window.browser_mod.player_set_volume(vol);
|
||||
}
|
||||
handleMoreInfo(ev) {
|
||||
moreInfo("media_player." + window.browser_mod.entity_id);
|
||||
}
|
||||
handlePlayPause(ev) {
|
||||
if (window.browser_mod.player.paused) window.browser_mod.player_play();
|
||||
else window.browser_mod.player_pause();
|
||||
}
|
||||
setDeviceID() {
|
||||
const newID = prompt("Set deviceID", deviceID);
|
||||
if (newID !== deviceID) {
|
||||
setDeviceID(newID);
|
||||
this.requestUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!window.browser_mod) {
|
||||
window.setTimeout(() => this.requestUpdate(), 100);
|
||||
return html``;
|
||||
}
|
||||
const player = window.browser_mod.player;
|
||||
return html`
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<ha-icon-button
|
||||
.icon=${player.muted ? "mdi:volume-off" : "mdi:volume-high"}
|
||||
@click=${this.handleMute}
|
||||
></ha-icon-button>
|
||||
<ha-slider
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.01"
|
||||
?disabled=${player.muted}
|
||||
value=${player.volume}
|
||||
@change=${this.handleVolumeChange}
|
||||
></ha-slider>
|
||||
|
||||
${window.browser_mod.player_state === "stopped"
|
||||
? html`<div class="placeholder"></div>`
|
||||
: html`
|
||||
<ha-icon-button
|
||||
.icon=${player.paused ? "mdi:play" : "mdi:pause"}
|
||||
@click=${this.handlePlayPause}
|
||||
highlight
|
||||
></ha-icon-button>
|
||||
`}
|
||||
<ha-icon-button
|
||||
.icon=${"mdi:cog"}
|
||||
@click=${this.handleMoreInfo}
|
||||
></ha-icon-button>
|
||||
</div>
|
||||
|
||||
<div class="device-id" @click=${this.setDeviceID}>${deviceID}</div>
|
||||
</ha-card>
|
||||
`;
|
||||
}
|
||||
|
||||
static get styles() {
|
||||
return css`
|
||||
paper-icon-button[highlight] {
|
||||
color: var(--accent-color);
|
||||
}
|
||||
@click=${this.handleMute}
|
||||
></ha-icon-button>
|
||||
<ha-slider
|
||||
min=0
|
||||
max=1
|
||||
step=0.01
|
||||
?disabled=${player.muted}
|
||||
value=${player.volume}
|
||||
@change=${this.handleVolumeChange}
|
||||
></ha-slider>
|
||||
|
||||
${window.browser_mod.player_state === "stopped"
|
||||
? html`<div class="placeholder"></div>`
|
||||
: html`
|
||||
<ha-icon-button
|
||||
.icon=${player.paused
|
||||
? "mdi:play"
|
||||
: "mdi:pause"
|
||||
}
|
||||
@click=${this.handlePlayPause}
|
||||
highlight
|
||||
></ha-icon-button>
|
||||
`}
|
||||
<ha-icon-button
|
||||
.icon=${"mdi:cog"}
|
||||
@click=${this.handleMoreInfo}
|
||||
></ha-icon-button>
|
||||
</div>
|
||||
|
||||
<div class="device-id" @click=${this.setDeviceID}>
|
||||
${deviceID}
|
||||
</div>
|
||||
|
||||
</ha-card>
|
||||
`;
|
||||
.card-content {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.placeholder {
|
||||
width: 24px;
|
||||
padding: 8px;
|
||||
}
|
||||
.device-id {
|
||||
opacity: 0.7;
|
||||
font-size: xx-small;
|
||||
margin-top: -10px;
|
||||
user-select: all;
|
||||
-webkit-user-select: all;
|
||||
-moz-user-select: all;
|
||||
-ms-user-select: all;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
static get styles() {
|
||||
return css`
|
||||
paper-icon-button[highlight] {
|
||||
color: var(--accent-color);
|
||||
}
|
||||
.card-content {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.placeholder {
|
||||
width: 24px;
|
||||
padding: 8px;
|
||||
}
|
||||
.device-id {
|
||||
opacity: 0.7;
|
||||
font-size: xx-small;
|
||||
margin-top: -10px;
|
||||
user-select: all;
|
||||
-webkit-user-select: all;
|
||||
-moz-user-select: all;
|
||||
-ms-user-select: all;
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!customElements.get("browser-player"))
|
||||
customElements.define("browser-player", BrowserPlayer);
|
||||
if (!customElements.get("browser-player"))
|
||||
customElements.define("browser-player", BrowserPlayer);
|
||||
});
|
||||
+41
-25
@@ -1,36 +1,52 @@
|
||||
import { fireEvent } from "card-tools/src/event";
|
||||
|
||||
export const BrowserModBrowserMixin = (C) => class extends C {
|
||||
|
||||
export const BrowserModBrowserMixin = (C) =>
|
||||
class extends C {
|
||||
constructor() {
|
||||
super();
|
||||
document.addEventListener("visibilitychange", () => this.sensor_update());
|
||||
window.addEventListener("location-changed", () => this.sensor_update());
|
||||
super();
|
||||
document.addEventListener("visibilitychange", () => this.sensor_update());
|
||||
window.addEventListener("location-changed", () => this.sensor_update());
|
||||
|
||||
window.setInterval(() => this.sensor_update(), 10000);
|
||||
window.setInterval(() => this.sensor_update(), 10000);
|
||||
}
|
||||
|
||||
sensor_update() {
|
||||
const update = async () => {
|
||||
const battery = navigator.getBattery ? await navigator.getBattery() : undefined;
|
||||
this.sendUpdate({browser: {
|
||||
path: window.location.pathname,
|
||||
visibility: document.visibilityState,
|
||||
userAgent: navigator.userAgent,
|
||||
currentUser: this._hass &&this._hass.user && this._hass.user.name,
|
||||
fullyKiosk: this.isFully,
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
battery_level: this.isFully ? window.fully.getBatteryLevel() : battery ? battery.level*100 : undefined,
|
||||
charging: this.isFully ? window.fully.isPlugged() : battery ? battery.charging : undefined,
|
||||
}});
|
||||
};
|
||||
update();
|
||||
const update = async () => {
|
||||
const battery = navigator.getBattery
|
||||
? await navigator.getBattery()
|
||||
: undefined;
|
||||
this.sendUpdate({
|
||||
browser: {
|
||||
path: window.location.pathname,
|
||||
visibility: document.visibilityState,
|
||||
userAgent: navigator.userAgent,
|
||||
currentUser: this._hass && this._hass.user && this._hass.user.name,
|
||||
fullyKiosk: this.isFully,
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
battery_level: this.isFully
|
||||
? window.fully.getBatteryLevel()
|
||||
: battery
|
||||
? battery.level * 100
|
||||
: undefined,
|
||||
charging: this.isFully
|
||||
? window.fully.isPlugged()
|
||||
: battery
|
||||
? battery.charging
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
};
|
||||
update();
|
||||
}
|
||||
|
||||
do_navigate(path) {
|
||||
if (!path) return;
|
||||
history.pushState(null, "", path);
|
||||
fireEvent("location-changed", {}, document.querySelector("home-assistant"));
|
||||
if (!path) return;
|
||||
history.pushState(null, "", path);
|
||||
fireEvent(
|
||||
"location-changed",
|
||||
{},
|
||||
document.querySelector("home-assistant")
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
+43
-32
@@ -1,46 +1,57 @@
|
||||
export const BrowserModCameraMixin = (C) => class extends C {
|
||||
|
||||
export const BrowserModCameraMixin = (C) =>
|
||||
class extends C {
|
||||
setup_camera() {
|
||||
console.log("Starting camera");
|
||||
|
||||
console.log("Starting camera")
|
||||
if (this._video) return;
|
||||
this._video = document.createElement("video");
|
||||
this._video.autoplay = true;
|
||||
this._video.playsInline = true;
|
||||
this._video.style.display = "none";
|
||||
|
||||
if(this._video) return;
|
||||
this._video = document.createElement("video");
|
||||
this._video.autoplay = true;
|
||||
this._video.playsInline = true;
|
||||
this._video.style.display = "none";
|
||||
this._canvas = document.createElement("canvas");
|
||||
this._canvas.style.display = "none";
|
||||
|
||||
this._canvas = document.createElement("canvas");
|
||||
this._canvas.style.display = "none";
|
||||
document.body.appendChild(this._video);
|
||||
document.body.appendChild(this._canvas);
|
||||
|
||||
document.body.appendChild(this._video);
|
||||
document.body.appendChild(this._canvas);
|
||||
if (!navigator.mediaDevices) return;
|
||||
|
||||
if(!navigator.mediaDevices) return;
|
||||
console.log("Starting devices");
|
||||
navigator.mediaDevices
|
||||
.getUserMedia({ video: true, audio: false })
|
||||
.then((stream) => {
|
||||
this._video.srcObject = stream;
|
||||
this._video.play();
|
||||
this.update_camera();
|
||||
});
|
||||
|
||||
console.log("Starting devices")
|
||||
navigator.mediaDevices.getUserMedia({video: true, audio: false}).then((stream) => {
|
||||
this._video.srcObject = stream;
|
||||
this._video.play();
|
||||
this.update_camera();
|
||||
})
|
||||
this._camera_framerate = 2;
|
||||
|
||||
this._camera_framerate = 2;
|
||||
|
||||
window.addEventListener("click", () => this._video.play(), {once: true});
|
||||
window.addEventListener("click", () => this._video.play(), {
|
||||
once: true,
|
||||
});
|
||||
}
|
||||
|
||||
update_camera() {
|
||||
this._canvas.width = this._video.videoWidth;
|
||||
this._canvas.height = this._video.videoHeight;
|
||||
this._canvas.width = this._video.videoWidth;
|
||||
this._canvas.height = this._video.videoHeight;
|
||||
|
||||
const context = this._canvas.getContext('2d');
|
||||
context.drawImage(this._video, 0, 0, this._video.videoWidth, this._video.videoHeight);
|
||||
const context = this._canvas.getContext("2d");
|
||||
context.drawImage(
|
||||
this._video,
|
||||
0,
|
||||
0,
|
||||
this._video.videoWidth,
|
||||
this._video.videoHeight
|
||||
);
|
||||
|
||||
this.sendUpdate({
|
||||
camera: this._canvas.toDataURL('image/jpeg'),
|
||||
});
|
||||
setTimeout(() => this.update_camera(), Math.round(1000 / this._camera_framerate));
|
||||
this.sendUpdate({
|
||||
camera: this._canvas.toDataURL("image/jpeg"),
|
||||
});
|
||||
setTimeout(
|
||||
() => this.update_camera(),
|
||||
Math.round(1000 / this._camera_framerate)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
+37
-41
@@ -1,51 +1,47 @@
|
||||
import { deviceID } from "card-tools/src/deviceId";
|
||||
import { deviceID } from "card-tools/src/deviceID";
|
||||
import { hass, provideHass } from "card-tools/src/hass";
|
||||
|
||||
export class BrowserModConnection{
|
||||
|
||||
async connect() {
|
||||
const isCast = document.querySelector("hc-main") !== null;
|
||||
if(!isCast) {
|
||||
if(!window.hassConnection) {
|
||||
window.setTimeout(() => this.connect(), 100);
|
||||
return;
|
||||
} else {
|
||||
this._connection = (await window.hassConnection).conn;
|
||||
}
|
||||
} else {
|
||||
this._connection = hass().connection;
|
||||
}
|
||||
|
||||
this._connection.subscribeMessage((msg) => this.msg_callback(msg), {
|
||||
type: 'browser_mod/connect',
|
||||
deviceID: deviceID,
|
||||
});
|
||||
|
||||
this._hass_patched = false;
|
||||
provideHass(this);
|
||||
export class BrowserModConnection {
|
||||
async connect() {
|
||||
const isCast = document.querySelector("hc-main") !== null;
|
||||
if (!isCast) {
|
||||
if (!window.hassConnection) {
|
||||
window.setTimeout(() => this.connect(), 100);
|
||||
return;
|
||||
} else {
|
||||
this._connection = (await window.hassConnection).conn;
|
||||
}
|
||||
} else {
|
||||
this._connection = hass().connection;
|
||||
}
|
||||
|
||||
set hass(hass) {
|
||||
this._hass = hass;
|
||||
}
|
||||
this._connection.subscribeMessage((msg) => this.msg_callback(msg), {
|
||||
type: "browser_mod/connect",
|
||||
deviceID: deviceID,
|
||||
});
|
||||
|
||||
get connected() {
|
||||
return this._connection !== undefined;
|
||||
}
|
||||
this._hass_patched = false;
|
||||
provideHass(this);
|
||||
}
|
||||
|
||||
msg_callback(message) {
|
||||
console.log(message);
|
||||
}
|
||||
set hass(hass) {
|
||||
this._hass = hass;
|
||||
}
|
||||
|
||||
sendUpdate(data) {
|
||||
if(!this.connected) return;
|
||||
this._connection.sendMessage({
|
||||
type: 'browser_mod/update',
|
||||
deviceID,
|
||||
data,
|
||||
}
|
||||
)
|
||||
}
|
||||
get connected() {
|
||||
return this._connection !== undefined;
|
||||
}
|
||||
|
||||
msg_callback(message) {
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
sendUpdate(data) {
|
||||
if (!this.connected) return;
|
||||
this._connection.sendMessage({
|
||||
type: "browser_mod/update",
|
||||
deviceID,
|
||||
data,
|
||||
});
|
||||
}
|
||||
}
|
||||
+52
-41
@@ -1,59 +1,70 @@
|
||||
export const FullyKioskMixin = (C) => class extends C {
|
||||
export const FullyKioskMixin = (C) =>
|
||||
class extends C {
|
||||
get isFully() {
|
||||
return window.fully !== undefined;
|
||||
return window.fully !== undefined;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
super();
|
||||
|
||||
if (!this.isFully) return;
|
||||
if (!this.isFully) return;
|
||||
|
||||
this._fullyMotion = false;
|
||||
this._motionTimeout = undefined;
|
||||
this._fullyMotion = false;
|
||||
this._motionTimeout = undefined;
|
||||
|
||||
for (const ev of ["screenOn", "screenOff", "pluggedAC", "pluggedUSB", "onBatteryLevelChanged", "unplugged", "networkReconnect", "onMotion"]) {
|
||||
window.fully.bind(ev, `window.browser_mod.fully_update("${ev}");`);
|
||||
}
|
||||
for (const ev of [
|
||||
"screenOn",
|
||||
"screenOff",
|
||||
"pluggedAC",
|
||||
"pluggedUSB",
|
||||
"onBatteryLevelChanged",
|
||||
"unplugged",
|
||||
"networkReconnect",
|
||||
"onMotion",
|
||||
]) {
|
||||
window.fully.bind(ev, `window.browser_mod.fully_update("${ev}");`);
|
||||
}
|
||||
|
||||
this._keepingAlive = false;
|
||||
this._keepingAlive = false;
|
||||
}
|
||||
|
||||
fully_update(event) {
|
||||
if(!this.isFully) return
|
||||
if(event === "screenOn") {
|
||||
window.clearTimeout(this._keepAliveTimer);
|
||||
if(!this._keepingAlive)
|
||||
this.screen_update();
|
||||
} else if (event === "screenOff") {
|
||||
this.screen_update();
|
||||
this._keepingAlive = false;
|
||||
if(this.config.force_stay_awake) {
|
||||
this._keepAliveTimer = window.setTimeout(() => {
|
||||
this._keepingAlive = true;
|
||||
window.fully.turnScreenOn();
|
||||
window.fully.turnScreenOff();
|
||||
}, 270000);
|
||||
}
|
||||
} else if (event === "onMotion") {
|
||||
this.fullyMotionTriggered();
|
||||
if (!this.isFully) return;
|
||||
if (event === "screenOn") {
|
||||
window.clearTimeout(this._keepAliveTimer);
|
||||
if (!this._keepingAlive) this.screen_update();
|
||||
} else if (event === "screenOff") {
|
||||
this.screen_update();
|
||||
this._keepingAlive = false;
|
||||
if (this.config.force_stay_awake) {
|
||||
this._keepAliveTimer = window.setTimeout(() => {
|
||||
this._keepingAlive = true;
|
||||
window.fully.turnScreenOn();
|
||||
window.fully.turnScreenOff();
|
||||
}, 270000);
|
||||
}
|
||||
} else if (event === "onMotion") {
|
||||
this.fullyMotionTriggered();
|
||||
}
|
||||
|
||||
this.sendUpdate({fully: {
|
||||
battery: window.fully.getBatteryLevel(),
|
||||
charging: window.fully.isPlugged(),
|
||||
motion: this._fullyMotion,
|
||||
ip: window.fully.getIp4Address(),
|
||||
}})
|
||||
this.sendUpdate({
|
||||
fully: {
|
||||
battery: window.fully.getBatteryLevel(),
|
||||
charging: window.fully.isPlugged(),
|
||||
motion: this._fullyMotion,
|
||||
ip: window.fully.getIp4Address(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
fullyMotionTriggered() {
|
||||
if(this._keepingAlive) return;
|
||||
this._fullyMotion = true;
|
||||
clearTimeout(this._motionTimeout);
|
||||
this._motionTimeout = setTimeout(() => {
|
||||
this._fullyMotion = false;
|
||||
this.fully_update();
|
||||
}, 5000);
|
||||
if (this._keepingAlive) return;
|
||||
this._fullyMotion = true;
|
||||
clearTimeout(this._motionTimeout);
|
||||
this._motionTimeout = setTimeout(() => {
|
||||
this._fullyMotion = false;
|
||||
this.fully_update();
|
||||
}, 5000);
|
||||
this.fully_update();
|
||||
}
|
||||
}
|
||||
};
|
||||
+48
-43
@@ -1,4 +1,4 @@
|
||||
import { deviceID } from "card-tools/src/deviceId";
|
||||
import { deviceID } from "card-tools/src/deviceID";
|
||||
import { lovelace_view } from "card-tools/src/hass";
|
||||
import { popUp } from "card-tools/src/popup";
|
||||
import { fireEvent } from "card-tools/src/event";
|
||||
@@ -12,7 +12,6 @@ import { BrowserModScreensaverMixin } from "./screensaver";
|
||||
import { BrowserModPopupsMixin } from "./popups";
|
||||
import { BrowserModBrowserMixin } from "./browser";
|
||||
|
||||
|
||||
const ext = (baseClass, mixins) =>
|
||||
mixins.reduceRight((base, mixin) => mixin(base), baseClass);
|
||||
|
||||
@@ -23,9 +22,7 @@ class BrowserMod extends ext(BrowserModConnection, [
|
||||
BrowserModCameraMixin,
|
||||
FullyKioskMixin,
|
||||
BrowserModMediaPlayerMixin,
|
||||
]) {
|
||||
|
||||
|
||||
]) {
|
||||
constructor() {
|
||||
super();
|
||||
this.entity_id = deviceID.replace("-", "_");
|
||||
@@ -33,15 +30,18 @@ class BrowserMod extends ext(BrowserModConnection, [
|
||||
this.connect();
|
||||
|
||||
document.body.addEventListener("ll-custom", (ev) => {
|
||||
if(ev.detail.browser_mod) {
|
||||
if (ev.detail.browser_mod) {
|
||||
this.msg_callback(ev.detail.browser_mod);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const pjson = require('../package.json');
|
||||
console.info(`%cBROWSER_MOD ${pjson.version} IS INSTALLED
|
||||
const pjson = require("../package.json");
|
||||
console.info(
|
||||
`%cBROWSER_MOD ${pjson.version} IS INSTALLED
|
||||
%cDeviceID: ${deviceID}`,
|
||||
"color: green; font-weight: bold", "");
|
||||
"color: green; font-weight: bold",
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
async msg_callback(msg) {
|
||||
@@ -65,83 +65,88 @@ class BrowserMod extends ext(BrowserModConnection, [
|
||||
"lovelace-reload": (msg) => this.lovelace_reload(msg),
|
||||
"window-reload": () => window.location.reload(),
|
||||
|
||||
blackout: (msg) => this.do_blackout(msg.time ? parseInt(msg.time) : undefined),
|
||||
blackout: (msg) =>
|
||||
this.do_blackout(msg.time ? parseInt(msg.time) : undefined),
|
||||
"no-blackout": (msg) => {
|
||||
if(msg.brightness && this.isFully) {
|
||||
if (msg.brightness && this.isFully) {
|
||||
window.fully.setScreenBrightness(msg.brightness);
|
||||
}
|
||||
this.no_blackout()
|
||||
this.no_blackout();
|
||||
},
|
||||
|
||||
"call-service": (msg) => this.call_service(msg),
|
||||
"commands": async (msg) => {
|
||||
for(const m of msg.commands) {
|
||||
commands: async (msg) => {
|
||||
for (const m of msg.commands) {
|
||||
await this.msg_callback(m);
|
||||
}
|
||||
},
|
||||
"delay": async (msg) => await new Promise((resolve) => {window.setTimeout(resolve, msg.seconds*1000)}),
|
||||
delay: async (msg) =>
|
||||
await new Promise((resolve) => {
|
||||
window.setTimeout(resolve, msg.seconds * 1000);
|
||||
}),
|
||||
};
|
||||
|
||||
await handlers[msg.command.replace("_","-")](msg);
|
||||
await handlers[msg.command.replace("_", "-")](msg);
|
||||
}
|
||||
|
||||
debug(msg) {
|
||||
popUp(`deviceID`, {type: "markdown", content: `# ${deviceID}`})
|
||||
popUp(`deviceID`, { type: "markdown", content: `# ${deviceID}` });
|
||||
alert(deviceID);
|
||||
}
|
||||
|
||||
set_theme(msg){
|
||||
if(!msg.theme) msg.theme = "default";
|
||||
fireEvent("settheme", {theme: msg.theme}, document.querySelector("home-assistant"));
|
||||
set_theme(msg) {
|
||||
if (!msg.theme) msg.theme = "default";
|
||||
fireEvent(
|
||||
"settheme",
|
||||
{ theme: msg.theme },
|
||||
document.querySelector("home-assistant")
|
||||
);
|
||||
}
|
||||
|
||||
lovelace_reload(msg) {
|
||||
const ll = lovelace_view();
|
||||
if (ll)
|
||||
fireEvent("config-refresh", {}, ll);
|
||||
if (ll) fireEvent("config-refresh", {}, ll);
|
||||
}
|
||||
|
||||
call_service(msg) {
|
||||
const _replaceThis = (data) => {
|
||||
if (typeof(data) === "string" && data === "this")
|
||||
return deviceID;
|
||||
if (Array.isArray(data))
|
||||
return data.map(_replaceThis);
|
||||
if (typeof data === "string" && data === "this") return deviceID;
|
||||
if (Array.isArray(data)) return data.map(_replaceThis);
|
||||
if (data.constructor == Object) {
|
||||
for (const key in data)
|
||||
data[key] = _replaceThis(data[key]);
|
||||
for (const key in data) data[key] = _replaceThis(data[key]);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
const [domain, service] = msg.service.split(".", 2);
|
||||
let service_data = _replaceThis(JSON.parse(JSON.stringify(msg.service_data)));
|
||||
};
|
||||
const [domain, service] = msg.service.split(".", 2);
|
||||
let service_data = _replaceThis(
|
||||
JSON.parse(JSON.stringify(msg.service_data))
|
||||
);
|
||||
this._hass.callService(domain, service, service_data);
|
||||
}
|
||||
|
||||
update(msg=null) {
|
||||
if(msg) {
|
||||
if(msg.name) {
|
||||
update(msg = null) {
|
||||
if (msg) {
|
||||
if (msg.name) {
|
||||
this.entity_id = msg.name.toLowerCase();
|
||||
}
|
||||
if(msg.camera) {
|
||||
if (msg.camera) {
|
||||
this.setup_camera();
|
||||
}
|
||||
this.config = {...this.config, ...msg};
|
||||
this.config = { ...this.config, ...msg };
|
||||
}
|
||||
this.player_update();
|
||||
this.fully_update();
|
||||
this.screen_update();
|
||||
this.sensor_update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
const bases = [customElements.whenDefined('home-assistant'), customElements.whenDefined('hc-main')];
|
||||
const bases = [
|
||||
customElements.whenDefined("home-assistant"),
|
||||
customElements.whenDefined("hc-main"),
|
||||
];
|
||||
Promise.race(bases).then(() => {
|
||||
window.setTimeout(() => {
|
||||
window.browser_mod = window.browser_mod || new BrowserMod();
|
||||
},
|
||||
1000
|
||||
);
|
||||
}, 1000);
|
||||
});
|
||||
+32
-30
@@ -1,51 +1,53 @@
|
||||
export const BrowserModMediaPlayerMixin = (C) => class extends C {
|
||||
|
||||
export const BrowserModMediaPlayerMixin = (C) =>
|
||||
class extends C {
|
||||
constructor() {
|
||||
super();
|
||||
this.player = new Audio();
|
||||
super();
|
||||
this.player = new Audio();
|
||||
|
||||
for (const event of ["play", "pause", "ended", "volumechange"]) {
|
||||
this.player.addEventListener(event, () => this.player_update());
|
||||
}
|
||||
for (const event of ["play", "pause", "ended", "volumechange"]) {
|
||||
this.player.addEventListener(event, () => this.player_update());
|
||||
}
|
||||
|
||||
window.addEventListener("click", () => this.player.play(), {once: true});
|
||||
window.addEventListener("click", () => this.player.play(), {
|
||||
once: true,
|
||||
});
|
||||
}
|
||||
|
||||
player_update(ev) {
|
||||
this.sendUpdate({player: {
|
||||
volume: this.player.volume,
|
||||
muted: this.player.muted,
|
||||
src: this.player.src,
|
||||
state: this.player_state,
|
||||
}})
|
||||
this.sendUpdate({
|
||||
player: {
|
||||
volume: this.player.volume,
|
||||
muted: this.player.muted,
|
||||
src: this.player.src,
|
||||
state: this.player_state,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
get player_state() {
|
||||
if (!this.player.src) return "stopped";
|
||||
if (this.player.ended) return "stopped";
|
||||
if (this.player.paused) return "paused";
|
||||
return "playing";
|
||||
if (!this.player.src) return "stopped";
|
||||
if (this.player.ended) return "stopped";
|
||||
if (this.player.paused) return "paused";
|
||||
return "playing";
|
||||
}
|
||||
|
||||
player_play(src) {
|
||||
if(src)
|
||||
this.player.src = src;
|
||||
this.player.play();
|
||||
if (src) this.player.src = src;
|
||||
this.player.play();
|
||||
}
|
||||
player_pause() {
|
||||
this.player.pause();
|
||||
this.player.pause();
|
||||
}
|
||||
player_stop() {
|
||||
this.player.pause();
|
||||
this.player.src = null;
|
||||
this.player.pause();
|
||||
this.player.src = null;
|
||||
}
|
||||
player_set_volume(level) {
|
||||
if(level === undefined) return;
|
||||
this.player.volume = level;
|
||||
if (level === undefined) return;
|
||||
this.player.volume = level;
|
||||
}
|
||||
player_mute(mute) {
|
||||
if(mute === undefined)
|
||||
mute = !this.player.muted;
|
||||
this.player.muted = Boolean(mute);
|
||||
if (mute === undefined) mute = !this.player.muted;
|
||||
this.player.muted = Boolean(mute);
|
||||
}
|
||||
}
|
||||
};
|
||||
+62
-52
@@ -3,77 +3,87 @@ import { load_lovelace, lovelace } from "card-tools/src/hass";
|
||||
import { moreInfo } from "card-tools/src/more-info";
|
||||
import { closePopUp, popUp } from "card-tools/src/popup";
|
||||
|
||||
export const BrowserModPopupsMixin = (C) => class extends C {
|
||||
|
||||
export const BrowserModPopupsMixin = (C) =>
|
||||
class extends C {
|
||||
constructor() {
|
||||
super();
|
||||
if (document.querySelector("home-assistant"))
|
||||
document.querySelector("home-assistant").addEventListener("hass-more-info", (ev) => this._popup_card(ev));
|
||||
super();
|
||||
if (document.querySelector("home-assistant"))
|
||||
document
|
||||
.querySelector("home-assistant")
|
||||
.addEventListener("hass-more-info", (ev) => this._popup_card(ev));
|
||||
|
||||
const isCast = document.querySelector("hc-main") !== null;
|
||||
if(!isCast)
|
||||
load_lovelace();
|
||||
const isCast = document.querySelector("hc-main") !== null;
|
||||
if (!isCast) load_lovelace();
|
||||
}
|
||||
|
||||
_popup_card(ev) {
|
||||
if(!lovelace()) return;
|
||||
if(!ev.detail || !ev.detail.entityId) return;
|
||||
const data = {
|
||||
...lovelace().config.popup_cards,
|
||||
...lovelace().config.views[lovelace().current_view].popup_cards,
|
||||
};
|
||||
const d = data[ev.detail.entityId];
|
||||
if(!d) return;
|
||||
if (!lovelace()) return;
|
||||
if (!ev.detail || !ev.detail.entityId) return;
|
||||
const data = {
|
||||
...lovelace().config.popup_cards,
|
||||
...lovelace().config.views[lovelace().current_view].popup_cards,
|
||||
};
|
||||
const d = data[ev.detail.entityId];
|
||||
if (!d) return;
|
||||
|
||||
popUp(
|
||||
d.title,
|
||||
d.card,
|
||||
d.large || false,
|
||||
d.style
|
||||
this.do_popup(d);
|
||||
window.setTimeout(() => {
|
||||
fireEvent(
|
||||
"hass-more-info",
|
||||
{ entityID: "." },
|
||||
document.querySelector("home-assistant")
|
||||
);
|
||||
window.setTimeout(() => {
|
||||
fireEvent("hass-more-info", {entityID: "."}, document.querySelector("home-assistant"));
|
||||
}, 50);
|
||||
}, 50);
|
||||
}
|
||||
|
||||
do_popup(cfg) {
|
||||
if (!(cfg.title || cfg.auto_close || cfg.hide_header)) return;
|
||||
if (!cfg.card) return;
|
||||
if (!(cfg.title || cfg.auto_close || cfg.hide_header)) {
|
||||
console.error(
|
||||
"browser_mod: popup: Must specify title, auto_close or hide_header."
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!cfg.card) {
|
||||
console.error("browser_mod: popup: No card specified");
|
||||
return;
|
||||
}
|
||||
|
||||
const open = () => {
|
||||
popUp(
|
||||
cfg.title,
|
||||
cfg.card,
|
||||
cfg.large,
|
||||
cfg.style,
|
||||
cfg.auto_close || cfg.hide_header,
|
||||
);
|
||||
};
|
||||
const open = () => {
|
||||
popUp(
|
||||
cfg.title,
|
||||
cfg.card,
|
||||
cfg.large,
|
||||
cfg.style,
|
||||
cfg.auto_close || cfg.hide_header
|
||||
);
|
||||
};
|
||||
|
||||
if(cfg.auto_close) {
|
||||
this.screensaver_set(open, closePopUp, cfg.time);
|
||||
} else {
|
||||
open();
|
||||
}
|
||||
if (cfg.auto_close) {
|
||||
this.screensaver_set(open, closePopUp, cfg.time);
|
||||
} else {
|
||||
open();
|
||||
}
|
||||
}
|
||||
|
||||
do_close_popup() {
|
||||
this.screensaver_stop();
|
||||
closePopUp();
|
||||
this.screensaver_stop();
|
||||
closePopUp();
|
||||
}
|
||||
|
||||
do_more_info(entity_id, large) {
|
||||
if (!entity_id) return;
|
||||
moreInfo(entity_id, large);
|
||||
if (!entity_id) return;
|
||||
moreInfo(entity_id, large);
|
||||
}
|
||||
|
||||
do_toast(message, duration) {
|
||||
if (!message) return;
|
||||
fireEvent("hass-notification", {
|
||||
message,
|
||||
duration: parseInt(duration),
|
||||
}, document.querySelector("home-assistant"));
|
||||
if (!message) return;
|
||||
fireEvent(
|
||||
"hass-notification",
|
||||
{
|
||||
message,
|
||||
duration: parseInt(duration),
|
||||
},
|
||||
document.querySelector("home-assistant")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
+88
-82
@@ -1,22 +1,23 @@
|
||||
export const BrowserModScreensaverMixin = (C) => class extends C {
|
||||
export const BrowserModScreensaverMixin = (C) =>
|
||||
class extends C {
|
||||
constructor() {
|
||||
super();
|
||||
this._blackout_panel = document.createElement("div");
|
||||
super();
|
||||
this._blackout_panel = document.createElement("div");
|
||||
|
||||
this._screenSaver = undefined;
|
||||
this._screenSaverTimer = undefined;
|
||||
this._screenSaverTimeOut = 0;
|
||||
this._screenSaver = undefined;
|
||||
this._screenSaverTimer = undefined;
|
||||
this._screenSaverTimeOut = 0;
|
||||
|
||||
this._screenSaver = {
|
||||
fn: undefined,
|
||||
clearfn: undefined,
|
||||
timer: undefined,
|
||||
timeout: undefined,
|
||||
listeners : {},
|
||||
active: false,
|
||||
};
|
||||
this._screenSaver = {
|
||||
fn: undefined,
|
||||
clearfn: undefined,
|
||||
timer: undefined,
|
||||
timeout: undefined,
|
||||
listeners: {},
|
||||
active: false,
|
||||
};
|
||||
|
||||
this._blackout_panel.style.cssText = `
|
||||
this._blackout_panel.style.cssText = `
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
@@ -27,95 +28,100 @@ export const BrowserModScreensaverMixin = (C) => class extends C {
|
||||
background: black;
|
||||
display: none;
|
||||
`;
|
||||
document.body.appendChild(this._blackout_panel);
|
||||
|
||||
document.body.appendChild(this._blackout_panel);
|
||||
}
|
||||
|
||||
screensaver_set(fn, clearfn, time) {
|
||||
this._ss_clear();
|
||||
this._screenSaver = {
|
||||
fn,
|
||||
clearfn,
|
||||
timer: undefined,
|
||||
timeout: time,
|
||||
listeners: {},
|
||||
active: false,
|
||||
}
|
||||
const l = () => this.screensaver_update();
|
||||
for(const event of ["mousemove", "mousedown", "keydown", "touchstart"]) {
|
||||
window.addEventListener(event, l);
|
||||
this._screenSaver.listeners[event] = l;
|
||||
}
|
||||
this._screenSaver.timer = window.setTimeout(() => this._ss_run(), time*1000);
|
||||
this._ss_clear();
|
||||
this._screenSaver = {
|
||||
fn,
|
||||
clearfn,
|
||||
timer: undefined,
|
||||
timeout: time,
|
||||
listeners: {},
|
||||
active: false,
|
||||
};
|
||||
const l = () => this.screensaver_update();
|
||||
for (const event of ["mousemove", "mousedown", "keydown", "touchstart"]) {
|
||||
window.addEventListener(event, l);
|
||||
this._screenSaver.listeners[event] = l;
|
||||
}
|
||||
this._screenSaver.timer = window.setTimeout(
|
||||
() => this._ss_run(),
|
||||
time * 1000
|
||||
);
|
||||
}
|
||||
|
||||
screensaver_update() {
|
||||
if (this._screenSaver.active) {
|
||||
this.screensaver_stop();
|
||||
} else {
|
||||
window.clearTimeout(this._screenSaver.timer);
|
||||
this._screenSaver.timer = window.setTimeout(() => this._ss_run(), this._screenSaver.timeout*1000);
|
||||
}
|
||||
if (this._screenSaver.active) {
|
||||
this.screensaver_stop();
|
||||
} else {
|
||||
window.clearTimeout(this._screenSaver.timer);
|
||||
this._screenSaver.timer = window.setTimeout(
|
||||
() => this._ss_run(),
|
||||
this._screenSaver.timeout * 1000
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
screensaver_stop() {
|
||||
this._ss_clear();
|
||||
this._screenSaver.active = false;
|
||||
if(this._screenSaver.clearfn)
|
||||
this._screenSaver.clearfn();
|
||||
if(this._screenSaver.timeout) {
|
||||
this.screensaver_set(
|
||||
this._screenSaver.fn,
|
||||
this._screenSaver.clearfn,
|
||||
this._screenSaver.timeout,
|
||||
);
|
||||
}
|
||||
this._ss_clear();
|
||||
this._screenSaver.active = false;
|
||||
if (this._screenSaver.clearfn) this._screenSaver.clearfn();
|
||||
if (this._screenSaver.timeout) {
|
||||
this.screensaver_set(
|
||||
this._screenSaver.fn,
|
||||
this._screenSaver.clearfn,
|
||||
this._screenSaver.timeout
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_ss_clear() {
|
||||
window.clearTimeout(this._screenSaverTimer);
|
||||
for(const [k, v] of Object.entries(this._screenSaver.listeners)) {
|
||||
window.removeEventListener(k, v);
|
||||
}
|
||||
window.clearTimeout(this._screenSaverTimer);
|
||||
for (const [k, v] of Object.entries(this._screenSaver.listeners)) {
|
||||
window.removeEventListener(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
_ss_run() {
|
||||
this._screenSaver.active = true;
|
||||
this._screenSaver.fn();
|
||||
this._screenSaver.active = true;
|
||||
this._screenSaver.fn();
|
||||
}
|
||||
|
||||
do_blackout(timeout) {
|
||||
this.screensaver_set(
|
||||
() => {
|
||||
if(this.isFully)
|
||||
window.fully.turnScreenOff(true);
|
||||
else
|
||||
this._blackout_panel.style.display = "block";
|
||||
this.screen_update();
|
||||
},
|
||||
() => {
|
||||
if(this._blackout_panel.style.display = "block")
|
||||
this._blackout_panel.style.display = "none"
|
||||
if(this.isFully && !window.fully.getScreenOn())
|
||||
window.fully.turnScreenOn();
|
||||
this.screen_update();
|
||||
},
|
||||
timeout || 0
|
||||
);
|
||||
this.screensaver_set(
|
||||
() => {
|
||||
if (this.isFully) window.fully.turnScreenOff(true);
|
||||
else this._blackout_panel.style.display = "block";
|
||||
this.screen_update();
|
||||
},
|
||||
() => {
|
||||
if ((this._blackout_panel.style.display = "block"))
|
||||
this._blackout_panel.style.display = "none";
|
||||
if (this.isFully && !window.fully.getScreenOn())
|
||||
window.fully.turnScreenOn();
|
||||
this.screen_update();
|
||||
},
|
||||
timeout || 0
|
||||
);
|
||||
}
|
||||
|
||||
no_blackout() {
|
||||
if(this.isFully)
|
||||
window.fully.turnScreenOn();
|
||||
this.screensaver_stop();
|
||||
if (this.isFully) window.fully.turnScreenOn();
|
||||
this.screensaver_stop();
|
||||
}
|
||||
|
||||
screen_update() {
|
||||
this.sendUpdate({screen: {
|
||||
blackout: this.isFully
|
||||
? !window.fully.getScreenOn()
|
||||
: Boolean(this._blackout_panel.style.display === "block"),
|
||||
brightness: this.isFully ? window.fully.getScreenBrightness() : undefined,
|
||||
}})
|
||||
this.sendUpdate({
|
||||
screen: {
|
||||
blackout: this.isFully
|
||||
? !window.fully.getScreenOn()
|
||||
: Boolean(this._blackout_panel.style.display === "block"),
|
||||
brightness: this.isFully
|
||||
? window.fully.getScreenBrightness()
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
Generated
+526
-3119
File diff suppressed because it is too large.
Load diff
+2
-2
@@ -12,8 +12,8 @@
|
||||
"author": "Thomas Lovén",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"webpack": "^4.46.0",
|
||||
"webpack-cli": "^3.3.12"
|
||||
"webpack": "^5.36.2",
|
||||
"webpack-cli": "^4.7.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"card-tools": "github:thomasloven/lovelace-card-tools"
|
||||
|
||||
@@ -45,6 +45,8 @@ views:
|
||||
card:
|
||||
type: markdown
|
||||
content: Local popup for climate.hvac
|
||||
light.kitchen_lights:
|
||||
type: No card
|
||||
|
||||
cards:
|
||||
- type: button
|
||||
@@ -57,3 +59,8 @@ views:
|
||||
name: Override global popup-card
|
||||
tap_action:
|
||||
action: more-info
|
||||
- type: button
|
||||
entity: light.kitchen_lights
|
||||
name: No card config
|
||||
tap_action:
|
||||
action: more-info
|
||||
Reference in new issue
Block a user