Fixes for iOS and FKB

This commit is contained in:
Thomas Lovén 2020-10-24 22:54:08 +02:00
parent d25c2e9767
commit 7d17efd961
9 changed files with 71 additions and 44 deletions

File diff suppressed because one or more lines are too long

View File

@ -48,6 +48,10 @@ class BrowserModLight(LightEntity, BrowserModEntity):
return SUPPORT_BRIGHTNESS return SUPPORT_BRIGHTNESS
return 0 return 0
@property
def brightness(self):
return self.data.get('brightness', None)
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
self.connection.send("no-blackout", **kwargs) self.connection.send("no-blackout", **kwargs)

View File

@ -1,4 +1,4 @@
import { deviceID } from "card-tools/src/deviceId" import { deviceID, setDeviceID } from "card-tools/src/deviceId"
import { moreInfo } from "card-tools/src/more-info" import { moreInfo } from "card-tools/src/more-info"
import "./browser-player-editor.js" import "./browser-player-editor.js"
@ -28,22 +28,31 @@ class BrowserPlayer extends LitElement {
setConfig(config) { setConfig(config) {
this._config = config; this._config = config;
for (const event of ["play", "pause", "ended", "volumechange", "canplay", "loadeddata"])
window.browser_mod.player.addEventListener(event, () => this.requestUpdate());
} }
handleMute(ev) { handleMute(ev) {
window.browser_mod.mute({}); window.browser_mod.player_mute();
} }
handleVolumeChange(ev) { handleVolumeChange(ev) {
const vol = parseFloat(ev.target.value); const vol = parseFloat(ev.target.value);
window.browser_mod.set_volume({volume_level: vol}); window.browser_mod.player_set_volume(vol);
} }
handleMoreInfo(ev) { handleMoreInfo(ev) {
moreInfo("media_player."+window.browser_mod.entity_id); moreInfo("media_player."+window.browser_mod.entity_id);
} }
handlePlayPause(ev) { handlePlayPause(ev) {
if (window.browser_mod.player.paused) if (window.browser_mod.player.paused)
window.browser_mod.play({}); window.browser_mod.player_play();
else else
window.browser_mod.pause({}); window.browser_mod.player_pause();
}
setDeviceID() {
const newID = prompt("Set deviceID", deviceID);
if (newID !== deviceID) {
setDeviceID(newID);
this.requestUpdate();
}
} }
render() { render() {
@ -74,22 +83,22 @@ class BrowserPlayer extends LitElement {
${window.browser_mod.player_state === "stopped" ${window.browser_mod.player_state === "stopped"
? html`<div class="placeholder"></div>` ? html`<div class="placeholder"></div>`
: html` : html`
<paper-icon-button <ha-icon-button
.icon=${player.paused .icon=${player.paused
? "mdi:play" ? "mdi:play"
: "mdi:pause" : "mdi:pause"
} }
@click=${this.handlePlayPause} @click=${this.handlePlayPause}
highlight highlight
></paper-icon-button> ></ha-icon-button>
`} `}
<paper-icon-button <ha-icon-button
.icon=${"mdi:settings"} .icon=${"mdi:cog"}
@click=${this.handleMoreInfo} @click=${this.handleMoreInfo}
></paper-icon-button> ></ha-icon-button>
</div> </div>
<div class="device-id"> <div class="device-id" @click=${this.setDeviceID}>
${deviceID} ${deviceID}
</div> </div>

View File

@ -11,6 +11,8 @@ export const BrowserModBrowserMixin = (C) => class extends C {
} }
sensor_update() { sensor_update() {
window.queueMicrotask( async () => {
const battery = navigator.getBattery ? await navigator.getBattery() : undefined;
this.sendUpdate({browser: { this.sendUpdate({browser: {
path: window.location.pathname, path: window.location.pathname,
visibility: document.visibilityState, visibility: document.visibilityState,
@ -19,7 +21,10 @@ export const BrowserModBrowserMixin = (C) => class extends C {
fullyKiosk: this.isFully, fullyKiosk: this.isFully,
width: window.innerWidth, width: window.innerWidth,
height: window.innerHeight, height: window.innerHeight,
battery: this.isFully ? window.fully.getBatteryLevel() : battery ? battery.level*100 : undefined,
charging: this.isFully ? window.fully.isPlugged() : battery ? battery.charging : undefined,
}}); }});
});
} }
do_navigate(path) { do_navigate(path) {

View File

@ -15,14 +15,14 @@ export const FullyKioskMixin = (C) => class extends C {
fully.bind(event, "window.browser_mod.fully_update();"); fully.bind(event, "window.browser_mod.fully_update();");
} }
fully.bind("onMotion", "window.browser_mod.fullyMotionTriggered();"); window.fully.bind("onMotion", "window.browser_mod.fullyMotionTriggered();");
} }
fully_update() { fully_update() {
if(!this.isFully) return if(!this.isFully) return
this.sendUpdate({fully: { this.sendUpdate({fully: {
battery: fully.getBatteryLevel(), battery: window.fully.getBatteryLevel(),
charging: fully.isPlugged(), charging: window.fully.isPlugged(),
motion: this._fullyMotion, motion: this._fullyMotion,
}}) }})
} }

View File

@ -12,15 +12,18 @@ import { BrowserModScreensaverMixin } from "./screensaver";
import { BrowserModPopupsMixin } from "./popups"; import { BrowserModPopupsMixin } from "./popups";
import { BrowserModBrowserMixin } from "./browser"; import { BrowserModBrowserMixin } from "./browser";
class BrowserMod extends
BrowserModBrowserMixin( const ext = (baseClass, mixins) =>
BrowserModPopupsMixin( mixins.reduceRight((base, mixin) => mixin(base), baseClass);
BrowserModScreensaverMixin(
BrowserModCameraMixin( class BrowserMod extends ext(BrowserModConnection, [
FullyKioskMixin( BrowserModBrowserMixin,
BrowserModMediaPlayerMixin( BrowserModPopupsMixin,
BrowserModConnection BrowserModScreensaverMixin,
)))))) { BrowserModCameraMixin,
FullyKioskMixin,
BrowserModMediaPlayerMixin,
]) {
constructor() { constructor() {

View File

@ -16,7 +16,7 @@ export const BrowserModPopupsMixin = (C) => class extends C {
} }
_popup_card(ev) { _popup_card(ev) {
if(!lovelace) return; if(!lovelace()) return;
if(!ev.detail || !ev.detail.entityId) return; if(!ev.detail || !ev.detail.entityId) return;
const data = { const data = {
...lovelace().config.popup_cards, ...lovelace().config.popup_cards,

View File

@ -28,6 +28,11 @@ export const BrowserModScreensaverMixin = (C) => class extends C {
display: none; display: none;
`; `;
document.body.appendChild(this._blackout_panel); document.body.appendChild(this._blackout_panel);
if(this.isFully) {
window.fully.bind("screenOn", "window.browser_mod.screen_update();");
window.fully.bind("screenOff", "window.browser_mod.screen_update();");
}
} }
screensaver_set(fn, clearfn, time) { screensaver_set(fn, clearfn, time) {
@ -110,7 +115,7 @@ export const BrowserModScreensaverMixin = (C) => class extends C {
screen_update() { screen_update() {
this.sendUpdate({screen: { this.sendUpdate({screen: {
blackout: this.isFully blackout: this.isFully
? window.fully.getScreenOn() ? !window.fully.getScreenOn()
: Boolean(this._blackout_panel.style.display === "block"), : Boolean(this._blackout_panel.style.display === "block"),
brightness: this.isFully ? window.fully.getScreenBrightness() : undefined, brightness: this.isFully ? window.fully.getScreenBrightness() : undefined,
}}) }})

View File

@ -9,6 +9,7 @@ browser_mod:
testdevice: testdevice:
alias: test alias: test
lovelace: lovelace:
mode: yaml mode: yaml
resources: resources: