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) {
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(
"hide-icons",
this.lovelaceConfig

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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