Compare commits
No commits in common. "6e5a1c18a3b5f3a9f79697a3f84d845c60dda2f1" and "1dddaa9bcca470f57768c39e37822dda3c4e74ab" have entirely different histories.
6e5a1c18a3
...
1dddaa9bcc
@ -1,6 +1,6 @@
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
|
||||
from .const import DOMAIN, DATA_ADDERS
|
||||
from .const import DATA_BROWSERS, DOMAIN, DATA_ADDERS
|
||||
from .entities import BrowserModEntity
|
||||
|
||||
|
||||
@ -15,14 +15,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
|
||||
|
||||
class BrowserBinarySensor(BrowserModEntity, BinarySensorEntity):
|
||||
def __init__(self, coordinator, browserID, parameter, name, icon=None):
|
||||
BrowserModEntity.__init__(self, coordinator, browserID, name, icon)
|
||||
def __init__(self, coordinator, browserID, parameter, name):
|
||||
BrowserModEntity.__init__(self, coordinator, browserID, name)
|
||||
BinarySensorEntity.__init__(self)
|
||||
self.parameter = parameter
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
return self._data.get("browser", {}).get(self.parameter, None)
|
||||
return self._data.get(DATA_BROWSERS, {}).get(self.parameter, None)
|
||||
|
||||
|
||||
class ActivityBinarySensor(BrowserModEntity, BinarySensorEntity):
|
||||
|
@ -57,50 +57,33 @@ class BrowserModBrowser:
|
||||
coordinator = self.coordinator
|
||||
browserID = self.browserID
|
||||
|
||||
def _assert_browser_sensor(type, name, *properties, **kwarg):
|
||||
def _assert_browser_sensor(type, name, *properties):
|
||||
"""Create a browser state sensor if it does not already exist"""
|
||||
if name in self.entities:
|
||||
return
|
||||
adder = hass.data[DOMAIN][DATA_ADDERS][type]
|
||||
cls = {"sensor": BrowserSensor, "binary_sensor": BrowserBinarySensor}[type]
|
||||
new = cls(coordinator, browserID, name, *properties, **kwarg)
|
||||
new = cls(coordinator, browserID, name, *properties)
|
||||
adder([new])
|
||||
self.entities[name] = new
|
||||
|
||||
_assert_browser_sensor("sensor", "path", "Browser path", icon="mdi:web")
|
||||
_assert_browser_sensor("sensor", "path", "Browser path")
|
||||
_assert_browser_sensor("sensor", "visibility", "Browser visibility")
|
||||
_assert_browser_sensor(
|
||||
"sensor", "userAgent", "Browser userAgent", icon="mdi:account-details"
|
||||
)
|
||||
_assert_browser_sensor(
|
||||
"sensor", "currentUser", "Browser user", icon="mdi:account"
|
||||
)
|
||||
_assert_browser_sensor(
|
||||
"sensor", "width", "Browser width", "px", icon="mdi:arrow-left-right"
|
||||
)
|
||||
_assert_browser_sensor(
|
||||
"sensor", "height", "Browser height", "px", icon="mdi:arrow-up-down"
|
||||
)
|
||||
_assert_browser_sensor("sensor", "userAgent", "Browser userAgent")
|
||||
_assert_browser_sensor("sensor", "currentUser", "Browser user")
|
||||
_assert_browser_sensor("sensor", "width", "Browser width", "px")
|
||||
_assert_browser_sensor("sensor", "height", "Browser height", "px")
|
||||
# Don't create battery sensor unless battery level is reported
|
||||
if self.data.get("browser", {}).get("battery_level", None) is not None:
|
||||
_assert_browser_sensor(
|
||||
"sensor", "battery_level", "Browser battery", "%", "battery"
|
||||
)
|
||||
|
||||
_assert_browser_sensor(
|
||||
"binary_sensor",
|
||||
"darkMode",
|
||||
"Browser dark mode",
|
||||
icon="mdi:theme-light-dark",
|
||||
)
|
||||
_assert_browser_sensor(
|
||||
"binary_sensor", "fullyKiosk", "Browser FullyKiosk", icon="mdi:alpha-f"
|
||||
)
|
||||
_assert_browser_sensor("binary_sensor", "darkMode", "Browser dark mode")
|
||||
_assert_browser_sensor("binary_sensor", "fullyKiosk", "Browser FullyKiosk")
|
||||
# Don't create a charging sensor unless charging state is reported
|
||||
if self.data.get("browser", {}).get("charging", None) is not None:
|
||||
_assert_browser_sensor(
|
||||
"binary_sensor", "charging", "Browser charging", icon="mdi:power-plug"
|
||||
)
|
||||
_assert_browser_sensor("binary_sensor", "charging", "Browser charging")
|
||||
|
||||
if "activity" not in self.entities:
|
||||
adder = hass.data[DOMAIN][DATA_ADDERS]["binary_sensor"]
|
||||
|
@ -619,19 +619,10 @@ const MediaPlayerMixin = (SuperClass) => {
|
||||
return class MediaPlayerMixinClass extends SuperClass {
|
||||
constructor() {
|
||||
super();
|
||||
this._audio_player = new Audio();
|
||||
this._video_player = document.createElement("video");
|
||||
this._video_player.controls = true;
|
||||
this._video_player.style.setProperty("width", "100%");
|
||||
this.player = this._audio_player;
|
||||
this.player = new Audio();
|
||||
this._player_enabled = false;
|
||||
for (const ev of ["play", "pause", "ended", "volumechange"]) {
|
||||
this._audio_player.addEventListener(ev, () => this._player_update());
|
||||
this._video_player.addEventListener(ev, () => this._player_update());
|
||||
}
|
||||
for (const ev of ["timeupdate"]) {
|
||||
this._audio_player.addEventListener(ev, () => this._player_update_choked());
|
||||
this._video_player.addEventListener(ev, () => this._player_update_choked());
|
||||
this.player.addEventListener(ev, () => this._player_update());
|
||||
}
|
||||
this.firstInteraction.then(() => {
|
||||
this._player_enabled = true;
|
||||
@ -639,18 +630,10 @@ const MediaPlayerMixin = (SuperClass) => {
|
||||
this.player.play();
|
||||
});
|
||||
this.addEventListener("command-player-play", (ev) => {
|
||||
var _a, _b, _c;
|
||||
if (this.player.src)
|
||||
this.player.pause();
|
||||
if ((_a = ev.detail) === null || _a === void 0 ? void 0 : _a.media_type)
|
||||
if ((_b = ev.detail) === null || _b === void 0 ? void 0 : _b.media_type.startsWith("video"))
|
||||
this.player = this._video_player;
|
||||
else
|
||||
this.player = this._audio_player;
|
||||
if ((_c = ev.detail) === null || _c === void 0 ? void 0 : _c.media_content_id)
|
||||
var _a;
|
||||
if ((_a = ev.detail) === null || _a === void 0 ? void 0 : _a.media_content_id)
|
||||
this.player.src = ev.detail.media_content_id;
|
||||
this.player.play();
|
||||
this._show_video_player();
|
||||
});
|
||||
this.addEventListener("command-player-pause", (ev) => this.player.pause());
|
||||
this.addEventListener("command-player-stop", (ev) => {
|
||||
@ -670,49 +653,17 @@ const MediaPlayerMixin = (SuperClass) => {
|
||||
else
|
||||
this.player.muted = !this.player.muted;
|
||||
});
|
||||
this.addEventListener("command-player-seek", (ev) => {
|
||||
this.player.currentTime = ev.detail.position;
|
||||
setTimeout(() => this._player_update(), 10);
|
||||
});
|
||||
this.addEventListener("command-player-turn-off", (ev) => {
|
||||
if (this.player === this._video_player &&
|
||||
this._video_player.isConnected)
|
||||
this.closePopup();
|
||||
else if (this.player.src)
|
||||
this.player.pause();
|
||||
this.player.src = "";
|
||||
this._player_update();
|
||||
});
|
||||
this.connectionPromise.then(() => this._player_update());
|
||||
}
|
||||
_show_video_player() {
|
||||
if (this.player === this._video_player && this.player.src) {
|
||||
selectTree(document, "home-assistant $ dialog-media-player-browse").then((el) => el === null || el === void 0 ? void 0 : el.closeDialog());
|
||||
this.showPopup(undefined, this._video_player, {
|
||||
dismiss_action: () => this._video_player.pause(),
|
||||
size: "wide",
|
||||
});
|
||||
}
|
||||
else if (this.player !== this._video_player &&
|
||||
this._video_player.isConnected) {
|
||||
this.closePopup();
|
||||
}
|
||||
}
|
||||
_player_update_choked() {
|
||||
if (this._player_update_cooldown)
|
||||
return;
|
||||
this._player_update_cooldown = window.setTimeout(() => (this._player_update_cooldown = undefined), 3000);
|
||||
this._player_update();
|
||||
}
|
||||
_player_update() {
|
||||
const state = this._player_enabled
|
||||
? !this.player.src || this.player.src === window.location.href
|
||||
? "off"
|
||||
: this.player.ended
|
||||
? this.player.src
|
||||
? this.player.ended
|
||||
? "stopped"
|
||||
: this.player.paused
|
||||
? "paused"
|
||||
: "playing"
|
||||
: "stopped"
|
||||
: "unavailable";
|
||||
this.sendUpdate({
|
||||
player: {
|
||||
@ -720,8 +671,6 @@ const MediaPlayerMixin = (SuperClass) => {
|
||||
muted: this.player.muted,
|
||||
src: this.player.src,
|
||||
state,
|
||||
media_duration: this.player.duration,
|
||||
media_position: this.player.currentTime,
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -1203,17 +1152,13 @@ class BrowserModPopup extends s {
|
||||
}
|
||||
this._autocloseListener = undefined;
|
||||
if (this._autoclose) {
|
||||
this._autocloseListener = () => this.dialog.close();
|
||||
window.browser_mod.addEventListener("browser-mod-activity", this._autocloseListener, { once: true });
|
||||
this._autocloseListener = this._dismiss.bind(this);
|
||||
window.browser_mod.addEventListener("browser-mod-activity", this._autocloseListener);
|
||||
}
|
||||
}
|
||||
async setupDialog(title, content, { right_button = undefined, right_button_action = undefined, left_button = undefined, left_button_action = undefined, dismissable = true, dismiss_action = undefined, timeout = undefined, timeout_action = undefined, size = undefined, style = undefined, autoclose = false, } = {}) {
|
||||
this.title = title;
|
||||
if (content && content instanceof HTMLElement) {
|
||||
this.card = undefined;
|
||||
this.content = content;
|
||||
}
|
||||
else if (content && typeof content === "object") {
|
||||
if (content && typeof content === "object") {
|
||||
// Create a card from config in content
|
||||
this.card = true;
|
||||
const helpers = await window.loadCardHelpers();
|
||||
@ -1244,30 +1189,30 @@ class BrowserModPopup extends s {
|
||||
this._autoclose = autoclose;
|
||||
}
|
||||
async _primary() {
|
||||
var _a, _b, _c, _d;
|
||||
var _a, _b, _c;
|
||||
if ((_a = this._actions) === null || _a === void 0 ? void 0 : _a.dismiss_action)
|
||||
this._actions.dismiss_action = undefined;
|
||||
(_b = this.dialog) === null || _b === void 0 ? void 0 : _b.close();
|
||||
(_d = (_c = this._actions) === null || _c === void 0 ? void 0 : _c.right_button_action) === null || _d === void 0 ? void 0 : _d.call(_c);
|
||||
await this.closeDialog();
|
||||
(_c = (_b = this._actions) === null || _b === void 0 ? void 0 : _b.right_button_action) === null || _c === void 0 ? void 0 : _c.call(_b);
|
||||
}
|
||||
async _secondary() {
|
||||
var _a, _b, _c, _d;
|
||||
var _a, _b, _c;
|
||||
if ((_a = this._actions) === null || _a === void 0 ? void 0 : _a.dismiss_action)
|
||||
this._actions.dismiss_action = undefined;
|
||||
(_b = this.dialog) === null || _b === void 0 ? void 0 : _b.close();
|
||||
(_d = (_c = this._actions) === null || _c === void 0 ? void 0 : _c.left_button_action) === null || _d === void 0 ? void 0 : _d.call(_c);
|
||||
await this.closeDialog();
|
||||
(_c = (_b = this._actions) === null || _b === void 0 ? void 0 : _b.left_button_action) === null || _c === void 0 ? void 0 : _c.call(_b);
|
||||
}
|
||||
async _dismiss(ev) {
|
||||
var _a, _b, _c;
|
||||
(_a = this.dialog) === null || _a === void 0 ? void 0 : _a.close();
|
||||
(_c = (_b = this._actions) === null || _b === void 0 ? void 0 : _b.dismiss_action) === null || _c === void 0 ? void 0 : _c.call(_b);
|
||||
async _dismiss() {
|
||||
var _a, _b;
|
||||
await this.closeDialog();
|
||||
(_b = (_a = this._actions) === null || _a === void 0 ? void 0 : _a.dismiss_action) === null || _b === void 0 ? void 0 : _b.call(_a);
|
||||
}
|
||||
async _timeout() {
|
||||
var _a, _b, _c, _d;
|
||||
var _a, _b, _c;
|
||||
if ((_a = this._actions) === null || _a === void 0 ? void 0 : _a.dismiss_action)
|
||||
this._actions.dismiss_action = undefined;
|
||||
(_b = this.dialog) === null || _b === void 0 ? void 0 : _b.close();
|
||||
(_d = (_c = this._actions) === null || _c === void 0 ? void 0 : _c.timeout_action) === null || _d === void 0 ? void 0 : _d.call(_c);
|
||||
await this.closeDialog();
|
||||
(_c = (_b = this._actions) === null || _b === void 0 ? void 0 : _b.timeout_action) === null || _c === void 0 ? void 0 : _c.call(_b);
|
||||
}
|
||||
render() {
|
||||
if (!this.open)
|
||||
@ -1275,12 +1220,10 @@ class BrowserModPopup extends s {
|
||||
return $ `
|
||||
<ha-dialog
|
||||
open
|
||||
@closed=${this.closeDialog}
|
||||
@closing=${this._dismiss}
|
||||
.heading=${this.title !== undefined}
|
||||
?hideActions=${this.actions === undefined}
|
||||
.scrimClickAction=${this.dismissable ? "close" : ""}
|
||||
.escapeKeyAction=${this.dismissable ? "close" : ""}
|
||||
.scrimClickAction=${this.dismissable ? this._dismiss : ""}
|
||||
.escapeKeyAction=${this.dismissable ? this._dismiss : ""}
|
||||
>
|
||||
${this.timeout
|
||||
? $ ` <div slot="heading" class="progress"></div> `
|
||||
@ -1331,7 +1274,6 @@ class BrowserModPopup extends s {
|
||||
static get styles() {
|
||||
return r$2 `
|
||||
ha-dialog {
|
||||
z-index: 10;
|
||||
--mdc-dialog-min-width: var(--popup-min-width, 400px);
|
||||
--mdc-dialog-max-width: var(--popup-max-width, 600px);
|
||||
--mdc-dialog-heading-ink-color: var(--primary-text-color);
|
||||
@ -2223,8 +2165,8 @@ const BrowserIDMixin = (SuperClass) => {
|
||||
- Tweaks
|
||||
- Quickbar tweaks (ctrl+enter)?
|
||||
x Card-mod preload
|
||||
x Video player?
|
||||
x Media_seek
|
||||
- Video player?
|
||||
- Media_seek
|
||||
- Screensavers
|
||||
x IMPORTANT: FIX DEFAULT HIDING OF ENTITIES
|
||||
- NOFIX. Home Assistant bug
|
||||
|
@ -11,11 +11,10 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BrowserModEntity(CoordinatorEntity):
|
||||
def __init__(self, coordinator, browserID, name, icon=None):
|
||||
def __init__(self, coordinator, browserID, name):
|
||||
super().__init__(coordinator)
|
||||
self.browserID = browserID
|
||||
self._name = name
|
||||
self._icon = icon
|
||||
|
||||
@property
|
||||
def _data(self):
|
||||
@ -55,7 +54,3 @@ class BrowserModEntity(CoordinatorEntity):
|
||||
@property
|
||||
def unique_id(self):
|
||||
return f"{self.browserID}-{self._name.replace(' ','_')}"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
return self._icon
|
||||
|
@ -15,9 +15,6 @@ from homeassistant.components.media_player.const import (
|
||||
MEDIA_TYPE_MUSIC,
|
||||
MEDIA_TYPE_URL,
|
||||
SUPPORT_BROWSE_MEDIA,
|
||||
SUPPORT_SEEK,
|
||||
SUPPORT_TURN_OFF,
|
||||
SUPPORT_TURN_ON,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
STATE_UNAVAILABLE,
|
||||
@ -25,12 +22,8 @@ from homeassistant.const import (
|
||||
STATE_PLAYING,
|
||||
STATE_IDLE,
|
||||
STATE_UNKNOWN,
|
||||
STATE_ON,
|
||||
STATE_OFF,
|
||||
)
|
||||
|
||||
from homeassistant.util import dt
|
||||
|
||||
from .entities import BrowserModEntity
|
||||
from .const import DOMAIN, DATA_ADDERS
|
||||
|
||||
@ -67,8 +60,6 @@ class BrowserModPlayer(BrowserModEntity, MediaPlayerEntity):
|
||||
"paused": STATE_PAUSED,
|
||||
"stopped": STATE_IDLE,
|
||||
"unavailable": STATE_UNAVAILABLE,
|
||||
"on": STATE_ON,
|
||||
"off": STATE_OFF,
|
||||
}.get(state, STATE_UNKNOWN)
|
||||
|
||||
@property
|
||||
@ -81,9 +72,6 @@ class BrowserModPlayer(BrowserModEntity, MediaPlayerEntity):
|
||||
| SUPPORT_VOLUME_SET
|
||||
| SUPPORT_VOLUME_MUTE
|
||||
| SUPPORT_BROWSE_MEDIA
|
||||
| SUPPORT_SEEK
|
||||
| SUPPORT_TURN_OFF
|
||||
| SUPPORT_TURN_ON
|
||||
)
|
||||
|
||||
@property
|
||||
@ -94,20 +82,6 @@ class BrowserModPlayer(BrowserModEntity, MediaPlayerEntity):
|
||||
def is_volume_muted(self):
|
||||
return self._data.get("player", {}).get("muted", False)
|
||||
|
||||
@property
|
||||
def media_duration(self):
|
||||
duration = self._data.get("player", {}).get("media_duration", None)
|
||||
return float(duration) if duration is not None else None
|
||||
|
||||
@property
|
||||
def media_position(self):
|
||||
position = self._data.get("player", {}).get("media_position", None)
|
||||
return float(position) if position is not None else None
|
||||
|
||||
@property
|
||||
def media_position_updated_at(self):
|
||||
return dt.utcnow()
|
||||
|
||||
def set_volume_level(self, volume):
|
||||
self.browser.send("player-set-volume", volume_level=volume)
|
||||
|
||||
@ -116,24 +90,21 @@ class BrowserModPlayer(BrowserModEntity, MediaPlayerEntity):
|
||||
|
||||
async def async_play_media(self, media_type, media_id, **kwargs):
|
||||
if media_source.is_media_source_id(media_id):
|
||||
media_type = MEDIA_TYPE_URL
|
||||
play_item = await media_source.async_resolve_media(
|
||||
self.hass, media_id, self.entity_id
|
||||
)
|
||||
media_type = play_item.mime_type
|
||||
media_id = play_item.url
|
||||
media_id = async_process_play_media_url(self.hass, media_id)
|
||||
if media_type in (MEDIA_TYPE_URL, MEDIA_TYPE_MUSIC):
|
||||
media_id = async_process_play_media_url(self.hass, media_id)
|
||||
self.browser.send(
|
||||
"player-play", media_content_id=media_id, media_type=media_type, **kwargs
|
||||
)
|
||||
self.browser.send("player-play", media_content_id=media_id)
|
||||
|
||||
async def async_browse_media(self, media_content_type=None, media_content_id=None):
|
||||
"""Implement the websocket media browsing helper."""
|
||||
return await media_source.async_browse_media(
|
||||
self.hass,
|
||||
media_content_id,
|
||||
# content_filter=lambda item: item.media_content_type.startswith("audio/"),
|
||||
content_filter=lambda item: item.media_content_type.startswith("audio/"),
|
||||
)
|
||||
|
||||
def media_play(self):
|
||||
@ -144,12 +115,3 @@ class BrowserModPlayer(BrowserModEntity, MediaPlayerEntity):
|
||||
|
||||
def media_stop(self):
|
||||
self.browser.send("player-stop")
|
||||
|
||||
def media_seek(self, position):
|
||||
self.browser.send("player-seek", position=position)
|
||||
|
||||
def turn_off(self):
|
||||
self.browser.send("player-turn-off")
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
self.browser.send("player-turn-on", **kwargs)
|
||||
|
@ -23,9 +23,8 @@ class BrowserSensor(BrowserModEntity, SensorEntity):
|
||||
name,
|
||||
unit_of_measurement=None,
|
||||
device_class=None,
|
||||
icon=None,
|
||||
):
|
||||
BrowserModEntity.__init__(self, coordinator, browserID, name, icon)
|
||||
BrowserModEntity.__init__(self, coordinator, browserID, name)
|
||||
SensorEntity.__init__(self)
|
||||
self.parameter = parameter
|
||||
self._device_class = device_class
|
||||
@ -33,7 +32,10 @@ class BrowserSensor(BrowserModEntity, SensorEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self._data.get("browser", {}).get(self.parameter, None)
|
||||
data = self._data
|
||||
data = data.get("browser", {})
|
||||
data = data.get(self.parameter, None)
|
||||
return data
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
|
@ -67,8 +67,8 @@ import { BrowserIDMixin } from "./browserID";
|
||||
- Tweaks
|
||||
- Quickbar tweaks (ctrl+enter)?
|
||||
x Card-mod preload
|
||||
x Video player?
|
||||
x Media_seek
|
||||
- Video player?
|
||||
- Media_seek
|
||||
- Screensavers
|
||||
x IMPORTANT: FIX DEFAULT HIDING OF ENTITIES
|
||||
- NOFIX. Home Assistant bug
|
||||
|
@ -1,34 +1,16 @@
|
||||
import { selectTree } from "../helpers";
|
||||
|
||||
export const MediaPlayerMixin = (SuperClass) => {
|
||||
return class MediaPlayerMixinClass extends SuperClass {
|
||||
public player;
|
||||
private _audio_player;
|
||||
private _video_player;
|
||||
private _player_enabled;
|
||||
private _player_update_cooldown;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._audio_player = new Audio();
|
||||
this._video_player = document.createElement("video");
|
||||
this._video_player.controls = true;
|
||||
this._video_player.style.setProperty("width", "100%");
|
||||
this.player = this._audio_player;
|
||||
this.player = new Audio();
|
||||
this._player_enabled = false;
|
||||
|
||||
for (const ev of ["play", "pause", "ended", "volumechange"]) {
|
||||
this._audio_player.addEventListener(ev, () => this._player_update());
|
||||
this._video_player.addEventListener(ev, () => this._player_update());
|
||||
}
|
||||
for (const ev of ["timeupdate"]) {
|
||||
this._audio_player.addEventListener(ev, () =>
|
||||
this._player_update_choked()
|
||||
);
|
||||
this._video_player.addEventListener(ev, () =>
|
||||
this._player_update_choked()
|
||||
);
|
||||
this.player.addEventListener(ev, () => this._player_update());
|
||||
}
|
||||
|
||||
this.firstInteraction.then(() => {
|
||||
@ -37,15 +19,9 @@ export const MediaPlayerMixin = (SuperClass) => {
|
||||
});
|
||||
|
||||
this.addEventListener("command-player-play", (ev) => {
|
||||
if (this.player.src) this.player.pause();
|
||||
if (ev.detail?.media_type)
|
||||
if (ev.detail?.media_type.startsWith("video"))
|
||||
this.player = this._video_player;
|
||||
else this.player = this._audio_player;
|
||||
if (ev.detail?.media_content_id)
|
||||
this.player.src = ev.detail.media_content_id;
|
||||
this.player.play();
|
||||
this._show_video_player();
|
||||
});
|
||||
this.addEventListener("command-player-pause", (ev) =>
|
||||
this.player.pause()
|
||||
@ -63,60 +39,19 @@ export const MediaPlayerMixin = (SuperClass) => {
|
||||
this.player.muted = Boolean(ev.detail.mute);
|
||||
else this.player.muted = !this.player.muted;
|
||||
});
|
||||
this.addEventListener("command-player-seek", (ev) => {
|
||||
this.player.currentTime = ev.detail.position;
|
||||
setTimeout(() => this._player_update(), 10);
|
||||
});
|
||||
this.addEventListener("command-player-turn-off", (ev) => {
|
||||
if (
|
||||
this.player === this._video_player &&
|
||||
this._video_player.isConnected
|
||||
)
|
||||
this.closePopup();
|
||||
else if (this.player.src) this.player.pause();
|
||||
this.player.src = "";
|
||||
this._player_update();
|
||||
});
|
||||
|
||||
this.connectionPromise.then(() => this._player_update());
|
||||
}
|
||||
|
||||
private _show_video_player() {
|
||||
if (this.player === this._video_player && this.player.src) {
|
||||
selectTree(
|
||||
document,
|
||||
"home-assistant $ dialog-media-player-browse"
|
||||
).then((el) => el?.closeDialog());
|
||||
this.showPopup(undefined, this._video_player, {
|
||||
dismiss_action: () => this._video_player.pause(),
|
||||
size: "wide",
|
||||
});
|
||||
} else if (
|
||||
this.player !== this._video_player &&
|
||||
this._video_player.isConnected
|
||||
) {
|
||||
this.closePopup();
|
||||
}
|
||||
}
|
||||
|
||||
private _player_update_choked() {
|
||||
if (this._player_update_cooldown) return;
|
||||
this._player_update_cooldown = window.setTimeout(
|
||||
() => (this._player_update_cooldown = undefined),
|
||||
3000
|
||||
);
|
||||
this._player_update();
|
||||
}
|
||||
|
||||
private _player_update() {
|
||||
const state = this._player_enabled
|
||||
? !this.player.src || this.player.src === window.location.href
|
||||
? "off"
|
||||
: this.player.ended
|
||||
? "stopped"
|
||||
: this.player.paused
|
||||
? "paused"
|
||||
: "playing"
|
||||
? this.player.src
|
||||
? this.player.ended
|
||||
? "stopped"
|
||||
: this.player.paused
|
||||
? "paused"
|
||||
: "playing"
|
||||
: "stopped"
|
||||
: "unavailable";
|
||||
this.sendUpdate({
|
||||
player: {
|
||||
@ -124,8 +59,6 @@ export const MediaPlayerMixin = (SuperClass) => {
|
||||
muted: this.player.muted,
|
||||
src: this.player.src,
|
||||
state,
|
||||
media_duration: this.player.duration,
|
||||
media_position: this.player.currentTime,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ import { property, query } from "lit/decorators.js";
|
||||
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
||||
import { provideHass, loadLoadCardHelpers, hass_base_el } from "../helpers";
|
||||
|
||||
let aaa = 0;
|
||||
|
||||
class BrowserModPopup extends LitElement {
|
||||
@property() open;
|
||||
@property() content;
|
||||
@ -50,11 +52,10 @@ class BrowserModPopup extends LitElement {
|
||||
}
|
||||
this._autocloseListener = undefined;
|
||||
if (this._autoclose) {
|
||||
this._autocloseListener = () => this.dialog.close();
|
||||
this._autocloseListener = this._dismiss.bind(this);
|
||||
window.browser_mod.addEventListener(
|
||||
"browser-mod-activity",
|
||||
this._autocloseListener,
|
||||
{ once: true }
|
||||
this._autocloseListener
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -77,10 +78,7 @@ class BrowserModPopup extends LitElement {
|
||||
} = {}
|
||||
) {
|
||||
this.title = title;
|
||||
if (content && content instanceof HTMLElement) {
|
||||
this.card = undefined;
|
||||
this.content = content;
|
||||
} else if (content && typeof content === "object") {
|
||||
if (content && typeof content === "object") {
|
||||
// Create a card from config in content
|
||||
this.card = true;
|
||||
const helpers = await window.loadCardHelpers();
|
||||
@ -114,21 +112,21 @@ class BrowserModPopup extends LitElement {
|
||||
|
||||
async _primary() {
|
||||
if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined;
|
||||
this.dialog?.close();
|
||||
await this.closeDialog();
|
||||
this._actions?.right_button_action?.();
|
||||
}
|
||||
async _secondary() {
|
||||
if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined;
|
||||
this.dialog?.close();
|
||||
await this.closeDialog();
|
||||
this._actions?.left_button_action?.();
|
||||
}
|
||||
async _dismiss(ev?) {
|
||||
this.dialog?.close();
|
||||
async _dismiss() {
|
||||
await this.closeDialog();
|
||||
this._actions?.dismiss_action?.();
|
||||
}
|
||||
async _timeout() {
|
||||
if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined;
|
||||
this.dialog?.close();
|
||||
await this.closeDialog();
|
||||
this._actions?.timeout_action?.();
|
||||
}
|
||||
|
||||
@ -138,12 +136,10 @@ class BrowserModPopup extends LitElement {
|
||||
return html`
|
||||
<ha-dialog
|
||||
open
|
||||
@closed=${this.closeDialog}
|
||||
@closing=${this._dismiss}
|
||||
.heading=${this.title !== undefined}
|
||||
?hideActions=${this.actions === undefined}
|
||||
.scrimClickAction=${this.dismissable ? "close" : ""}
|
||||
.escapeKeyAction=${this.dismissable ? "close" : ""}
|
||||
.scrimClickAction=${this.dismissable ? this._dismiss : ""}
|
||||
.escapeKeyAction=${this.dismissable ? this._dismiss : ""}
|
||||
>
|
||||
${this.timeout
|
||||
? html` <div slot="heading" class="progress"></div> `
|
||||
@ -195,7 +191,6 @@ class BrowserModPopup extends LitElement {
|
||||
static get styles() {
|
||||
return css`
|
||||
ha-dialog {
|
||||
z-index: 10;
|
||||
--mdc-dialog-min-width: var(--popup-min-width, 400px);
|
||||
--mdc-dialog-max-width: var(--popup-max-width, 600px);
|
||||
--mdc-dialog-heading-ink-color: var(--primary-text-color);
|
||||
|
Loading…
x
Reference in New Issue
Block a user