mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-13 04:16:34 +00:00
Make updates more distinct recognizable by device name (#13433)
This commit is contained in:
parent
1b5c30712e
commit
4b54cb4a35
@ -2,6 +2,8 @@ import "@material/mwc-button/mwc-button";
|
|||||||
import "@material/mwc-list/mwc-list";
|
import "@material/mwc-list/mwc-list";
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
|
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import "../../../components/entity/state-badge";
|
import "../../../components/entity/state-badge";
|
||||||
import "../../../components/ha-alert";
|
import "../../../components/ha-alert";
|
||||||
@ -10,9 +12,19 @@ import type { UpdateEntity } from "../../../data/update";
|
|||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
import "../../../components/ha-circular-progress";
|
import "../../../components/ha-circular-progress";
|
||||||
import "../../../components/ha-list-item";
|
import "../../../components/ha-list-item";
|
||||||
|
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
||||||
|
import {
|
||||||
|
computeDeviceName,
|
||||||
|
DeviceRegistryEntry,
|
||||||
|
subscribeDeviceRegistry,
|
||||||
|
} from "../../../data/device_registry";
|
||||||
|
import {
|
||||||
|
EntityRegistryEntry,
|
||||||
|
subscribeEntityRegistry,
|
||||||
|
} from "../../../data/entity_registry";
|
||||||
|
|
||||||
@customElement("ha-config-updates")
|
@customElement("ha-config-updates")
|
||||||
class HaConfigUpdates extends LitElement {
|
class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ type: Boolean }) public narrow!: boolean;
|
@property({ type: Boolean }) public narrow!: boolean;
|
||||||
@ -20,9 +32,36 @@ class HaConfigUpdates extends LitElement {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public updateEntities?: UpdateEntity[];
|
public updateEntities?: UpdateEntity[];
|
||||||
|
|
||||||
|
@property({ attribute: false, type: Array })
|
||||||
|
private devices?: DeviceRegistryEntry[];
|
||||||
|
|
||||||
|
@property({ attribute: false, type: Array })
|
||||||
|
private entities?: EntityRegistryEntry[];
|
||||||
|
|
||||||
@property({ type: Number })
|
@property({ type: Number })
|
||||||
public total?: number;
|
public total?: number;
|
||||||
|
|
||||||
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
|
return [
|
||||||
|
subscribeDeviceRegistry(this.hass.connection, (entries) => {
|
||||||
|
this.devices = entries;
|
||||||
|
}),
|
||||||
|
subscribeEntityRegistry(this.hass.connection!, (entities) => {
|
||||||
|
this.entities = entities.filter((entity) => entity.device_id !== null);
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private getDeviceEntry = memoizeOne(
|
||||||
|
(deviceId: string): DeviceRegistryEntry | undefined =>
|
||||||
|
this.devices?.find((device) => device.id === deviceId)
|
||||||
|
);
|
||||||
|
|
||||||
|
private getEntityEntry = memoizeOne(
|
||||||
|
(entityId: string): EntityRegistryEntry | undefined =>
|
||||||
|
this.entities?.find((entity) => entity.entity_id === entityId)
|
||||||
|
);
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this.updateEntities?.length) {
|
if (!this.updateEntities?.length) {
|
||||||
return html``;
|
return html``;
|
||||||
@ -37,8 +76,14 @@ class HaConfigUpdates extends LitElement {
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
<mwc-list>
|
<mwc-list>
|
||||||
${updates.map(
|
${updates.map((entity) => {
|
||||||
(entity) => html`
|
const entityEntry = this.getEntityEntry(entity.entity_id);
|
||||||
|
const deviceEntry =
|
||||||
|
entityEntry && entityEntry.device_id
|
||||||
|
? this.getDeviceEntry(entityEntry.device_id)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
return html`
|
||||||
<ha-list-item
|
<ha-list-item
|
||||||
twoline
|
twoline
|
||||||
graphic="avatar"
|
graphic="avatar"
|
||||||
@ -65,16 +110,13 @@ class HaConfigUpdates extends LitElement {
|
|||||||
></ha-circular-progress>`
|
></ha-circular-progress>`
|
||||||
: ""}
|
: ""}
|
||||||
<span
|
<span
|
||||||
>${entity.attributes.title ||
|
>${deviceEntry
|
||||||
entity.attributes.friendly_name}</span
|
? computeDeviceName(deviceEntry, this.hass)
|
||||||
|
: entity.attributes.friendly_name}</span
|
||||||
>
|
>
|
||||||
<span slot="secondary">
|
<span slot="secondary">
|
||||||
${this.hass.localize(
|
${entity.attributes.title} ${entity.attributes.latest_version}
|
||||||
"ui.panel.config.updates.version_available",
|
${entity.attributes.skipped_version
|
||||||
{
|
|
||||||
version_available: entity.attributes.latest_version,
|
|
||||||
}
|
|
||||||
)}${entity.attributes.skipped_version
|
|
||||||
? `(${this.hass.localize("ui.panel.config.updates.skipped")})`
|
? `(${this.hass.localize("ui.panel.config.updates.skipped")})`
|
||||||
: ""}
|
: ""}
|
||||||
</span>
|
</span>
|
||||||
@ -88,8 +130,8 @@ class HaConfigUpdates extends LitElement {
|
|||||||
: html`<ha-icon-next slot="meta"></ha-icon-next>`
|
: html`<ha-icon-next slot="meta"></ha-icon-next>`
|
||||||
: ""}
|
: ""}
|
||||||
</ha-list-item>
|
</ha-list-item>
|
||||||
`
|
`;
|
||||||
)}
|
})}
|
||||||
</mwc-list>
|
</mwc-list>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -1225,7 +1225,6 @@
|
|||||||
"updates_refreshed": "{count} {count, plural,\n one {update}\n other {updates}\n} refreshed",
|
"updates_refreshed": "{count} {count, plural,\n one {update}\n other {updates}\n} refreshed",
|
||||||
"title": "{count} {count, plural,\n one {update}\n other {updates}\n}",
|
"title": "{count} {count, plural,\n one {update}\n other {updates}\n}",
|
||||||
"unable_to_fetch": "Unable to load updates",
|
"unable_to_fetch": "Unable to load updates",
|
||||||
"version_available": "Version {version_available} is available",
|
|
||||||
"more_updates": "Show all updates",
|
"more_updates": "Show all updates",
|
||||||
"show": "show",
|
"show": "show",
|
||||||
"show_skipped": "Show skipped updates",
|
"show_skipped": "Show skipped updates",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user