Set Error if entity is unavailable (#12791)

This commit is contained in:
Zack Barett 2022-05-26 12:25:00 -05:00 committed by GitHub
parent c9df93bc54
commit 00dcecabb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -28,6 +28,7 @@ import { fireEvent } from "../../common/dom/fire_event";
import { computeRTLDirection } from "../../common/util/compute_rtl";
import { debounce } from "../../common/util/debounce";
import { getSignedPath } from "../../data/auth";
import { UNAVAILABLE_STATES } from "../../data/entity";
import type { MediaPlayerItem } from "../../data/media-player";
import {
browseMediaPlayer,
@ -45,6 +46,7 @@ import type { HomeAssistant } from "../../types";
import { brandsUrl, extractDomainFromBrandUrl } from "../../util/brands-url";
import { documentationUrl } from "../../util/documentation-url";
import "../entity/ha-entity-picker";
import "../ha-alert";
import "../ha-button-menu";
import "../ha-card";
import "../ha-circular-progress";
@ -246,6 +248,16 @@ export class HaMediaPlayerBrowse extends LitElement {
],
replace: true,
});
} else if (
err.code === "entity_not_found" &&
UNAVAILABLE_STATES.includes(this.hass.states[this.entityId]?.state)
) {
this._setError({
message: this.hass.localize(
`ui.components.media-browser.media_player_unavailable`
),
code: "entity_not_found",
});
} else {
this._setError(err);
}
@ -305,7 +317,11 @@ export class HaMediaPlayerBrowse extends LitElement {
protected render(): TemplateResult {
if (this._error) {
return html`
<div class="container">${this._renderError(this._error)}</div>
<div class="container">
<ha-alert alert-type="error">
${this._renderError(this._error)}
</ha-alert>
</div>
`;
}
@ -420,7 +436,9 @@ export class HaMediaPlayerBrowse extends LitElement {
this._error
? html`
<div class="container">
${this._renderError(this._error)}
<ha-alert alert-type="error">
${this._renderError(this._error)}
</ha-alert>
</div>
`
: isTTSMediaSource(currentItem.media_content_id)

View File

@ -609,7 +609,8 @@
"tv_show": "TV Show",
"url": "URL",
"video": "Video"
}
},
"media_player_unavailable": "The selected media player is unavailable."
},
"calendar": {
"my_calendars": "My Calendars",