Fixes for disabled/unavailable entities (#14451)

This commit is contained in:
Bram Kragten 2022-11-28 12:13:54 +01:00 committed by GitHub
parent 0cfba81eae
commit 147b1f34ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 114 additions and 50 deletions

View File

@ -21,9 +21,9 @@ let colorIndex = 0;
export const getStateColorToken = ( export const getStateColorToken = (
stateString: string, stateString: string,
entityState: HassEntity entityState?: HassEntity
) => { ) => {
if (!stateActive(entityState, stateString)) { if (!entityState || !stateActive(entityState, stateString)) {
return `disabled`; return `disabled`;
} }
const color = stateColor(entityState, stateString); const color = stateColor(entityState, stateString);
@ -35,8 +35,8 @@ export const getStateColorToken = (
const getColor = ( const getColor = (
stateString: string, stateString: string,
entityState: HassEntity, computedStyles: CSSStyleDeclaration,
computedStyles: CSSStyleDeclaration entityState?: HassEntity
) => { ) => {
const stateColorToken = getStateColorToken(stateString, entityState); const stateColorToken = getStateColorToken(stateString, entityState);
@ -273,8 +273,8 @@ export class StateHistoryChartTimeline extends LitElement {
label: locState, label: locState,
color: getColor( color: getColor(
prevState, prevState,
this.hass.states[stateInfo.entity_id], computedStyles,
computedStyles this.hass.states[stateInfo.entity_id]
), ),
}); });
@ -291,8 +291,8 @@ export class StateHistoryChartTimeline extends LitElement {
label: locState, label: locState,
color: getColor( color: getColor(
prevState, prevState,
this.hass.states[stateInfo.entity_id], computedStyles,
computedStyles this.hass.states[stateInfo.entity_id]
), ),
}); });
} }

View File

@ -151,9 +151,7 @@ export class MoreInfoHistory extends LitElement {
setTimeout(() => fireEvent(this, "close-dialog"), 500); setTimeout(() => fireEvent(this, "close-dialog"), 500);
} }
static get styles() { static styles = css`
return [
css`
.header { .header {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
@ -167,17 +165,13 @@ export class MoreInfoHistory extends LitElement {
} }
.title { .title {
font-family: var(--paper-font-title_-_font-family); font-family: var(--paper-font-title_-_font-family);
-webkit-font-smoothing: var( -webkit-font-smoothing: var(--paper-font-title_-_-webkit-font-smoothing);
--paper-font-title_-_-webkit-font-smoothing
);
font-size: var(--paper-font-subhead_-_font-size); font-size: var(--paper-font-subhead_-_font-size);
font-weight: var(--paper-font-title_-_font-weight); font-weight: var(--paper-font-title_-_font-weight);
letter-spacing: var(--paper-font-title_-_letter-spacing); letter-spacing: var(--paper-font-title_-_letter-spacing);
line-height: var(--paper-font-title_-_line-height); line-height: var(--paper-font-title_-_line-height);
} }
`, `;
];
}
} }
declare global { declare global {

View File

@ -30,7 +30,14 @@ export class MoreInfoInfo extends LitElement {
const domain = computeDomain(entityId); const domain = computeDomain(entityId);
return html` return html`
${stateObj.attributes.restored && this._entityEntry ${!stateObj
? html`<ha-alert alert-type="warning">
${this.hass.localize(
"ui.dialogs.entity_registry.editor.unavailable"
)}
</ha-alert>`
: ""}
${stateObj?.attributes.restored && this._entityEntry
? html`<ha-alert alert-type="warning"> ? html`<ha-alert alert-type="warning">
${this.hass.localize( ${this.hass.localize(
"ui.dialogs.more_info_control.restored.no_longer_provided", "ui.dialogs.more_info_control.restored.no_longer_provided",

View File

@ -54,11 +54,13 @@ export class HaMoreInfoSettings extends LitElement {
} }
return html` return html`
<div @entity-entry-updated=${this._entryUpdated}>
${dynamicElement(this._settingsElementTag, { ${dynamicElement(this._settingsElementTag, {
hass: this.hass, hass: this.hass,
entry: this._entry, entry: this._entry,
entityId: this.entityId, entityId: this.entityId,
})} })}
</div>
`; `;
} }
@ -84,6 +86,10 @@ export class HaMoreInfoSettings extends LitElement {
} }
} }
private _entryUpdated(ev: CustomEvent<ExtEntityRegistryEntry>) {
this._entry = ev.detail;
}
private async _loadPlatformSettingTabs(): Promise<void> { private async _loadPlatformSettingTabs(): Promise<void> {
if (!this._entry) { if (!this._entry) {
return; return;

View File

@ -80,6 +80,7 @@ class DialogDeviceRegistryDetail extends LitElement {
<div class="row"> <div class="row">
<ha-switch <ha-switch
.checked=${!this._disabledBy} .checked=${!this._disabledBy}
.disabled=${this._params.device.disabled_by === "config_entry"}
@change=${this._disabledByChanged} @change=${this._disabledByChanged}
> >
</ha-switch> </ha-switch>

View File

@ -299,20 +299,35 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
return html` return html`
${!stateObj ${!stateObj
? html` ? html`
<div class="container warning"> <ha-alert alert-type="warning">
${this.hass!.localize(
"ui.dialogs.entity_registry.editor.unavailable"
)}
${this._device?.disabled_by ${this._device?.disabled_by
? html`<br />${this.hass!.localize( ? html`${this.hass!.localize(
"ui.dialogs.entity_registry.editor.device_disabled" "ui.dialogs.entity_registry.editor.device_disabled"
)}<br /><mwc-button @click=${this._openDeviceSettings}> )}<mwc-button
@click=${this._openDeviceSettings}
slot="action"
>
${this.hass!.localize( ${this.hass!.localize(
"ui.dialogs.entity_registry.editor.open_device_settings" "ui.dialogs.entity_registry.editor.open_device_settings"
)} )}
</mwc-button>` </mwc-button>`
: ""} : this.entry.disabled_by
</div> ? html`${this.hass!.localize(
"ui.dialogs.entity_registry.editor.entity_disabled"
)}${["user", "integration"].includes(this._disabledBy!)
? html`<mwc-button
slot="action"
@click=${this._enableEntry}
>
${this.hass!.localize(
"ui.dialogs.entity_registry.editor.enable_entity"
)}</mwc-button
>`
: ""}`
: this.hass!.localize(
"ui.dialogs.entity_registry.editor.unavailable"
)}
</ha-alert>
` `
: ""} : ""}
${this._error ${this._error
@ -922,6 +937,39 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
}); });
} }
private async _enableEntry() {
this._error = undefined;
this._submitting = true;
try {
const result = await updateEntityRegistryEntry(
this.hass!,
this._origEntityId,
{ disabled_by: null }
);
fireEvent(this, "entity-entry-updated", result.entity_entry);
if (result.require_restart) {
showAlertDialog(this, {
text: this.hass.localize(
"ui.dialogs.entity_registry.editor.enabled_restart_confirm"
),
});
}
if (result.reload_delay) {
showAlertDialog(this, {
text: this.hass.localize(
"ui.dialogs.entity_registry.editor.enabled_delay_confirm",
"delay",
result.reload_delay
),
});
}
} catch (err: any) {
this._error = err.message;
} finally {
this._submitting = false;
}
}
private async _updateEntry(): Promise<void> { private async _updateEntry(): Promise<void> {
this._submitting = true; this._submitting = true;
@ -1163,6 +1211,9 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
li[divider] { li[divider] {
border-bottom-color: var(--divider-color); border-bottom-color: var(--divider-color);
} }
ha-alert mwc-button {
width: max-content;
}
`, `,
]; ];
} }
@ -1172,4 +1223,7 @@ declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
"entity-registry-settings": EntityRegistrySettings; "entity-registry-settings": EntityRegistrySettings;
} }
interface HASSDomEvents {
"entity-entry-updated": ExtEntityRegistryEntry;
}
} }

View File

@ -893,6 +893,8 @@
"hidden_label": "Hidden", "hidden_label": "Hidden",
"hidden_cause": "Hidden by {cause}.", "hidden_cause": "Hidden by {cause}.",
"device_disabled": "The device of this entity is disabled.", "device_disabled": "The device of this entity is disabled.",
"entity_disabled": "This entity is disabled.",
"enable_entity": "Enable",
"open_device_settings": "Open device settings", "open_device_settings": "Open device settings",
"switch_as_x_confirm": "This switch will be hidden and a new {domain} will be added. Your existing configurations using the switch will continue to work.", "switch_as_x_confirm": "This switch will be hidden and a new {domain} will be added. Your existing configurations using the switch will continue to work.",
"enabled_description": "Disabled entities will not be added to Home Assistant.", "enabled_description": "Disabled entities will not be added to Home Assistant.",