Cast View 0 + show active (#3466)

* View 0 + show active

* Fix view 0 receiver

* Type

select doesn't seem to be used?
This commit is contained in:
Bram Kragten 2019-08-10 00:34:09 +02:00 committed by Paulus Schoutsen
parent 53f5a29151
commit e2dfac48d0
7 changed files with 22 additions and 22 deletions

View File

@ -158,16 +158,6 @@ class HcCast extends LitElement {
protected updated(changedProps) { protected updated(changedProps) {
super.updated(changedProps); super.updated(changedProps);
if (this.castManager && this.castManager.status) {
const selectEl = this.shadowRoot!.querySelector("select");
if (selectEl) {
this.shadowRoot!.querySelector("select")!.value =
this.castManager.castConnectedToOurHass &&
!this.castManager.status.showDemo
? this.castManager.status.lovelacePath || ""
: "";
}
}
this.toggleAttribute( this.toggleAttribute(
"hide-icons", "hide-icons",
this.lovelaceConfig this.lovelaceConfig

View File

@ -16,8 +16,10 @@ import "./hc-launch-screen";
@customElement("hc-lovelace") @customElement("hc-lovelace")
class HcLovelace extends LitElement { class HcLovelace extends LitElement {
@property() public hass!: HomeAssistant; @property() public hass!: HomeAssistant;
@property() public lovelaceConfig!: LovelaceConfig; @property() public lovelaceConfig!: LovelaceConfig;
@property() public viewPath?: string;
@property() public viewPath?: string | number;
protected render(): TemplateResult | void { protected render(): TemplateResult | void {
const index = this._viewIndex; const index = this._viewIndex;
@ -64,7 +66,7 @@ class HcLovelace extends LitElement {
private get _viewIndex() { private get _viewIndex() {
const selectedView = this.viewPath; const selectedView = this.viewPath;
const selectedViewInt = parseInt(selectedView!, 10); const selectedViewInt = parseInt(selectedView as string, 10);
for (let i = 0; i < this.lovelaceConfig.views.length; i++) { for (let i = 0; i < this.lovelaceConfig.views.length; i++) {
if ( if (
this.lovelaceConfig.views[i].path === selectedView || this.lovelaceConfig.views[i].path === selectedView ||

View File

@ -1,10 +1,10 @@
import { HassElement } from "../../../../src/state/hass-element";
import { import {
getAuth, getAuth,
createConnection, createConnection,
UnsubscribeFunc, UnsubscribeFunc,
} from "home-assistant-js-websocket"; } from "home-assistant-js-websocket";
import { customElement, TemplateResult, html, property } from "lit-element"; import { customElement, TemplateResult, html, property } from "lit-element";
import { HassElement } from "../../../../src/state/hass-element";
import { import {
HassMessage, HassMessage,
ConnectMessage, ConnectMessage,
@ -26,9 +26,13 @@ import { isNavigationClick } from "../../../../src/common/dom/is-navigation-clic
@customElement("hc-main") @customElement("hc-main")
export class HcMain extends HassElement { export class HcMain extends HassElement {
@property() private _showDemo = false; @property() private _showDemo = false;
@property() private _lovelaceConfig?: LovelaceConfig; @property() private _lovelaceConfig?: LovelaceConfig;
@property() private _lovelacePath: string | null = null;
@property() private _lovelacePath: string | number | null = null;
@property() private _error?: string; @property() private _error?: string;
private _unsubLovelace?: UnsubscribeFunc; private _unsubLovelace?: UnsubscribeFunc;
public processIncomingMessage(msg: HassMessage) { public processIncomingMessage(msg: HassMessage) {
@ -53,7 +57,7 @@ export class HcMain extends HassElement {
`; `;
} }
if (!this._lovelaceConfig || !this._lovelacePath) { if (!this._lovelaceConfig || this._lovelacePath === null) {
return html` return html`
<hc-launch-screen <hc-launch-screen
.hass=${this.hass} .hass=${this.hass}

View File

@ -1,10 +1,10 @@
// Nessages to be processed inside the Cast Receiver app // Nessages to be processed inside the Cast Receiver app
import { Auth } from "home-assistant-js-websocket";
import { CastManager } from "./cast_manager"; import { CastManager } from "./cast_manager";
import { BaseCastMessage } from "./types"; import { BaseCastMessage } from "./types";
import { CAST_DEV_HASS_URL, CAST_DEV } from "./const"; import { CAST_DEV_HASS_URL, CAST_DEV } from "./const";
import { Auth } from "home-assistant-js-websocket";
export interface GetStatusMessage extends BaseCastMessage { export interface GetStatusMessage extends BaseCastMessage {
type: "get_status"; type: "get_status";
@ -19,7 +19,7 @@ export interface ConnectMessage extends BaseCastMessage {
export interface ShowLovelaceViewMessage extends BaseCastMessage { export interface ShowLovelaceViewMessage extends BaseCastMessage {
type: "show_lovelace_view"; type: "show_lovelace_view";
viewPath: string | null; viewPath: string | number | null;
} }
export interface ShowDemoMessage extends BaseCastMessage { export interface ShowDemoMessage extends BaseCastMessage {
@ -64,7 +64,6 @@ export const ensureConnectedCastSession = (cast: CastManager, auth: Auth) => {
if (cast.castConnectedToOurHass) { if (cast.castConnectedToOurHass) {
unsub(); unsub();
resolve(); resolve();
return;
} }
}); });

View File

@ -7,7 +7,7 @@ export interface ReceiverStatusMessage extends BaseCastMessage {
connected: boolean; connected: boolean;
showDemo: boolean; showDemo: boolean;
hassUrl?: string; hassUrl?: string;
lovelacePath?: string | null; lovelacePath?: string | number | null;
} }
export type SenderMessage = ReceiverStatusMessage; export type SenderMessage = ReceiverStatusMessage;

View File

@ -30,7 +30,7 @@ export interface CastConfig {
type: "cast"; type: "cast";
icon: string; icon: string;
name: string; name: string;
view: string; view: string | number;
// Hide the row if either unsupported browser or no API available. // Hide the row if either unsupported browser or no API available.
hide_if_unavailable: boolean; hide_if_unavailable: boolean;
} }

View File

@ -23,11 +23,13 @@ class HuiCastRow extends LitElement implements EntityRow {
public hass!: HomeAssistant; public hass!: HomeAssistant;
@property() private _config?: CastConfig; @property() private _config?: CastConfig;
@property() private _castManager?: CastManager | null; @property() private _castManager?: CastManager | null;
@property() private _noHTTPS = false; @property() private _noHTTPS = false;
public setConfig(config: CastConfig): void { public setConfig(config: CastConfig): void {
if (!config || !config.view) { if (!config || config.view === undefined || config.view === null) {
throw new Error("Invalid Configuration: 'view' required"); throw new Error("Invalid Configuration: 'view' required");
} }
@ -66,6 +68,8 @@ class HuiCastRow extends LitElement implements EntityRow {
<google-cast-launcher></google-cast-launcher> <google-cast-launcher></google-cast-launcher>
<mwc-button <mwc-button
@click=${this._sendLovelace} @click=${this._sendLovelace}
.unelevated=${this._castManager.status &&
this._config.view === this._castManager.status.lovelacePath}
.disabled=${!this._castManager.status} .disabled=${!this._castManager.status}
> >
SHOW SHOW
@ -120,6 +124,7 @@ class HuiCastRow extends LitElement implements EntityRow {
:host { :host {
display: flex; display: flex;
align-items: center; align-items: center;
overflow: visible;
} }
ha-icon { ha-icon {
padding: 8px; padding: 8px;
@ -127,7 +132,6 @@ class HuiCastRow extends LitElement implements EntityRow {
} }
.flex { .flex {
flex: 1; flex: 1;
overflow: hidden;
margin-left: 16px; margin-left: 16px;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@ -144,6 +148,7 @@ class HuiCastRow extends LitElement implements EntityRow {
align-items: center; align-items: center;
} }
google-cast-launcher { google-cast-launcher {
margin-right: 0.57em;
cursor: pointer; cursor: pointer;
display: inline-block; display: inline-block;
height: 24px; height: 24px;