Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/data/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,27 @@ export const updateUsesProgress = (entity: UpdateEntity): boolean =>
supportsFeature(entity, UpdateEntityFeature.PROGRESS) &&
entity.attributes.update_percentage !== null;

export const updateAvailable = (
entity: UpdateEntity,
showSkipped = false
): boolean =>
entity.state === BINARY_STATE_ON ||
(showSkipped && Boolean(entity.attributes.skipped_version));

export const updateCanInstall = (
entity: UpdateEntity,
showSkipped = false
): boolean =>
(entity.state === BINARY_STATE_ON ||
(showSkipped && Boolean(entity.attributes.skipped_version))) &&
updateAvailable(entity, showSkipped) &&
supportsFeature(entity, UpdateEntityFeature.INSTALL);

export const updateCanNotInstall = (
entity: UpdateEntity,
showSkipped = false
): boolean =>
updateAvailable(entity, showSkipped) &&
!supportsFeature(entity, UpdateEntityFeature.INSTALL);

export const latestVersionIsSkipped = (entity: UpdateEntity): boolean =>
!!(
entity.attributes.latest_version &&
Expand Down Expand Up @@ -108,13 +121,17 @@ export const filterUpdateEntities = (
);
});

export const filterUpdateEntitiesWithInstall = (
export const filterUpdateEntitiesParameterized = (
entities: HassEntities,
showSkipped = false
showSkipped = false,
showNotInstallable = false
) =>
filterUpdateEntities(entities).filter((entity) =>
updateCanInstall(entity, showSkipped)
);
filterUpdateEntities(entities).filter((entity) => {
if (showNotInstallable) {
return updateCanNotInstall(entity, showSkipped);
}
return updateCanInstall(entity, showSkipped);
});

export const checkForEntityUpdates = async (
element: HTMLElement,
Expand Down
73 changes: 53 additions & 20 deletions src/panels/config/core/ha-config-section-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from "../../../data/hassio/supervisor";
import {
checkForEntityUpdates,
filterUpdateEntitiesWithInstall,
filterUpdateEntitiesParameterized,
} from "../../../data/update";
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
import "../../../layouts/hass-subpage";
Expand All @@ -53,9 +53,15 @@ class HaConfigSectionUpdates extends LitElement {
}

protected render(): TemplateResult {
const canInstallUpdates = this._filterUpdateEntitiesWithInstall(
const canInstallUpdates = this._filterUpdateEntitiesParameterized(
this.hass.states,
this._showSkipped
this._showSkipped,
false
);
const notInstallableUpdates = this._filterUpdateEntitiesParameterized(
this.hass.states,
this._showSkipped,
true
);
Comment on lines +56 to 65
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling _filterUpdateEntitiesParameterized twice with different args defeats the memoization as the cache only keeps the latest value.
You should create a new memoized method similar to _filterUpdateEntitiesParameterized for "not installable" updates instead of reusing _filterUpdateEntitiesParameterized.


return html`
Expand Down Expand Up @@ -104,26 +110,45 @@ class HaConfigSectionUpdates extends LitElement {
</ha-button-menu>
</div>
<div class="content">
<ha-card outlined>
<div class="card-content">
${canInstallUpdates.length
? html`
${canInstallUpdates.length
? html`
<ha-card>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outlined is missing here. Is it intentional?

<div class="card-content">
<ha-config-updates
.hass=${this.hass}
.narrow=${this.narrow}
.updateEntities=${canInstallUpdates}
.isInstallable=${true}
showAll
></ha-config-updates>
</div>
</ha-card>
`
: ""}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: ""}
: nothing}

${notInstallableUpdates.length
? html`
<ha-card>
<div class="card-content">
<ha-config-updates
.hass=${this.hass}
.narrow=${this.narrow}
.updateEntities=${notInstallableUpdates}
.isInstallable=${false}
showAll
></ha-config-updates>
`
: html`
<div class="no-updates">
${this.hass.localize(
"ui.panel.config.updates.no_updates"
)}
</div>
`}
</div>
</ha-card>
</div>
</ha-card>
`
: ""}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: ""}
: nothing}

${canInstallUpdates.length + notInstallableUpdates.length
? ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
? ""
? nothing

: html`
<ha-card>
<div class="no-updates">
${this.hass.localize("ui.panel.config.updates.no_updates")}
</div>
</ha-card>
`}
</div>
</hass-subpage>
`;
Expand Down Expand Up @@ -177,9 +202,17 @@ class HaConfigSectionUpdates extends LitElement {
checkForEntityUpdates(this, this.hass);
}

private _filterUpdateEntitiesWithInstall = memoizeOne(
(entities: HassEntities, showSkipped: boolean) =>
filterUpdateEntitiesWithInstall(entities, showSkipped)
private _filterUpdateEntitiesParameterized = memoizeOne(
(
entities: HassEntities,
showSkipped: boolean,
showNotInstallable: boolean
) =>
filterUpdateEntitiesParameterized(
entities,
showSkipped,
showNotInstallable
)
);

static styles = css`
Expand Down
15 changes: 9 additions & 6 deletions src/panels/config/dashboard/ha-config-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import type { UpdateEntity } from "../../../data/update";
import {
checkForEntityUpdates,
filterUpdateEntitiesWithInstall,
filterUpdateEntitiesParameterized,
} from "../../../data/update";
import {
QuickBarMode,
Expand Down Expand Up @@ -203,7 +203,7 @@ class HaConfigDashboard extends SubscribeMixin(LitElement) {

protected render(): TemplateResult {
const { updates: canInstallUpdates, total: totalUpdates } =
this._filterUpdateEntitiesWithInstall(
this._filterUpdateEntitiesParameterized(
this.hass.states,
this.hass.entities
);
Expand Down Expand Up @@ -288,6 +288,7 @@ class HaConfigDashboard extends SubscribeMixin(LitElement) {
.narrow=${this.narrow}
.total=${totalUpdates}
.updateEntities=${canInstallUpdates}
.isInstallable=${true}
></ha-config-updates>
${totalUpdates > canInstallUpdates.length
? html`
Expand Down Expand Up @@ -344,14 +345,16 @@ class HaConfigDashboard extends SubscribeMixin(LitElement) {
showShortcutsDialog(this);
}

private _filterUpdateEntitiesWithInstall = memoizeOne(
private _filterUpdateEntitiesParameterized = memoizeOne(
(
entities: HomeAssistant["states"],
entityRegistry: HomeAssistant["entities"]
): { updates: UpdateEntity[]; total: number } => {
const updates = filterUpdateEntitiesWithInstall(entities).filter(
(entity) => !entityRegistry[entity.entity_id]?.hidden
);
const updates = filterUpdateEntitiesParameterized(
entities,
false,
false
).filter((entity) => !entityRegistry[entity.entity_id]?.hidden);

return {
updates: updates.slice(0, updates.length === 3 ? updates.length : 2),
Expand Down
3 changes: 3 additions & 0 deletions src/panels/config/dashboard/ha-config-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {

@property({ type: Number }) public total?: number;

@property({ attribute: false }) public isInstallable = true;

@state() private _devices?: DeviceRegistryEntry[];

@state() private _entities?: EntityRegistryEntry[];
Expand Down Expand Up @@ -91,6 +93,7 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
<div class="title" role="heading" aria-level="2">
${this.hass.localize("ui.panel.config.updates.title", {
count: this.total || this.updateEntities.length,
installable: this.isInstallable ? "true" : "false",
})}
</div>
<ha-md-list>
Expand Down
2 changes: 1 addition & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@
"no_new_updates": "No new updates found",
"updates_refreshed": "State of {count} {count, plural,\n one {update}\n other {updates}\n} refreshed",
"checking_updates": "Checking for updates...",
"title": "{count} {count, plural,\n one {update}\n other {updates}\n}",
"title": "{count} {count, plural,\n one {{installable, select, \n true {installable} \n other {not installable}\n} update}\n other {{installable, select, \n true {installable} \n other {not installable}\n} updates}\n}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overcomplicates it IMO. Lets just leave the existing translation as is and add a new one for "not installable" updates.
The vast majority of cases will not have "not installable" updates so they don't need to see "installable" for normal updates. It would just confuse users and translators.

"unable_to_fetch": "Unable to load updates",
"more_updates": "Show all updates",
"show": "show",
Expand Down
Loading