Add optional hass object to ha-alert to compute rtl

This commit is contained in:
Ludeeus 2021-10-09 06:23:31 +00:00
parent 6f6fc759cc
commit 843aa3acb0
23 changed files with 74 additions and 27 deletions

View File

@ -55,7 +55,9 @@ class HassioAddonAudio extends LitElement {
> >
<div class="card-content"> <div class="card-content">
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error"
>${this._error}</ha-alert
>`
: ""} : ""}
<paper-dropdown-menu <paper-dropdown-menu

View File

@ -137,14 +137,16 @@ class HassioAddonConfig extends LitElement {
.yamlSchema=${ADDON_YAML_SCHEMA} .yamlSchema=${ADDON_YAML_SCHEMA}
></ha-yaml-editor>`} ></ha-yaml-editor>`}
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error">
${this._error}
</ha-alert>`
: ""} : ""}
${!this._yamlMode || ${!this._yamlMode ||
(this._canShowSchema && this.addon.schema) || (this._canShowSchema && this.addon.schema) ||
this._valid this._valid
? "" ? ""
: html` : html`
<ha-alert alert-type="error"> <ha-alert .hass=${this.hass} alert-type="error">
${this.supervisor.localize( ${this.supervisor.localize(
"addon.configuration.options.invalid_yaml" "addon.configuration.options.invalid_yaml"
)} )}

View File

@ -64,7 +64,9 @@ class HassioAddonNetwork extends LitElement {
> >
<div class="card-content"> <div class="card-content">
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error">
${this._error}
</ha-alert>`
: ""} : ""}
<table> <table>

View File

@ -40,7 +40,9 @@ class HassioAddonDocumentationDashboard extends LitElement {
<div class="content"> <div class="content">
<ha-card> <ha-card>
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error">
${this._error}
</ha-alert>`
: ""} : ""}
<div class="card-content"> <div class="card-content">
${this._content ${this._content

View File

@ -144,14 +144,14 @@ class HassioAddonInfo extends LitElement {
this.addon.arch this.addon.arch
) )
? html` ? html`
<ha-alert alert-type="warning"> <ha-alert .hass=${this.hass} alert-type="warning">
${this.supervisor.localize( ${this.supervisor.localize(
"addon.dashboard.not_available_arch" "addon.dashboard.not_available_arch"
)} )}
</ha-alert> </ha-alert>
` `
: html` : html`
<ha-alert alert-type="warning"> <ha-alert .hass=${this.hass} alert-type="warning">
${this.supervisor.localize( ${this.supervisor.localize(
"addon.dashboard.not_available_arch", "addon.dashboard.not_available_arch",
"core_version_installed", "core_version_installed",
@ -572,7 +572,9 @@ class HassioAddonInfo extends LitElement {
</div> </div>
</div> </div>
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error">
${this._error}
</ha-alert>`
: ""} : ""}
${!this.addon.version && addonStoreInfo && !this.addon.available ${!this.addon.version && addonStoreInfo && !this.addon.available
? !addonArchIsSupported( ? !addonArchIsSupported(
@ -580,14 +582,14 @@ class HassioAddonInfo extends LitElement {
this.addon.arch this.addon.arch
) )
? html` ? html`
<ha-alert alert-type="warning"> <ha-alert .hass=${this.hass} alert-type="warning">
${this.supervisor.localize( ${this.supervisor.localize(
"addon.dashboard.not_available_arch" "addon.dashboard.not_available_arch"
)} )}
</ha-alert> </ha-alert>
` `
: html` : html`
<ha-alert alert-type="warning"> <ha-alert .hass=${this.hass} alert-type="warning">
${this.supervisor.localize( ${this.supervisor.localize(
"addon.dashboard.not_available_version", "addon.dashboard.not_available_version",
"core_version_installed", "core_version_installed",

View File

@ -36,7 +36,9 @@ class HassioAddonLogs extends LitElement {
<h1>${this.addon.name}</h1> <h1>${this.addon.name}</h1>
<ha-card> <ha-card>
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error">
${this._error}
</ha-alert>`
: ""} : ""}
<div class="card-content"> <div class="card-content">
${this._content ${this._content

View File

@ -92,7 +92,9 @@ class HassioBackupDialog
> >
</supervisor-backup-content>`} </supervisor-backup-content>`}
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error">
${this._error}
</ha-alert>`
: ""} : ""}
<mwc-button <mwc-button

View File

@ -64,7 +64,9 @@ class HassioCreateBackupDialog extends LitElement {
> >
</supervisor-backup-content>`} </supervisor-backup-content>`}
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error">
${this._error}
</ha-alert>`
: ""} : ""}
<mwc-button slot="secondaryAction" @click=${this.closeDialog}> <mwc-button slot="secondaryAction" @click=${this.closeDialog}>
${this._dialogParams.supervisor.localize("common.close")} ${this._dialogParams.supervisor.localize("common.close")}

View File

@ -252,7 +252,7 @@ export class DialogHassioNetwork
` `
: ""} : ""}
${this._dirty ${this._dirty
? html`<ha-alert alert-type="warning"> ? html`<ha-alert .hass=${this.hass} alert-type="warning">
${this.supervisor.localize("dialog.network.warning")} ${this.supervisor.localize("dialog.network.warning")}
</ha-alert>` </ha-alert>`
: ""} : ""}

View File

@ -78,7 +78,9 @@ class HassioRepositoriesDialog extends LitElement {
)} )}
> >
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error">
${this._error}
</ha-alert>`
: ""} : ""}
<div class="form"> <div class="form">
${repositories.length ${repositories.length

View File

@ -130,7 +130,9 @@ class DialogSupervisorUpdate extends LitElement {
)} )}
</p>`} </p>`}
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error">
${this._error}
</ha-alert>`
: ""} : ""}
</ha-dialog> </ha-dialog>
`; `;

View File

@ -174,6 +174,7 @@ class HassioSupervisorInfo extends LitElement {
</ha-settings-row>` </ha-settings-row>`
: "" : ""
: html`<ha-alert : html`<ha-alert
.hass=${this.hass}
alert-type="warning" alert-type="warning"
.actionText=${this.supervisor.localize("common.learn_more")} .actionText=${this.supervisor.localize("common.learn_more")}
@alert-action-clicked=${this._unsupportedDialog} @alert-action-clicked=${this._unsupportedDialog}
@ -184,6 +185,7 @@ class HassioSupervisorInfo extends LitElement {
</ha-alert>`} </ha-alert>`}
${!this.supervisor.supervisor.healthy ${!this.supervisor.supervisor.healthy
? html`<ha-alert ? html`<ha-alert
.hass=${this.hass}
alert-type="error" alert-type="error"
.actionText=${this.supervisor.localize("common.learn_more")} .actionText=${this.supervisor.localize("common.learn_more")}
@alert-action-clicked=${this._unhealthyDialog} @alert-action-clicked=${this._unhealthyDialog}

View File

@ -69,7 +69,9 @@ class HassioSupervisorLog extends LitElement {
return html` return html`
<ha-card> <ha-card>
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error">
${this._error}
</ha-alert>`
: ""} : ""}
${this.hass.userData?.showAdvanced ${this.hass.userData?.showAdvanced
? html` ? html`

View File

@ -11,6 +11,8 @@ import { css, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { classMap } from "lit/directives/class-map"; import { classMap } from "lit/directives/class-map";
import { fireEvent } from "../common/dom/fire_event"; import { fireEvent } from "../common/dom/fire_event";
import { computeRTL } from "../common/util/compute_rtl";
import { HomeAssistant } from "../types";
import "./ha-svg-icon"; import "./ha-svg-icon";
const ALERT_ICONS = { const ALERT_ICONS = {
@ -29,6 +31,8 @@ declare global {
@customElement("ha-alert") @customElement("ha-alert")
class HaAlert extends LitElement { class HaAlert extends LitElement {
@property({ type: Object }) public hass?: HomeAssistant;
@property() public title = ""; @property() public title = "";
@property({ attribute: "alert-type" }) public alertType: @property({ attribute: "alert-type" }) public alertType:
@ -37,7 +41,7 @@ class HaAlert extends LitElement {
| "error" | "error"
| "success" = "info"; | "success" = "info";
@property({ attribute: "action-text" }) public actionText = ""; @property({ attribute: "action-text" }) public actionText?: string;
@property({ type: Boolean }) public dismissable = false; @property({ type: Boolean }) public dismissable = false;
@ -47,7 +51,7 @@ class HaAlert extends LitElement {
return html` return html`
<div <div
class="issue-type ${classMap({ class="issue-type ${classMap({
rtl: this.rtl, rtl: this.hass ? computeRTL(this.hass) : this.rtl,
[this.alertType]: true, [this.alertType]: true,
})}" })}"
> >

View File

@ -46,6 +46,7 @@ export class CloudGooglePref extends LitElement {
${google_enabled && !this.cloudStatus.google_registered ${google_enabled && !this.cloudStatus.google_registered
? html` ? html`
<ha-alert <ha-alert
.hass=${this.hass}
.title=${this.hass.localize( .title=${this.hass.localize(
"ui.panel.config.cloud.account.google.not_configured_title" "ui.panel.config.cloud.account.google.not_configured_title"
)} )}

View File

@ -64,6 +64,7 @@ export class CloudRemotePref extends LitElement {
${!remote_connected && remote_enabled ${!remote_connected && remote_enabled
? html` ? html`
<ha-alert <ha-alert
.hass=${this.hass}
.title=${this.hass.localize( .title=${this.hass.localize(
`ui.panel.config.cloud.account.remote.reconnecting` `ui.panel.config.cloud.account.remote.reconnecting`
)} )}

View File

@ -23,6 +23,7 @@ class EnergyValidationMessage extends LitElement {
return Object.entries(grouped).map( return Object.entries(grouped).map(
([issueType, gIssues]) => html` ([issueType, gIssues]) => html`
<ha-alert <ha-alert
.hass=${this.hass}
alert-type="warning" alert-type="warning"
.title=${ .title=${
this.hass.localize( this.hass.localize(

View File

@ -78,7 +78,7 @@ class HaConfigEnergy extends LitElement {
.route=${this.route} .route=${this.route}
.tabs=${configSections.experiences} .tabs=${configSections.experiences}
> >
<ha-alert> <ha-alert .hass=${this.hass}>
After setting up a new device, it can take up to 2 hours for new data After setting up a new device, it can take up to 2 hours for new data
to arrive in your energy dashboard. to arrive in your energy dashboard.
</ha-alert> </ha-alert>

View File

@ -159,7 +159,10 @@ export class ZwaveMigration extends LitElement {
) )
.map( .map(
(entityState) => (entityState) =>
html`<ha-alert alert-type="warning"> html`<ha-alert
.hass=${this.hass}
alert-type="warning"
>
Device ${computeStateName(entityState)} Device ${computeStateName(entityState)}
(${entityState.entity_id}) is not ready yet! For (${entityState.entity_id}) is not ready yet! For
the best result, wake the device up if it is the best result, wake the device up if it is
@ -252,7 +255,10 @@ export class ZwaveMigration extends LitElement {
</p> </p>
${this._waitingOnDevices?.map( ${this._waitingOnDevices?.map(
(device) => (device) =>
html`<ha-alert alert-type="warning"> html`<ha-alert
.hass=${this.hass}
alert-type="warning"
>
Device ${computeDeviceName(device, this.hass)} is Device ${computeDeviceName(device, this.hass)} is
not ready yet! For the best result, wake the device not ready yet! For the best result, wake the device
up if it is battery powered and wait for this device up if it is battery powered and wait for this device
@ -265,6 +271,7 @@ export class ZwaveMigration extends LitElement {
${this._migratedZwaveEntities!.length !== ${this._migratedZwaveEntities!.length !==
this._migrationData.zwave_entity_ids.length this._migrationData.zwave_entity_ids.length
? html`<ha-alert ? html`<ha-alert
.hass=${this.hass}
alert-type="warning" alert-type="warning"
title="Not all entities can be migrated!" title="Not all entities can be migrated!"
> >

View File

@ -166,7 +166,7 @@ class DialogZWaveJSAddNode extends LitElement {
</p> </p>
${ ${
this._error this._error
? html`<ha-alert alert-type="error" ? html`<ha-alert .hass=${this.hass} alert-type="error"
>${this._error}</ha-alert >${this._error}</ha-alert
>` >`
: "" : ""
@ -192,7 +192,9 @@ class DialogZWaveJSAddNode extends LitElement {
? html` ? html`
<h3>The device has requested the following security classes:</h3> <h3>The device has requested the following security classes:</h3>
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? html`<ha-alert .hass=${this.hass} alert-type="error"
>${this._error}</ha-alert
>`
: ""} : ""}
<div class="flex-column"> <div class="flex-column">
${this._requestedGrant?.securityClasses ${this._requestedGrant?.securityClasses
@ -356,6 +358,7 @@ class DialogZWaveJSAddNode extends LitElement {
</p> </p>
${this._lowSecurity ${this._lowSecurity
? html`<ha-alert ? html`<ha-alert
.hass=${this.hass}
alert-type="warning" alert-type="warning"
title="The device was added insecurely" title="The device was added insecurely"
> >

View File

@ -35,7 +35,11 @@ export class HuiErrorCard extends LitElement implements LovelaceCard {
} }
} }
return html`<ha-alert alert-type="error" .title=${this._config.error}> return html`<ha-alert
.hass=${this.hass}
alert-type="error"
.title=${this._config.error}
>
${dumped ? html`<pre>${dumped}</pre>` : ""} ${dumped ? html`<pre>${dumped}</pre>` : ""}
</ha-alert>`; </ha-alert>`;
} }

View File

@ -19,7 +19,9 @@ export const createEntityNotFoundWarning = (
@customElement("hui-warning") @customElement("hui-warning")
export class HuiWarning extends LitElement { export class HuiWarning extends LitElement {
protected render(): TemplateResult { protected render(): TemplateResult {
return html`<ha-alert alert-type="warning"><slot></slot></ha-alert> `; return html`<ha-alert alert-type="warning">
<slot></slot>
</ha-alert> `;
} }
} }

View File

@ -124,7 +124,7 @@ export class HuiDialogEditView extends LitElement {
? html` ? html`
${VIEWS_NO_BADGE_SUPPORT.includes(this._type) ${VIEWS_NO_BADGE_SUPPORT.includes(this._type)
? html` ? html`
<ha-alert alert-type="warning"> <ha-alert .hass=${this.hass} alert-type="warning">
${this.hass!.localize( ${this.hass!.localize(
"ui.panel.lovelace.editor.edit_badges.view_no_badges" "ui.panel.lovelace.editor.edit_badges.view_no_badges"
)} )}