Add link to aliases in cloud config entity settings (#14959)

This commit is contained in:
Bram Kragten 2023-01-02 20:42:31 +01:00 committed by GitHub
parent bdef924426
commit fe87466351
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 92 additions and 69 deletions

View File

@ -71,7 +71,6 @@ class HaDemo extends HomeAssistantAppEl {
entity_category: null, entity_category: null,
has_entity_name: false, has_entity_name: false,
unique_id: "co2_intensity", unique_id: "co2_intensity",
aliases: [],
}, },
{ {
config_entry_id: "co2signal", config_entry_id: "co2signal",
@ -87,7 +86,6 @@ class HaDemo extends HomeAssistantAppEl {
entity_category: null, entity_category: null,
has_entity_name: false, has_entity_name: false,
unique_id: "grid_fossil_fuel_percentage", unique_id: "grid_fossil_fuel_percentage",
aliases: [],
}, },
]); ]);

View File

@ -197,7 +197,6 @@ const createEntityRegistryEntries = (
platform: "updater", platform: "updater",
has_entity_name: false, has_entity_name: false,
unique_id: "updater", unique_id: "updater",
aliases: [],
}, },
]; ];

View File

@ -28,7 +28,7 @@ class StateInfo extends LitElement {
const name = computeStateName(this.stateObj); const name = computeStateName(this.stateObj);
return html` <state-badge return html`<state-badge
.stateObj=${this.stateObj} .stateObj=${this.stateObj}
.stateColor=${true} .stateColor=${true}
.color=${this.color} .color=${this.color}

View File

@ -22,7 +22,6 @@ export interface EntityRegistryEntry {
original_name?: string; original_name?: string;
unique_id: string; unique_id: string;
translation_key?: string; translation_key?: string;
aliases: string[];
} }
export interface ExtEntityRegistryEntry extends EntityRegistryEntry { export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
@ -30,6 +29,7 @@ export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
original_icon?: string; original_icon?: string;
device_class?: string; device_class?: string;
original_device_class?: string; original_device_class?: string;
aliases: string[];
} }
export interface UpdateEntityRegistryEntryResult { export interface UpdateEntityRegistryEntryResult {

View File

@ -541,15 +541,10 @@ export class HaAutomationTrace extends LitElement {
justify-content: center; justify-content: center;
display: flex; display: flex;
} }
.info { .info {
flex: 1; flex: 1;
background-color: var(--card-background-color); background-color: var(--card-background-color);
} }
.linkButton {
color: var(--primary-text-color);
}
.trace-link { .trace-link {
text-decoration: none; text-decoration: none;
} }

View File

@ -9,7 +9,6 @@ import {
mdiFormatListChecks, mdiFormatListChecks,
mdiSync, mdiSync,
} from "@mdi/js"; } from "@mdi/js";
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map"; import { classMap } from "lit/directives/class-map";
@ -43,20 +42,20 @@ import {
} from "../../../../data/cloud"; } from "../../../../data/cloud";
import { import {
EntityRegistryEntry, EntityRegistryEntry,
subscribeEntityRegistry, getExtendedEntityRegistryEntry,
updateEntityRegistryEntry,
} from "../../../../data/entity_registry"; } from "../../../../data/entity_registry";
import { showDomainTogglerDialog } from "../../../../dialogs/domain-toggler/show-dialog-domain-toggler"; import { showDomainTogglerDialog } from "../../../../dialogs/domain-toggler/show-dialog-domain-toggler";
import "../../../../layouts/hass-loading-screen"; import "../../../../layouts/hass-loading-screen";
import "../../../../layouts/hass-subpage"; import "../../../../layouts/hass-subpage";
import { SubscribeMixin } from "../../../../mixins/subscribe-mixin";
import { haStyle } from "../../../../resources/styles"; import { haStyle } from "../../../../resources/styles";
import type { HomeAssistant } from "../../../../types"; import type { HomeAssistant } from "../../../../types";
import { showEntityAliasesDialog } from "../../entities/entity-aliases/show-dialog-entity-aliases";
const DEFAULT_CONFIG_EXPOSE = true; const DEFAULT_CONFIG_EXPOSE = true;
const IGNORE_INTERFACES = ["Alexa.EndpointHealth"];
@customElement("cloud-alexa") @customElement("cloud-alexa")
class CloudAlexa extends SubscribeMixin(LitElement) { class CloudAlexa extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property() @property()
@ -171,10 +170,17 @@ class CloudAlexa extends SubscribeMixin(LitElement) {
secondary-line secondary-line
@click=${this._showMoreInfo} @click=${this._showMoreInfo}
> >
${entity.interfaces ${entity.entity_id in this.hass.entities
.filter((ifc) => !IGNORE_INTERFACES.includes(ifc)) ? html`<button
.map((ifc) => ifc.replace(/(Alexa.|Controller)/g, "")) class="link"
.join(", ")} .entityId=${entity.entity_id}
@click=${this._openAliasesSettings}
>
${this.hass.localize(
"ui.panel.config.cloud.alexa.manage_aliases"
)}
</button>`
: ""}
</state-info> </state-info>
${!emptyFilter ${!emptyFilter
? html`${iconButton}` ? html`${iconButton}`
@ -323,23 +329,33 @@ class CloudAlexa extends SubscribeMixin(LitElement) {
if (changedProps.has("cloudStatus")) { if (changedProps.has("cloudStatus")) {
this._entityConfigs = this.cloudStatus.prefs.alexa_entity_configs; this._entityConfigs = this.cloudStatus.prefs.alexa_entity_configs;
} }
if (
changedProps.has("hass") &&
changedProps.get("hass")?.entities !== this.hass.entities
) {
const categories = {};
for (const entry of Object.values(this.hass.entities)) {
categories[entry.entity_id] = entry.entity_category;
}
this._entityCategories = categories;
}
} }
protected override hassSubscribe(): ( private async _openAliasesSettings(ev) {
| UnsubscribeFunc ev.stopPropagation();
| Promise<UnsubscribeFunc> const entityId = ev.target.entityId;
)[] { const entry = await getExtendedEntityRegistryEntry(this.hass, entityId);
return [ if (!entry) {
subscribeEntityRegistry(this.hass.connection, (entries) => { return;
const categories = {}; }
showEntityAliasesDialog(this, {
for (const entry of entries) { entity: entry,
categories[entry.entity_id] = entry.entity_category; updateEntry: async (updates) => {
} await updateEntityRegistryEntry(this.hass, entry.entity_id, updates);
},
this._entityCategories = categories; });
}),
];
} }
private async _fetchData() { private async _fetchData() {

View File

@ -9,7 +9,6 @@ import {
mdiFormatListChecks, mdiFormatListChecks,
mdiSync, mdiSync,
} from "@mdi/js"; } from "@mdi/js";
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map"; import { classMap } from "lit/directives/class-map";
@ -41,7 +40,8 @@ import {
} from "../../../../data/cloud"; } from "../../../../data/cloud";
import { import {
EntityRegistryEntry, EntityRegistryEntry,
subscribeEntityRegistry, getExtendedEntityRegistryEntry,
updateEntityRegistryEntry,
} from "../../../../data/entity_registry"; } from "../../../../data/entity_registry";
import { import {
fetchCloudGoogleEntities, fetchCloudGoogleEntities,
@ -51,15 +51,15 @@ import { showDomainTogglerDialog } from "../../../../dialogs/domain-toggler/show
import { showAlertDialog } from "../../../../dialogs/generic/show-dialog-box"; import { showAlertDialog } from "../../../../dialogs/generic/show-dialog-box";
import "../../../../layouts/hass-loading-screen"; import "../../../../layouts/hass-loading-screen";
import "../../../../layouts/hass-subpage"; import "../../../../layouts/hass-subpage";
import { SubscribeMixin } from "../../../../mixins/subscribe-mixin"; import { buttonLinkStyle, haStyle } from "../../../../resources/styles";
import { haStyle } from "../../../../resources/styles";
import type { HomeAssistant } from "../../../../types"; import type { HomeAssistant } from "../../../../types";
import { showToast } from "../../../../util/toast"; import { showToast } from "../../../../util/toast";
import { showEntityAliasesDialog } from "../../entities/entity-aliases/show-dialog-entity-aliases";
const DEFAULT_CONFIG_EXPOSE = true; const DEFAULT_CONFIG_EXPOSE = true;
@customElement("cloud-google-assistant") @customElement("cloud-google-assistant")
class CloudGoogleAssistant extends SubscribeMixin(LitElement) { class CloudGoogleAssistant extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property() public cloudStatus!: CloudStatusLoggedIn; @property() public cloudStatus!: CloudStatusLoggedIn;
@ -174,15 +174,23 @@ class CloudGoogleAssistant extends SubscribeMixin(LitElement) {
secondary-line secondary-line
@click=${this._showMoreInfo} @click=${this._showMoreInfo}
> >
${entity.traits ${entity.entity_id in this.hass.entities
.map((trait) => trait.substr(trait.lastIndexOf(".") + 1)) ? html`<button
.join(", ")} class="link"
.entityId=${entity.entity_id}
@click=${this._openAliasesSettings}
>
${this.hass.localize(
"ui.panel.config.cloud.google.manage_aliases"
)}
</button>`
: ""}
</state-info> </state-info>
${!emptyFilter ${!emptyFilter
? html`${iconButton}` ? html`${iconButton}`
: html`<ha-button-menu : html`<ha-button-menu
corner="BOTTOM_START" corner="BOTTOM_START"
.entityId=${stateObj.entity_id} .entityId=${entity.entity_id}
@action=${this._exposeChanged} @action=${this._exposeChanged}
> >
${iconButton} ${iconButton}
@ -308,7 +316,7 @@ class CloudGoogleAssistant extends SubscribeMixin(LitElement) {
</h3> </h3>
${!this.narrow ${!this.narrow
? this.hass!.localize( ? this.hass!.localize(
"ui.panel.config.cloud.alexa.exposed", "ui.panel.config.cloud.google.exposed",
"selected", "selected",
selected selected
) )
@ -329,7 +337,7 @@ class CloudGoogleAssistant extends SubscribeMixin(LitElement) {
</h3> </h3>
${!this.narrow ${!this.narrow
? this.hass!.localize( ? this.hass!.localize(
"ui.panel.config.cloud.alexa.not_exposed", "ui.panel.config.cloud.google.not_exposed",
"selected", "selected",
this._entities.length - selected this._entities.length - selected
) )
@ -354,23 +362,33 @@ class CloudGoogleAssistant extends SubscribeMixin(LitElement) {
if (changedProps.has("cloudStatus")) { if (changedProps.has("cloudStatus")) {
this._entityConfigs = this.cloudStatus.prefs.google_entity_configs; this._entityConfigs = this.cloudStatus.prefs.google_entity_configs;
} }
if (
changedProps.has("hass") &&
changedProps.get("hass")?.entities !== this.hass.entities
) {
const categories = {};
for (const entry of Object.values(this.hass.entities)) {
categories[entry.entity_id] = entry.entity_category;
}
this._entityCategories = categories;
}
} }
protected override hassSubscribe(): ( private async _openAliasesSettings(ev) {
| UnsubscribeFunc ev.stopPropagation();
| Promise<UnsubscribeFunc> const entityId = ev.target.entityId;
)[] { const entry = await getExtendedEntityRegistryEntry(this.hass, entityId);
return [ if (!entry) {
subscribeEntityRegistry(this.hass.connection, (entries) => { return;
const categories = {}; }
showEntityAliasesDialog(this, {
for (const entry of entries) { entity: entry,
categories[entry.entity_id] = entry.entity_category; updateEntry: async (updates) => {
} await updateEntityRegistryEntry(this.hass, entry.entity_id, updates);
},
this._entityCategories = categories; });
}),
];
} }
private _configIsDomainExposed( private _configIsDomainExposed(
@ -583,6 +601,7 @@ class CloudGoogleAssistant extends SubscribeMixin(LitElement) {
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return [ return [
haStyle, haStyle,
buttonLinkStyle,
css` css`
mwc-list-item > [slot="meta"] { mwc-list-item > [slot="meta"] {
margin-left: 4px; margin-left: 4px;

View File

@ -1,11 +1,11 @@
import { fireEvent } from "../../../../common/dom/fire_event"; import { fireEvent } from "../../../../common/dom/fire_event";
import { import {
EntityRegistryEntry,
EntityRegistryEntryUpdateParams, EntityRegistryEntryUpdateParams,
ExtEntityRegistryEntry,
} from "../../../../data/entity_registry"; } from "../../../../data/entity_registry";
export interface EntityAliasesDialogParams { export interface EntityAliasesDialogParams {
entity: EntityRegistryEntry; entity: ExtEntityRegistryEntry;
updateEntry: ( updateEntry: (
updates: Partial<EntityRegistryEntryUpdateParams> updates: Partial<EntityRegistryEntryUpdateParams>
) => Promise<unknown>; ) => Promise<unknown>;

View File

@ -728,7 +728,6 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
selectable: false, selectable: false,
entity_category: null, entity_category: null,
has_entity_name: false, has_entity_name: false,
aliases: [],
}); });
} }
if (changed) { if (changed) {

View File

@ -527,15 +527,10 @@ export class HaScriptTrace extends LitElement {
:host([narrow]) .graph { :host([narrow]) .graph {
max-width: 100%; max-width: 100%;
} }
.info { .info {
flex: 1; flex: 1;
background-color: var(--card-background-color); background-color: var(--card-background-color);
} }
.linkButton {
color: var(--primary-text-color);
}
.trace-link { .trace-link {
text-decoration: none; text-decoration: none;
} }

View File

@ -2634,7 +2634,7 @@
"enable_state_reporting": "Enable State Reporting", "enable_state_reporting": "Enable State Reporting",
"info_state_reporting": "If you enable state reporting, Home Assistant will send all state changes of exposed entities to Amazon. This allows you to always see the latest states in the Alexa app and use the state changes to create routines.", "info_state_reporting": "If you enable state reporting, Home Assistant will send all state changes of exposed entities to Amazon. This allows you to always see the latest states in the Alexa app and use the state changes to create routines.",
"state_reporting_error": "Unable to {enable_disable} report state.", "state_reporting_error": "Unable to {enable_disable} report state.",
"manage_entities": "Manage Entities", "manage_entities": "[%key:ui::panel::config::cloud::account::google::manage_entities%]",
"enable": "enable", "enable": "enable",
"disable": "disable", "disable": "disable",
"not_configured_title": "Alexa is not activated", "not_configured_title": "Alexa is not activated",
@ -2685,6 +2685,7 @@
"follow_domain": "[%key:ui::panel::config::cloud::google::follow_domain%]", "follow_domain": "[%key:ui::panel::config::cloud::google::follow_domain%]",
"exposed": "[%key:ui::panel::config::cloud::google::exposed%]", "exposed": "[%key:ui::panel::config::cloud::google::exposed%]",
"not_exposed": "[%key:ui::panel::config::cloud::google::not_exposed%]", "not_exposed": "[%key:ui::panel::config::cloud::google::not_exposed%]",
"manage_aliases": "[%key:ui::panel::config::cloud::google::manage_aliases%]",
"expose": "Expose to Alexa", "expose": "Expose to Alexa",
"sync_entities": "Synchronize entities", "sync_entities": "Synchronize entities",
"sync_entities_error": "Failed to sync entities:" "sync_entities_error": "Failed to sync entities:"
@ -2710,6 +2711,7 @@
"follow_domain": "Follow domain", "follow_domain": "Follow domain",
"exposed": "{selected} exposed", "exposed": "{selected} exposed",
"not_exposed": "{selected} not exposed", "not_exposed": "{selected} not exposed",
"manage_aliases": "Manage aliases",
"sync_to_google": "Synchronizing changes to Google.", "sync_to_google": "Synchronizing changes to Google.",
"sync_entities": "Synchronize entities", "sync_entities": "Synchronize entities",
"sync_entities_error": "Failed to sync entities:", "sync_entities_error": "Failed to sync entities:",