Skip to content

Commit

Permalink
Merge pull request #12582 from home-assistant/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored May 4, 2022
2 parents 02af4c2 + a4f8e88 commit a39af9c
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 24 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = home-assistant-frontend
version = 20220503.0
version = 20220504.0
author = The Home Assistant Authors
author_email = hello@home-assistant.io
license = Apache-2.0
Expand Down
31 changes: 26 additions & 5 deletions src/components/media-player/ha-media-player-browse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import "@lit-labs/virtualizer";
import type { LitVirtualizer } from "@lit-labs/virtualizer";
import { grid } from "@lit-labs/virtualizer/layouts/grid";
import "@material/mwc-button/mwc-button";
import "@material/mwc-list/mwc-list";
import "@material/mwc-list/mwc-list-item";
import { mdiArrowUpRight, mdiPlay, mdiPlus } from "@mdi/js";
import "@polymer/paper-tooltip/paper-tooltip";
import { grid } from "@lit-labs/virtualizer/layouts/grid";
import "@lit-labs/virtualizer";
import {
css,
CSSResultGroup,
Expand All @@ -21,10 +22,12 @@ import {
state,
} from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { styleMap } from "lit/directives/style-map";
import { until } from "lit/directives/until";
import { fireEvent } from "../../common/dom/fire_event";
import { computeRTLDirection } from "../../common/util/compute_rtl";
import { debounce } from "../../common/util/debounce";
import { getSignedPath } from "../../data/auth";
import type { MediaPlayerItem } from "../../data/media-player";
import {
browseMediaPlayer,
Expand All @@ -39,6 +42,7 @@ import { showAlertDialog } from "../../dialogs/generic/show-dialog-box";
import { installResizeObserver } from "../../panels/lovelace/common/install-resize-observer";
import { haStyle } from "../../resources/styles";
import type { HomeAssistant } from "../../types";
import { brandsUrl, extractDomainFromBrandUrl } from "../../util/brands-url";
import { documentationUrl } from "../../util/documentation-url";
import "../entity/ha-entity-picker";
import "../ha-button-menu";
Expand All @@ -49,8 +53,6 @@ import "../ha-icon-button";
import "../ha-svg-icon";
import "./ha-browse-media-tts";
import type { TtsMediaPickedEvent } from "./ha-browse-media-tts";
import { getSignedPath } from "../../data/auth";
import { brandsUrl, extractDomainFromBrandUrl } from "../../util/brands-url";

declare global {
interface HASSDomEvents {
Expand Down Expand Up @@ -100,6 +102,10 @@ export class HaMediaPlayerBrowse extends LitElement {

@query(".content") private _content?: HTMLDivElement;

@query("lit-virtualizer") private _virtualizer?: LitVirtualizer;

private _observed = false;

private _headerOffsetHeight = 0;

private _resizeObserver?: ResizeObserver;
Expand Down Expand Up @@ -280,6 +286,19 @@ export class HaMediaPlayerBrowse extends LitElement {
this._animateHeaderHeight();
} else if (changedProps.has("_currentItem")) {
this._setHeaderHeight();

// This fixes a race condition for resizing of the cards using the grid layout
if (this._observed) {
return;
}

// @ts-ignore
const virtualizer = this._virtualizer?._virtualizer;

if (virtualizer) {
this._observed = true;
setTimeout(() => virtualizer._observeMutations(), 0);
}
}
}

Expand Down Expand Up @@ -477,6 +496,9 @@ export class HaMediaPlayerBrowse extends LitElement {
<lit-virtualizer
scroller
.items=${children}
style=${styleMap({
height: `${children.length * 72 + 26}px`,
})}
.renderItem=${this._renderListItem}
></lit-virtualizer>
${currentItem.not_shown
Expand Down Expand Up @@ -606,7 +628,6 @@ export class HaMediaPlayerBrowse extends LitElement {
</div>
<span class="title">${child.title}</span>
</mwc-list-item>
<li divider role="separator"></li>
`;
};

Expand Down
29 changes: 24 additions & 5 deletions src/data/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import type {
HassEntities,
HassEntityAttributeBase,
HassEntityBase,
HassEvent,
} from "home-assistant-js-websocket";
import { BINARY_STATE_ON } from "../common/const";
import { computeDomain } from "../common/entity/compute_domain";
import { computeStateDomain } from "../common/entity/compute_state_domain";
import { supportsFeature } from "../common/entity/supports-feature";
import { caseInsensitiveStringCompare } from "../common/string/compare";
Expand Down Expand Up @@ -110,15 +112,32 @@ export const checkForEntityUpdates = async (
return;
}

let updated = 0;

const unsubscribeEvents = await hass.connection.subscribeEvents<HassEvent>(
(event) => {
if (computeDomain(event.data.entity_id) === "update") {
updated++;
showToast(element, {
message: hass.localize("ui.panel.config.updates.updates_refreshed", {
count: updated,
}),
});
}
},
"state_changed"
);

await hass.callService("homeassistant", "update_entity", {
entity_id: entities,
});

if (filterUpdateEntitiesWithInstall(hass.states).length) {
showToast(element, {
message: hass.localize("ui.panel.config.updates.updates_refreshed"),
});
} else {
// there is no reliable way to know if all the updates are done updating, so we just wait a bit for now...
await new Promise((r) => setTimeout(r, 10000));

unsubscribeEvents();

if (updated === 0) {
showToast(element, {
message: hass.localize("ui.panel.config.updates.no_new_updates"),
});
Expand Down
3 changes: 2 additions & 1 deletion src/panels/config/automation/action/ha-automation-action.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import deepClone from "deep-clone-simple";
import "@material/mwc-button";
import { css, CSSResultGroup, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
Expand Down Expand Up @@ -83,7 +84,7 @@ export default class HaAutomationAction extends LitElement {
ev.stopPropagation();
const index = (ev.target as any).index;
fireEvent(this, "value-changed", {
value: this.actions.concat(this.actions[index]),
value: this.actions.concat(deepClone(this.actions[index])),
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import deepClone from "deep-clone-simple";
import "@material/mwc-button";
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
import { customElement, property } from "lit/decorators";
Expand Down Expand Up @@ -96,7 +97,7 @@ export default class HaAutomationCondition extends LitElement {
ev.stopPropagation();
const index = (ev.target as any).index;
fireEvent(this, "value-changed", {
value: this.conditions.concat(this.conditions[index]),
value: this.conditions.concat(deepClone(this.conditions[index])),
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import deepClone from "deep-clone-simple";
import "@material/mwc-button";
import { css, CSSResultGroup, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
Expand Down Expand Up @@ -67,7 +68,7 @@ export default class HaAutomationTrigger extends LitElement {
ev.stopPropagation();
const index = (ev.target as any).index;
fireEvent(this, "value-changed", {
value: this.triggers.concat(this.triggers[index]),
value: this.triggers.concat(deepClone(this.triggers[index])),
});
}

Expand Down
10 changes: 9 additions & 1 deletion src/panels/config/core/ha-config-section-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ class HaConfigSectionUpdates extends LitElement {
></ha-config-updates>
`
: html`
${this.hass.localize("ui.panel.config.updates.no_updates")}
<div class="no-updates">
${this.hass.localize(
"ui.panel.config.updates.no_updates"
)}
</div>
`}
</div>
</ha-card>
Expand Down Expand Up @@ -198,6 +202,10 @@ class HaConfigSectionUpdates extends LitElement {
flex-direction: column;
padding: 0;
}
.no-updates {
padding: 16px;
}
`;
}

Expand Down
26 changes: 25 additions & 1 deletion src/panels/config/dashboard/ha-config-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "../../../components/ha-alert";
import "../../../components/ha-icon-next";
import type { UpdateEntity } from "../../../data/update";
import type { HomeAssistant } from "../../../types";
import "../../../components/ha-circular-progress";

@customElement("ha-config-updates")
class HaConfigUpdates extends LitElement {
Expand Down Expand Up @@ -51,7 +52,18 @@ class HaConfigUpdates extends LitElement {
.title=${entity.attributes.title ||
entity.attributes.friendly_name}
.stateObj=${entity}
class=${this.narrow && entity.attributes.in_progress
? "updating"
: ""}
></state-badge>
${this.narrow && entity.attributes.in_progress
? html`<ha-circular-progress
active
size="small"
slot="graphic"
class="absolute"
></ha-circular-progress>`
: ""}
<span
>${entity.attributes.title ||
entity.attributes.friendly_name}</span
Expand All @@ -67,7 +79,13 @@ class HaConfigUpdates extends LitElement {
: ""}
</span>
${!this.narrow
? html`<ha-icon-next slot="meta"></ha-icon-next>`
? entity.attributes.in_progress
? html`<ha-circular-progress
active
size="small"
slot="meta"
></ha-circular-progress>`
: html`<ha-icon-next slot="meta"></ha-icon-next>`
: ""}
</mwc-list-item>
`
Expand Down Expand Up @@ -121,6 +139,12 @@ class HaConfigUpdates extends LitElement {
cursor: pointer;
font-size: 16px;
}
ha-circular-progress.absolute {
position: absolute;
}
state-badge.updating {
opacity: 0.5;
}
`,
];
}
Expand Down
1 change: 0 additions & 1 deletion src/panels/config/integrations/ha-integration-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import type { ConfigEntryExtended } from "./ha-config-integrations";
import "./ha-integration-header";

const integrationsWithPanel = {
hassio: "/hassio/dashboard",
mqtt: "/config/mqtt",
zha: "/config/zha/dashboard",
zwave_js: "/config/zwave_js/dashboard",
Expand Down
14 changes: 7 additions & 7 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1175,15 +1175,15 @@
},
"updates": {
"caption": "Updates",
"description": "Manage updates of Home Assistant, Add-ons and devices",
"description": "Manage updates of Home Assistant, add-ons and devices",
"no_updates": "No updates available",
"no_update_entities": {
"title": "Unable to check for updates",
"description": "You do not have any integrations that provide updates."
},
"check_updates": "Check for updates",
"no_new_updates": "No new updates found",
"updates_refreshed": "Updates 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}",
"unable_to_fetch": "Unable to load updates",
"version_available": "Version {version_available} is available",
Expand Down Expand Up @@ -1490,7 +1490,7 @@
},
"core": {
"caption": "General",
"description": "Name, Timezone and locale settings",
"description": "Name, time zone and locale settings",
"section": {
"core": {
"header": "General Configuration",
Expand Down Expand Up @@ -3139,7 +3139,7 @@
},
"analytics": {
"caption": "Analytics",
"description": "Learn how to share data to better the Open Home"
"description": "Learn how to share data to improve Home Assistant"
},
"network": {
"caption": "Network",
Expand Down Expand Up @@ -3184,11 +3184,11 @@
},
"system_health": {
"caption": "System Health",
"description": "Status, Stats and Integration startup time",
"description": "Status, metrics and integration startup time",
"cpu_usage": "Processor Usage",
"ram_usage": "Memory Usage",
"core_stats": "Core Stats",
"supervisor_stats": "Supervisor Stats",
"core_stats": "Core Metrics",
"supervisor_stats": "Supervisor Metrics",
"integration_start_time": "Integration Startup Time"
},
"system_dashboard": {
Expand Down

0 comments on commit a39af9c

Please sign in to comment.