Cast fixes (#10598)

This commit is contained in:
Bram Kragten 2021-11-17 19:33:15 +01:00 committed by GitHub
parent 582fab7ea1
commit 7d94615f47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 16 deletions

View File

@ -15,7 +15,7 @@ class HcLovelace extends LitElement {
@property() public viewPath?: string | number; @property() public viewPath?: string | number;
public urlPath?: string | null; @property() public urlPath: string | null = null;
protected render(): TemplateResult { protected render(): TemplateResult {
const index = this._viewIndex; const index = this._viewIndex;
@ -31,7 +31,7 @@ class HcLovelace extends LitElement {
config: this.lovelaceConfig, config: this.lovelaceConfig,
rawConfig: this.lovelaceConfig, rawConfig: this.lovelaceConfig,
editMode: false, editMode: false,
urlPath: this.urlPath!, urlPath: this.urlPath,
enableFullEditMode: () => undefined, enableFullEditMode: () => undefined,
mode: "storage", mode: "storage",
locale: this.hass.locale, locale: this.hass.locale,

View File

@ -40,9 +40,9 @@ export class HcMain extends HassElement {
@state() private _error?: string; @state() private _error?: string;
private _unsubLovelace?: UnsubscribeFunc; @state() private _urlPath?: string | null;
private _urlPath?: string | null; private _unsubLovelace?: UnsubscribeFunc;
public processIncomingMessage(msg: HassMessage) { public processIncomingMessage(msg: HassMessage) {
if (msg.type === "connect") { if (msg.type === "connect") {
@ -68,8 +68,10 @@ export class HcMain extends HassElement {
!this._lovelaceConfig || !this._lovelaceConfig ||
this._lovelacePath === null || this._lovelacePath === null ||
// Guard against part of HA not being loaded yet. // Guard against part of HA not being loaded yet.
(this.hass && !this.hass ||
(!this.hass.states || !this.hass.config || !this.hass.services)) !this.hass.states ||
!this.hass.config ||
!this.hass.services
) { ) {
return html` return html`
<hc-launch-screen <hc-launch-screen
@ -119,7 +121,7 @@ export class HcMain extends HassElement {
if (this.hass) { if (this.hass) {
status.hassUrl = this.hass.auth.data.hassUrl; status.hassUrl = this.hass.auth.data.hassUrl;
status.lovelacePath = this._lovelacePath!; status.lovelacePath = this._lovelacePath;
status.urlPath = this._urlPath; status.urlPath = this._urlPath;
} }
@ -173,6 +175,7 @@ export class HcMain extends HassElement {
} }
private async _handleShowLovelaceMessage(msg: ShowLovelaceViewMessage) { private async _handleShowLovelaceMessage(msg: ShowLovelaceViewMessage) {
this._showDemo = false;
// We should not get this command before we are connected. // We should not get this command before we are connected.
// Means a client got out of sync. Let's send status to them. // Means a client got out of sync. Let's send status to them.
if (!this.hass) { if (!this.hass) {
@ -183,14 +186,16 @@ export class HcMain extends HassElement {
if (msg.urlPath === "lovelace") { if (msg.urlPath === "lovelace") {
msg.urlPath = null; msg.urlPath = null;
} }
this._lovelacePath = msg.viewPath;
if (!this._unsubLovelace || this._urlPath !== msg.urlPath) { if (!this._unsubLovelace || this._urlPath !== msg.urlPath) {
this._urlPath = msg.urlPath; this._urlPath = msg.urlPath;
this._lovelaceConfig = undefined;
if (this._unsubLovelace) { if (this._unsubLovelace) {
this._unsubLovelace(); this._unsubLovelace();
} }
const llColl = atLeastVersion(this.hass.connection.haVersion, 0, 107) const llColl = atLeastVersion(this.hass.connection.haVersion, 0, 107)
? getLovelaceCollection(this.hass!.connection, msg.urlPath) ? getLovelaceCollection(this.hass.connection, msg.urlPath)
: getLegacyLovelaceCollection(this.hass!.connection); : getLegacyLovelaceCollection(this.hass.connection);
// We first do a single refresh because we need to check if there is LL // We first do a single refresh because we need to check if there is LL
// configuration. // configuration.
try { try {
@ -199,8 +204,12 @@ export class HcMain extends HassElement {
this._handleNewLovelaceConfig(lovelaceConfig) this._handleNewLovelaceConfig(lovelaceConfig)
); );
} catch (err: any) { } catch (err: any) {
// eslint-disable-next-line if (err.code !== "config_not_found") {
console.log("Error fetching Lovelace configuration", err, msg); // eslint-disable-next-line
console.log("Error fetching Lovelace configuration", err, msg);
this._error = `Error fetching Lovelace configuration: ${err.message}`;
return;
}
// Generate a Lovelace config. // Generate a Lovelace config.
this._unsubLovelace = () => undefined; this._unsubLovelace = () => undefined;
await this._generateLovelaceConfig(); await this._generateLovelaceConfig();
@ -215,8 +224,6 @@ export class HcMain extends HassElement {
loadLovelaceResources(resources, this.hass!.auth.data.hassUrl); loadLovelaceResources(resources, this.hass!.auth.data.hassUrl);
} }
} }
this._showDemo = false;
this._lovelacePath = msg.viewPath;
this._sendStatus(); this._sendStatus();
} }
@ -237,7 +244,7 @@ export class HcMain extends HassElement {
} }
private _handleNewLovelaceConfig(lovelaceConfig: LovelaceConfig) { private _handleNewLovelaceConfig(lovelaceConfig: LovelaceConfig) {
castContext.setApplicationState(lovelaceConfig.title!); castContext.setApplicationState(lovelaceConfig.title || "");
this._lovelaceConfig = lovelaceConfig; this._lovelaceConfig = lovelaceConfig;
} }

View File

@ -26,7 +26,9 @@ class HaEntityMarker extends LitElement {
? html`<div ? html`<div
class="entity-picture" class="entity-picture"
style=${styleMap({ style=${styleMap({
"background-image": `url(${this.entityPicture})`, "background-image": `url(${this.hass.hassUrl(
this.entityPicture
)})`,
})} })}
></div>` ></div>`
: this.entityName} : this.entityName}

View File

@ -544,7 +544,9 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
} }
try { try {
const { foreground, background } = await extractColors(this._image); const { foreground, background } = await extractColors(
this.hass.hassUrl(this._image)
);
this._backgroundColor = background.hex; this._backgroundColor = background.hex;
this._foregroundColor = foreground.hex; this._foregroundColor = foreground.hex;
} catch (err: any) { } catch (err: any) {