Skip to content

Commit

Permalink
Fixes for iOS and FKB
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Oct 24, 2020
1 parent d25c2e9 commit 7d17efd
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 44 deletions.
20 changes: 10 additions & 10 deletions custom_components/browser_mod/browser_mod.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions custom_components/browser_mod/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def supported_features(self):
return SUPPORT_BRIGHTNESS
return 0

@property
def brightness(self):
return self.data.get('brightness', None)

def turn_on(self, **kwargs):
self.connection.send("no-blackout", **kwargs)

Expand Down
31 changes: 20 additions & 11 deletions js/browser-player.js
Original file line number Diff line number Diff line change
@@ -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 "./browser-player-editor.js"

Expand Down Expand Up @@ -28,22 +28,31 @@ class BrowserPlayer extends LitElement {

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.mute({});
window.browser_mod.player_mute();
}
handleVolumeChange(ev) {
const vol = parseFloat(ev.target.value);
window.browser_mod.set_volume({volume_level: vol});
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.play({});
window.browser_mod.player_play();
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() {
Expand Down Expand Up @@ -74,22 +83,22 @@ class BrowserPlayer extends LitElement {
${window.browser_mod.player_state === "stopped"
? html`<div class="placeholder"></div>`
: html`
<paper-icon-button
<ha-icon-button
.icon=${player.paused
? "mdi:play"
: "mdi:pause"
}
@click=${this.handlePlayPause}
highlight
></paper-icon-button>
></ha-icon-button>
`}
<paper-icon-button
.icon=${"mdi:settings"}
<ha-icon-button
.icon=${"mdi:cog"}
@click=${this.handleMoreInfo}
></paper-icon-button>
></ha-icon-button>
</div>
<div class="device-id">
<div class="device-id" @click=${this.setDeviceID}>
${deviceID}
</div>
Expand Down
23 changes: 14 additions & 9 deletions js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ export const BrowserModBrowserMixin = (C) => class extends C {
}

sensor_update() {
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,
}});
window.queueMicrotask( 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: this.isFully ? window.fully.getBatteryLevel() : battery ? battery.level*100 : undefined,
charging: this.isFully ? window.fully.isPlugged() : battery ? battery.charging : undefined,
}});
});
}

do_navigate(path) {
Expand Down
6 changes: 3 additions & 3 deletions js/fullyKiosk.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export const FullyKioskMixin = (C) => class extends C {
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() {
if(!this.isFully) return
this.sendUpdate({fully: {
battery: fully.getBatteryLevel(),
charging: fully.isPlugged(),
battery: window.fully.getBatteryLevel(),
charging: window.fully.isPlugged(),
motion: this._fullyMotion,
}})
}
Expand Down
21 changes: 12 additions & 9 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ import { BrowserModScreensaverMixin } from "./screensaver";
import { BrowserModPopupsMixin } from "./popups";
import { BrowserModBrowserMixin } from "./browser";

class BrowserMod extends
BrowserModBrowserMixin(
BrowserModPopupsMixin(
BrowserModScreensaverMixin(
BrowserModCameraMixin(
FullyKioskMixin(
BrowserModMediaPlayerMixin(
BrowserModConnection
)))))) {

const ext = (baseClass, mixins) =>
mixins.reduceRight((base, mixin) => mixin(base), baseClass);

class BrowserMod extends ext(BrowserModConnection, [
BrowserModBrowserMixin,
BrowserModPopupsMixin,
BrowserModScreensaverMixin,
BrowserModCameraMixin,
FullyKioskMixin,
BrowserModMediaPlayerMixin,
]) {


constructor() {
Expand Down
2 changes: 1 addition & 1 deletion js/popups.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const BrowserModPopupsMixin = (C) => class extends C {
}

_popup_card(ev) {
if(!lovelace) return;
if(!lovelace()) return;
if(!ev.detail || !ev.detail.entityId) return;
const data = {
...lovelace().config.popup_cards,
Expand Down
7 changes: 6 additions & 1 deletion js/screensaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export const BrowserModScreensaverMixin = (C) => class extends C {
display: none;
`;
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) {
Expand Down Expand Up @@ -110,7 +115,7 @@ export const BrowserModScreensaverMixin = (C) => class extends C {
screen_update() {
this.sendUpdate({screen: {
blackout: this.isFully
? window.fully.getScreenOn()
? !window.fully.getScreenOn()
: Boolean(this._blackout_panel.style.display === "block"),
brightness: this.isFully ? window.fully.getScreenBrightness() : undefined,
}})
Expand Down
1 change: 1 addition & 0 deletions test/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ browser_mod:
testdevice:
alias: test


lovelace:
mode: yaml
resources:
Expand Down

0 comments on commit 7d17efd

Please sign in to comment.