mirror of
https://github.com/home-assistant/frontend.git
synced 2026-11-26 22:59:34 +00:00
Compare commits
15
Commits
dev
...
20261125.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c70897226 | ||
|
|
3a27de8e0a | ||
|
|
bc21f2903d | ||
|
|
b067ce5515 | ||
|
|
c95ed9f16c | ||
|
|
95eb2641e2 | ||
|
|
4cb23b772a | ||
|
|
0bf5da2e09 | ||
|
|
c12ad32797 | ||
|
|
2c03c2d74a | ||
|
|
2705e6da51 | ||
|
|
e3871d47de | ||
|
|
ead8c01926 | ||
|
|
258cb6f8b9 | ||
|
|
72057cf504 |
No files matched your search
@@ -70,6 +70,32 @@ const ENTITIES = [
|
||||
CoverEntityFeature.CLOSE_TILT,
|
||||
},
|
||||
},
|
||||
{
|
||||
entity_id: "cover.tilt_only_closed",
|
||||
state: "closed",
|
||||
attributes: {
|
||||
friendly_name: "Tilt-only blind closed",
|
||||
device_class: "blind",
|
||||
assumed_state: true,
|
||||
supported_features:
|
||||
CoverEntityFeature.OPEN_TILT +
|
||||
CoverEntityFeature.STOP_TILT +
|
||||
CoverEntityFeature.CLOSE_TILT,
|
||||
},
|
||||
},
|
||||
{
|
||||
entity_id: "cover.tilt_only_open",
|
||||
state: "open",
|
||||
attributes: {
|
||||
friendly_name: "Tilt-only blind open",
|
||||
device_class: "blind",
|
||||
assumed_state: true,
|
||||
supported_features:
|
||||
CoverEntityFeature.OPEN_TILT +
|
||||
CoverEntityFeature.STOP_TILT +
|
||||
CoverEntityFeature.CLOSE_TILT,
|
||||
},
|
||||
},
|
||||
{
|
||||
entity_id: "cover.tilt_slider_half",
|
||||
state: "on",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "home-assistant-frontend"
|
||||
version = "20261125.0"
|
||||
version = "20261125.1"
|
||||
license = "Apache-2.0"
|
||||
license-files = ["LICENSE*"]
|
||||
description = "The Home Assistant frontend"
|
||||
|
||||
@@ -250,8 +250,8 @@ export class HaDialog extends ScrollableFadeMixin(LitElement) {
|
||||
this._hassConfig?.auth.external &&
|
||||
isIosApp(this._hassConfig.auth.external)
|
||||
) {
|
||||
const element = this.querySelector("[autofocus]");
|
||||
if (element !== null) {
|
||||
const element = this._autofocusElement();
|
||||
if (element) {
|
||||
if (!element.id) {
|
||||
element.id = "ha-dialog-autofocus";
|
||||
}
|
||||
@@ -264,10 +264,30 @@ export class HaDialog extends ScrollableFadeMixin(LitElement) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
(this.querySelector("[autofocus]") as HTMLElement | null)?.focus();
|
||||
this._autofocusElement()?.focus();
|
||||
});
|
||||
};
|
||||
|
||||
// Wrappers like ha-adaptive-dialog pass their content in through slots
|
||||
private _autofocusElement(): HTMLElement | null {
|
||||
const element = this.querySelector<HTMLElement>("[autofocus]");
|
||||
if (element) {
|
||||
return element;
|
||||
}
|
||||
for (const slot of this.querySelectorAll("slot")) {
|
||||
for (const assigned of slot.assignedElements({ flatten: true })) {
|
||||
if (assigned.matches("[autofocus]")) {
|
||||
return assigned as HTMLElement;
|
||||
}
|
||||
const nested = assigned.querySelector<HTMLElement>("[autofocus]");
|
||||
if (nested) {
|
||||
return nested;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private _handleAfterShow = (ev: Event) => {
|
||||
if (ev.eventPhase !== Event.AT_TARGET) {
|
||||
return;
|
||||
|
||||
@@ -238,6 +238,7 @@ export class HaGridSizeEditor extends LitElement {
|
||||
grid-template-rows: auto auto;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: var(--ha-space-2);
|
||||
padding-left: var(--ha-space-4);
|
||||
}
|
||||
.precise {
|
||||
grid-area: precise;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { TemplateResult } from "lit";
|
||||
import type { PropertyValues, TemplateResult } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import type { ActionHandlerOptions } from "../../data/lovelace/action_handler";
|
||||
import { actionHandler } from "../../panels/lovelace/common/directives/action-handler-directive";
|
||||
import { actionHandlerBind } from "../../panels/lovelace/common/directives/action-handler-directive";
|
||||
import "../ha-icon";
|
||||
import "../ha-svg-icon";
|
||||
|
||||
@@ -56,6 +56,11 @@ export class HaTileIcon extends LitElement {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues<this>): void {
|
||||
super.updated(changedProps);
|
||||
actionHandlerBind(this, this.actionHandlerOptions);
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const hasImage = Boolean(this.imageUrl);
|
||||
|
||||
@@ -67,7 +72,6 @@ export class HaTileIcon extends LitElement {
|
||||
aria-label=${ifDefined(
|
||||
this.interactive ? this.accessibleLabel : undefined
|
||||
)}
|
||||
.actionHandler=${actionHandler(this.actionHandlerOptions)}
|
||||
>
|
||||
<slot name="icon">${this._renderIcon()}</slot>
|
||||
</div>
|
||||
@@ -94,6 +98,7 @@ export class HaTileIcon extends LitElement {
|
||||
:host([interactive]) {
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
pointer-events: auto;
|
||||
cursor: pointer;
|
||||
}
|
||||
:host([interactive]:active) {
|
||||
transform: scale(1.2);
|
||||
@@ -143,6 +148,9 @@ export class HaTileIcon extends LitElement {
|
||||
transition: color 180ms ease-in-out;
|
||||
pointer-events: none;
|
||||
}
|
||||
::slotted(:not([slot])) {
|
||||
pointer-events: none;
|
||||
}
|
||||
.container img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
@@ -5,6 +5,9 @@ import {
|
||||
} from "home-assistant-js-websocket";
|
||||
import type { Store } from "home-assistant-js-websocket/dist/store";
|
||||
import type { DataTableRowData } from "../components/data-table/ha-data-table";
|
||||
import type { HomeAssistant } from "../types";
|
||||
import type { ConfigEntry } from "./config_entries";
|
||||
import type { DeviceRegistryEntry } from "./device/device_registry";
|
||||
|
||||
export interface BluetoothDeviceData extends DataTableRowData {
|
||||
address: string;
|
||||
@@ -74,6 +77,54 @@ export const isScannerStateMismatch = (state: BluetoothScannerState): boolean =>
|
||||
state.requested_mode !== "auto" &&
|
||||
state.current_mode !== state.requested_mode;
|
||||
|
||||
export interface BluetoothAdapterDevice {
|
||||
device: DeviceRegistryEntry;
|
||||
entry: ConfigEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the Bluetooth adapters into enabled and disabled ones. An adapter is
|
||||
* a device with a Bluetooth connection that belongs to a `bluetooth` config
|
||||
* entry. Config entries without such a device (for example ignored discoveries
|
||||
* or removed proxies) are not adapters, unless they are disabled, so they can
|
||||
* still be enabled again.
|
||||
*/
|
||||
export const getBluetoothAdapters = (
|
||||
devices: HomeAssistant["devices"],
|
||||
configEntries: ConfigEntry[]
|
||||
) => {
|
||||
const entryMap = new Map(configEntries.map((e) => [e.entry_id, e]));
|
||||
|
||||
const enabledDevices: BluetoothAdapterDevice[] = [];
|
||||
const disabledDevices: BluetoothAdapterDevice[] = [];
|
||||
const matchedEntryIds = new Set<string>();
|
||||
|
||||
for (const device of Object.values(devices)) {
|
||||
const btConnection = device.connections.find((c) => c[0] === "bluetooth");
|
||||
if (!btConnection) {
|
||||
continue;
|
||||
}
|
||||
const entry = device.config_entries
|
||||
.map((id) => entryMap.get(id))
|
||||
.find((e) => e !== undefined);
|
||||
if (!entry) {
|
||||
continue;
|
||||
}
|
||||
matchedEntryIds.add(entry.entry_id);
|
||||
if (entry.disabled_by !== null) {
|
||||
disabledDevices.push({ device, entry });
|
||||
} else {
|
||||
enabledDevices.push({ device, entry });
|
||||
}
|
||||
}
|
||||
|
||||
const disabledEntriesWithoutDevice = configEntries.filter(
|
||||
(e) => e.disabled_by !== null && !matchedEntryIds.has(e.entry_id)
|
||||
);
|
||||
|
||||
return { enabledDevices, disabledDevices, disabledEntriesWithoutDevice };
|
||||
};
|
||||
|
||||
export const subscribeBluetoothScannersDetailsUpdates = (
|
||||
conn: Connection,
|
||||
store: Store<BluetoothScannersDetails>
|
||||
|
||||
+19
-5
@@ -239,12 +239,29 @@ export interface CoverEntity extends HassEntityBase {
|
||||
attributes: CoverEntityAttributes;
|
||||
}
|
||||
|
||||
// For covers that report no value, the open or closed state tells where it is
|
||||
const valueFromState = (stateObj: CoverEntity): number | undefined => {
|
||||
if (stateObj.state === UNKNOWN || stateObj.state === UNAVAILABLE) {
|
||||
return undefined;
|
||||
}
|
||||
return stateObj.state === "closed" || stateObj.state === "opening" ? 0 : 100;
|
||||
};
|
||||
|
||||
export const coverCurrentValue = (
|
||||
stateObj: CoverEntity,
|
||||
mode: CoverControlMode
|
||||
): number | undefined => {
|
||||
if (mode === "tilt") {
|
||||
return stateObj.attributes.current_tilt_position ?? undefined;
|
||||
const tilt = stateObj.attributes.current_tilt_position;
|
||||
// The state only describes the slats when the cover can't move up or down
|
||||
if (
|
||||
tilt != null ||
|
||||
coverSupportsTiltPosition(stateObj) ||
|
||||
coverHasPositionControls(stateObj)
|
||||
) {
|
||||
return tilt ?? undefined;
|
||||
}
|
||||
return valueFromState(stateObj);
|
||||
}
|
||||
const position = stateObj.attributes.current_position;
|
||||
if (
|
||||
@@ -253,10 +270,7 @@ export const coverCurrentValue = (
|
||||
) {
|
||||
return position ?? undefined;
|
||||
}
|
||||
if (stateObj.state === UNKNOWN || stateObj.state === UNAVAILABLE) {
|
||||
return undefined;
|
||||
}
|
||||
return stateObj.state === "closed" || stateObj.state === "opening" ? 0 : 100;
|
||||
return valueFromState(stateObj);
|
||||
};
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -167,3 +167,9 @@ export const updateDismissedSuggestions = (
|
||||
statisticId,
|
||||
];
|
||||
};
|
||||
|
||||
/** The dismissed statistics without the restored one. */
|
||||
export const restoreDismissedSuggestion = (
|
||||
dismissed: string[],
|
||||
statisticId: string
|
||||
): string[] => dismissed.filter((id) => id !== statisticId);
|
||||
@@ -3,8 +3,11 @@ import {
|
||||
mdiImageMultipleOutline,
|
||||
mdiLightningBolt,
|
||||
} from "@mdi/js";
|
||||
import type { ContextType } from "@lit/context";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||
import { consume } from "../../common/decorators/consume";
|
||||
import { consumeLocalize } from "../../common/decorators/consume-context-entry";
|
||||
import type { LocalizeFunc } from "../../common/translations/localize";
|
||||
import { CAMERA_STREAM_TYPE_NAMES } from "../../components/camera/ha-camera-stream-badge";
|
||||
@@ -21,6 +24,8 @@ import {
|
||||
type CameraStreamType,
|
||||
type StreamType,
|
||||
} from "../../data/camera-streams";
|
||||
import { fetchCloudStatus } from "../../data/cloud";
|
||||
import { apiContext, configContext } from "../../data/context";
|
||||
import { haStyleDialog, haStyleDialogFixedTop } from "../../resources/styles";
|
||||
import { DialogMixin } from "../dialog-mixin";
|
||||
import type { CameraStreamInfoDialogParams } from "./show-dialog-camera-stream-info";
|
||||
@@ -40,6 +45,34 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
@consumeLocalize()
|
||||
private _localize!: LocalizeFunc;
|
||||
|
||||
@consume({ context: apiContext })
|
||||
private _api!: ContextType<typeof apiContext>;
|
||||
|
||||
@consume({ context: configContext })
|
||||
private _hassConfig!: ContextType<typeof configContext>;
|
||||
|
||||
@state() private _cloudIceServers = false;
|
||||
|
||||
protected firstUpdated() {
|
||||
this._fetchCloudIceServers();
|
||||
}
|
||||
|
||||
// The same check that core uses to add the cloud TURN servers
|
||||
private async _fetchCloudIceServers() {
|
||||
if (!isComponentLoaded(this._hassConfig.config, "cloud")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const status = await fetchCloudStatus(this._api.callWS);
|
||||
this._cloudIceServers =
|
||||
status.logged_in &&
|
||||
status.active_subscription &&
|
||||
status.prefs.cloud_ice_servers_enabled;
|
||||
} catch (_err) {
|
||||
// Without the cloud status the label stays hidden
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (!this.params) {
|
||||
return nothing;
|
||||
@@ -124,6 +157,18 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
wrap-supporting-text
|
||||
>
|
||||
<ha-svg-icon slot="start" .path=${icon}></ha-svg-icon>
|
||||
${
|
||||
type === STREAM_TYPE_WEB_RTC && this._cloudIceServers
|
||||
? html`<span slot="headline" class="headline">
|
||||
${CAMERA_STREAM_TYPE_NAMES[type]}
|
||||
<span class="tag cloud"
|
||||
>${this._localize(
|
||||
"ui.dialogs.camera_stream_info.enhanced_by_cloud"
|
||||
)}</span
|
||||
>
|
||||
</span>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
current
|
||||
? html`<span slot="end" class="tag current"
|
||||
@@ -188,6 +233,20 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
|
||||
.headline {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: var(--ha-space-2);
|
||||
/* The row keeps the headline on one line, but a long tag must wrap */
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.tag.cloud {
|
||||
background-color: var(--ha-color-fill-primary-quiet-resting);
|
||||
color: var(--ha-color-on-primary-quiet);
|
||||
}
|
||||
|
||||
.tag.current {
|
||||
background-color: var(--ha-color-fill-success-quiet-resting);
|
||||
color: var(--ha-color-on-success-quiet);
|
||||
|
||||
@@ -22,7 +22,6 @@ import {
|
||||
coverHasPositionControls,
|
||||
coverHasTiltControls,
|
||||
coverModeAttribute,
|
||||
coverSupportsPosition,
|
||||
coverSupportsSetValue,
|
||||
defaultCoverMode,
|
||||
} from "../../../data/cover";
|
||||
@@ -164,7 +163,7 @@ class MoreInfoCover extends LitElement {
|
||||
if (!request || this._drag) {
|
||||
return undefined;
|
||||
}
|
||||
if (request.mode === "position" && !coverSupportsPosition(this.stateObj!)) {
|
||||
if (!coverSupportsSetValue(this.stateObj!, request.mode)) {
|
||||
return this._hint(request.value ? "requested_open" : "requested_closed");
|
||||
}
|
||||
return this._hint("requested", {
|
||||
|
||||
@@ -95,6 +95,23 @@ class DialogStartupProgress extends DialogMixin(LitElement) {
|
||||
.slice(0, MAX_SLOWEST);
|
||||
});
|
||||
}
|
||||
if (changedProps.has("_progress") || changedProps.has("_setups")) {
|
||||
this._loadTitles();
|
||||
}
|
||||
}
|
||||
|
||||
private _loadTitles() {
|
||||
const progress = this._progress
|
||||
? this._computeProgress(this._progress, this._config.config.state)
|
||||
: undefined;
|
||||
const domains = [
|
||||
...(progress?.active.map(([domain]) => domain) ?? []),
|
||||
...(progress?.failed ?? []),
|
||||
...(this._setups?.map((setup) => setup.domain) ?? []),
|
||||
];
|
||||
if (domains.length) {
|
||||
this._i18n.loadBackendTranslation("title", domains);
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
|
||||
+29
-1
@@ -75,11 +75,39 @@ const clearUrlParams = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const SERVER_CHECK_TIMEOUT = 10_000;
|
||||
|
||||
const checkServer = async () => {
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), SERVER_CHECK_TIMEOUT);
|
||||
try {
|
||||
const response = await fetch(`${hassUrl}/manifest.json`, {
|
||||
mode: "no-cors",
|
||||
cache: "no-store",
|
||||
signal: controller.signal,
|
||||
});
|
||||
if (response.status >= 500) {
|
||||
throw new Error(`Home Assistant responded with ${response.status}`);
|
||||
}
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
};
|
||||
|
||||
// The login page is never cached, so check the server is up before getAuth redirects to it.
|
||||
const loadTokensOrCheckServer = async () => {
|
||||
const tokens = loadTokens();
|
||||
if (!tokens || tokens.hassUrl !== hassUrl) {
|
||||
await checkServer();
|
||||
}
|
||||
return tokens;
|
||||
};
|
||||
|
||||
const authOptions = {
|
||||
hassUrl,
|
||||
limitHassInstance: true,
|
||||
saveTokens,
|
||||
loadTokens: () => Promise.resolve(loadTokens()),
|
||||
loadTokens: loadTokensOrCheckServer,
|
||||
};
|
||||
|
||||
const getAuthDroppingStaleCallback = async () => {
|
||||
|
||||
@@ -89,7 +89,11 @@ class HaBackupConfigAgents extends LitElement {
|
||||
|
||||
const retention = this.agentsConfig?.[agentId]?.retention;
|
||||
|
||||
if (retention) {
|
||||
if (retention && !this._value.includes(agentId)) {
|
||||
texts.push(
|
||||
this.hass.localize("ui.panel.config.backup.agents.retention_inactive")
|
||||
);
|
||||
} else if (retention) {
|
||||
if (retention.copies === null && retention.days === null) {
|
||||
texts.push(
|
||||
this.hass.localize("ui.panel.config.backup.agents.retention_all")
|
||||
|
||||
@@ -120,21 +120,34 @@ class HaConfigBackupDetails extends LitElement {
|
||||
</p>
|
||||
</div>
|
||||
`
|
||||
: html`<ha-backup-config-retention
|
||||
location-specific
|
||||
.headline=${this.hass.localize(
|
||||
`ui.panel.config.backup.location.retention_for_${isLocalAgent(this.agentId) ? "this_system" : "location"}`,
|
||||
{ location: agentName }
|
||||
)}
|
||||
.hass=${this.hass}
|
||||
.retention=${
|
||||
!this.config
|
||||
? undefined
|
||||
: this.config.agents[this.agentId]
|
||||
?.retention || null
|
||||
}
|
||||
@value-changed=${this._retentionChanged}
|
||||
></ha-backup-config-retention>`
|
||||
: html`${
|
||||
this.config &&
|
||||
!this.config.create_backup.agent_ids.includes(
|
||||
this.agentId
|
||||
)
|
||||
? html`<div class="card-content">
|
||||
<ha-alert alert-type="info">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.backup.location.retention_inactive"
|
||||
)}
|
||||
</ha-alert>
|
||||
</div>`
|
||||
: nothing
|
||||
}<ha-backup-config-retention
|
||||
location-specific
|
||||
.headline=${this.hass.localize(
|
||||
`ui.panel.config.backup.location.retention_for_${isLocalAgent(this.agentId) ? "this_system" : "location"}`,
|
||||
{ location: agentName }
|
||||
)}
|
||||
.hass=${this.hass}
|
||||
.retention=${
|
||||
!this.config
|
||||
? undefined
|
||||
: this.config.agents[this.agentId]
|
||||
?.retention || null
|
||||
}
|
||||
@value-changed=${this._retentionChanged}
|
||||
></ha-backup-config-retention>`
|
||||
}
|
||||
</ha-card>
|
||||
<ha-card>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { mdiFire, mdiFlash, mdiLightbulbOnOutline, mdiWater } from "@mdi/js";
|
||||
import type { ContextType } from "@lit/context";
|
||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import type { CSSResultGroup, TemplateResult } from "lit";
|
||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { repeat } from "lit/directives/repeat";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { consume } from "../../../../common/decorators/consume";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { consumeEntityStates } from "../../../../common/decorators/consume-context-entry";
|
||||
import { computeAreaName } from "../../../../common/entity/compute_area_name";
|
||||
import { getEntityAreaId } from "../../../../common/entity/context/get_entity_context";
|
||||
@@ -35,6 +36,7 @@ import type {
|
||||
import {
|
||||
computeEnergySuggestions,
|
||||
ENERGY_SUGGESTION_EDITORS,
|
||||
restoreDismissedSuggestion,
|
||||
updateDismissedSuggestions,
|
||||
} from "../../../../data/energy_suggestions";
|
||||
import {
|
||||
@@ -65,6 +67,8 @@ export class EnergySuggestions extends LitElement {
|
||||
|
||||
@property() public tab: EnergySuggestionTab = "electricity";
|
||||
|
||||
@property({ type: Boolean, attribute: false }) public showDismissed = false;
|
||||
|
||||
@state() private _statistics?: StatisticsMetaData[];
|
||||
|
||||
@state() private _dismissed?: string[];
|
||||
@@ -72,6 +76,11 @@ export class EnergySuggestions extends LitElement {
|
||||
// Dismissals not yet echoed by the subscription, so an older echo can't drop them
|
||||
@state() private _pendingDismissed: string[] = [];
|
||||
|
||||
// Restores not yet echoed by the subscription
|
||||
@state() private _pendingRestored: string[] = [];
|
||||
|
||||
private _reportedDismissedCount?: number;
|
||||
|
||||
@state() private _slots: Record<string, EnergySuggestionSlot> = {};
|
||||
|
||||
@state() private _loadFailed = false;
|
||||
@@ -114,27 +123,46 @@ export class EnergySuggestions extends LitElement {
|
||||
(
|
||||
statistics: StatisticsMetaData[],
|
||||
preferences: EnergyPreferences,
|
||||
dismissed: string[],
|
||||
states: HomeAssistant["states"],
|
||||
tab: EnergySuggestionTab
|
||||
) =>
|
||||
computeEnergySuggestions({
|
||||
statistics,
|
||||
preferences,
|
||||
dismissed,
|
||||
states,
|
||||
}).filter((suggestion) => suggestion.tab === tab)
|
||||
computeEnergySuggestions({ statistics, preferences, states }).filter(
|
||||
(suggestion) => suggestion.tab === tab
|
||||
)
|
||||
);
|
||||
|
||||
private _allDismissed = memoizeOne((stored: string[], pending: string[]) =>
|
||||
pending.length
|
||||
? [...stored, ...pending.filter((id) => !stored.includes(id))]
|
||||
: stored
|
||||
private _splitSuggestions = memoizeOne(
|
||||
(all: EnergyMeterSuggestion[], dismissed: string[]) => ({
|
||||
suggestions: all.filter(
|
||||
(suggestion) => !dismissed.includes(suggestion.statisticId)
|
||||
),
|
||||
dismissedSuggestions: all.filter((suggestion) =>
|
||||
dismissed.includes(suggestion.statisticId)
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
private _allDismissed = memoizeOne(
|
||||
(stored: string[], pending: string[], restored: string[]) =>
|
||||
[...stored, ...pending.filter((id) => !stored.includes(id))].filter(
|
||||
(id) => !restored.includes(id)
|
||||
)
|
||||
);
|
||||
|
||||
private get _currentDismissed(): string[] {
|
||||
return this._allDismissed(
|
||||
this._dismissed!,
|
||||
this._pendingDismissed,
|
||||
this._pendingRestored
|
||||
);
|
||||
}
|
||||
|
||||
// Kept live so a dismiss in another tab isn't overwritten by this one.
|
||||
private _unsubDismissed?: Promise<UnsubscribeFunc>;
|
||||
|
||||
// Each save builds on the list the previous one stored
|
||||
private _saveQueue: Promise<unknown> = Promise.resolve();
|
||||
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._load();
|
||||
@@ -161,6 +189,9 @@ export class EnergySuggestions extends LitElement {
|
||||
this._pendingDismissed = this._pendingDismissed.filter(
|
||||
(id) => !dismissed.includes(id)
|
||||
);
|
||||
this._pendingRestored = this._pendingRestored.filter((id) =>
|
||||
dismissed.includes(id)
|
||||
);
|
||||
}
|
||||
);
|
||||
try {
|
||||
@@ -203,14 +234,8 @@ export class EnergySuggestions extends LitElement {
|
||||
if (!this._statistics || !this._dismissed) {
|
||||
return nothing;
|
||||
}
|
||||
const suggestions = this._computeSuggestions(
|
||||
this._statistics,
|
||||
this.preferences,
|
||||
this._allDismissed(this._dismissed, this._pendingDismissed),
|
||||
this._states,
|
||||
this.tab
|
||||
);
|
||||
if (!suggestions.length) {
|
||||
const { suggestions, dismissedSuggestions, showDismissed } = this._view()!;
|
||||
if (!suggestions.length && !showDismissed) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
@@ -218,27 +243,67 @@ export class EnergySuggestions extends LitElement {
|
||||
<ha-card>
|
||||
<h1 class="card-header">
|
||||
<ha-svg-icon .path=${mdiLightbulbOnOutline}></ha-svg-icon>
|
||||
${this._i18n.localize("ui.panel.config.energy.suggestions.title", {
|
||||
count: suggestions.length,
|
||||
})}
|
||||
${
|
||||
suggestions.length
|
||||
? this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.title",
|
||||
{
|
||||
count: suggestions.length,
|
||||
}
|
||||
)
|
||||
: this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.dismissed_title"
|
||||
)
|
||||
}
|
||||
</h1>
|
||||
<div class="card-content">
|
||||
<p>
|
||||
${this._i18n.localize("ui.panel.config.energy.suggestions.sub")}
|
||||
</p>
|
||||
<div class="items-container">
|
||||
${repeat(
|
||||
suggestions,
|
||||
(suggestion) => suggestion.statisticId,
|
||||
(suggestion) => this._renderSuggestion(suggestion)
|
||||
${this._i18n.localize(
|
||||
suggestions.length
|
||||
? "ui.panel.config.energy.suggestions.sub"
|
||||
: "ui.panel.config.energy.suggestions.dismissed_sub"
|
||||
)}
|
||||
</div>
|
||||
</p>
|
||||
${
|
||||
suggestions.length
|
||||
? html`<div class="items-container">
|
||||
${repeat(
|
||||
suggestions,
|
||||
(suggestion) => suggestion.statisticId,
|
||||
(suggestion) => this._renderSuggestion(suggestion, false)
|
||||
)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
showDismissed
|
||||
? html`${
|
||||
suggestions.length
|
||||
? html`<h3>
|
||||
${this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.dismissed"
|
||||
)}
|
||||
</h3>`
|
||||
: nothing
|
||||
}
|
||||
<div class="items-container">
|
||||
${repeat(
|
||||
dismissedSuggestions,
|
||||
(suggestion) => suggestion.statisticId,
|
||||
(suggestion) => this._renderSuggestion(suggestion, true)
|
||||
)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
</ha-card>
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderSuggestion(suggestion: EnergyMeterSuggestion) {
|
||||
private _renderSuggestion(
|
||||
suggestion: EnergyMeterSuggestion,
|
||||
dismissed: boolean
|
||||
) {
|
||||
const slot = this._slotFor(suggestion);
|
||||
const label = getStatisticLabel(
|
||||
this._states,
|
||||
@@ -300,9 +365,11 @@ export class EnergySuggestions extends LitElement {
|
||||
appearance="plain"
|
||||
variant="neutral"
|
||||
.suggestion=${suggestion}
|
||||
@click=${this._dismiss}
|
||||
@click=${dismissed ? this._restore : this._dismiss}
|
||||
>${this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.dismiss"
|
||||
dismissed
|
||||
? "ui.panel.config.energy.suggestions.restore"
|
||||
: "ui.panel.config.energy.suggestions.dismiss"
|
||||
)}</ha-button
|
||||
>
|
||||
</div>
|
||||
@@ -341,14 +408,13 @@ export class EnergySuggestions extends LitElement {
|
||||
.suggestion;
|
||||
const statisticId = suggestion.statisticId;
|
||||
this._pendingDismissed = [...this._pendingDismissed, statisticId];
|
||||
this._pendingRestored = this._pendingRestored.filter(
|
||||
(id) => id !== statisticId
|
||||
);
|
||||
try {
|
||||
await saveFrontendUserData(this._connection.connection, "energy", {
|
||||
dismissed_suggestions: updateDismissedSuggestions(
|
||||
this._allDismissed(this._dismissed!, this._pendingDismissed),
|
||||
statisticId,
|
||||
this._statistics!
|
||||
),
|
||||
});
|
||||
await this._saveDismissed((dismissed) =>
|
||||
updateDismissedSuggestions(dismissed, statisticId, this._statistics!)
|
||||
);
|
||||
} catch (err: any) {
|
||||
this._pendingDismissed = this._pendingDismissed.filter(
|
||||
(id) => id !== statisticId
|
||||
@@ -362,6 +428,70 @@ export class EnergySuggestions extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _view() {
|
||||
if (this._loadFailed || !this._statistics || !this._dismissed) {
|
||||
return undefined;
|
||||
}
|
||||
const { suggestions, dismissedSuggestions } = this._splitSuggestions(
|
||||
this._computeSuggestions(
|
||||
this._statistics,
|
||||
this.preferences,
|
||||
this._states,
|
||||
this.tab
|
||||
),
|
||||
this._currentDismissed
|
||||
);
|
||||
return {
|
||||
suggestions,
|
||||
dismissedSuggestions,
|
||||
showDismissed: this.showDismissed && dismissedSuggestions.length > 0,
|
||||
};
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues): void {
|
||||
super.updated(changedProps);
|
||||
const count = this._view()?.dismissedSuggestions.length ?? 0;
|
||||
if (count !== this._reportedDismissedCount) {
|
||||
this._reportedDismissedCount = count;
|
||||
fireEvent(this, "energy-suggestions-dismissed-count", { count });
|
||||
}
|
||||
}
|
||||
|
||||
private async _restore(ev: Event) {
|
||||
const suggestion: EnergyMeterSuggestion = (ev.currentTarget as any)
|
||||
.suggestion;
|
||||
const statisticId = suggestion.statisticId;
|
||||
this._pendingRestored = [...this._pendingRestored, statisticId];
|
||||
this._pendingDismissed = this._pendingDismissed.filter(
|
||||
(id) => id !== statisticId
|
||||
);
|
||||
try {
|
||||
await this._saveDismissed((dismissed) =>
|
||||
restoreDismissedSuggestion(dismissed, statisticId)
|
||||
);
|
||||
} catch (err: any) {
|
||||
this._pendingRestored = this._pendingRestored.filter(
|
||||
(id) => id !== statisticId
|
||||
);
|
||||
showAlertDialog(this, {
|
||||
title: this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.restore_failed"
|
||||
),
|
||||
text: err.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private _saveDismissed(update: (dismissed: string[]) => string[]) {
|
||||
const save = this._saveQueue.then(() =>
|
||||
saveFrontendUserData(this._connection.connection, "energy", {
|
||||
dismissed_suggestions: update(this._dismissed!),
|
||||
})
|
||||
);
|
||||
this._saveQueue = save.catch(() => undefined);
|
||||
return save;
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return [
|
||||
haStyle,
|
||||
@@ -407,4 +537,8 @@ declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-energy-suggestions": EnergySuggestions;
|
||||
}
|
||||
|
||||
interface HASSDomEvents {
|
||||
"energy-suggestions-dismissed-count": { count: number };
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import "../../../layouts/hass-error-screen";
|
||||
import {
|
||||
mdiDotsVertical,
|
||||
mdiDownload,
|
||||
mdiEye,
|
||||
mdiEyeOff,
|
||||
mdiFire,
|
||||
mdiLightningBolt,
|
||||
mdiViewDashboardEdit,
|
||||
@@ -10,6 +13,7 @@ import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { cache } from "lit/directives/cache";
|
||||
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||
import { navigate } from "../../../common/navigate";
|
||||
import type {
|
||||
EnergyPreferencesValidation,
|
||||
@@ -38,6 +42,9 @@ import "./components/ha-energy-battery-settings";
|
||||
import "./components/ha-energy-gas-settings";
|
||||
import "./components/ha-energy-water-settings";
|
||||
import "./components/ha-energy-suggestions";
|
||||
import "../../../components/ha-dropdown";
|
||||
import "../../../components/ha-dropdown-item";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import { fileDownload } from "../../../util/file_download";
|
||||
import { showToast } from "../../../util/toast";
|
||||
import type { PageNavigation } from "../../../layouts/hass-tabs-subpage";
|
||||
@@ -98,6 +105,11 @@ class HaConfigEnergy extends LitElement {
|
||||
|
||||
@state() private _statsMetadata?: Record<string, StatisticsMetaData>;
|
||||
|
||||
// Dismissed meters on the current tab, as counted by the suggestions card
|
||||
@state() private _dismissedSuggestions = 0;
|
||||
|
||||
@state() private _showDismissedSuggestions = false;
|
||||
|
||||
private get _currTab(): string {
|
||||
return this.route.path.split("/")[1] || "electricity";
|
||||
}
|
||||
@@ -105,6 +117,10 @@ class HaConfigEnergy extends LitElement {
|
||||
protected willUpdate(changedProperties: PropertyValues<this>) {
|
||||
if (changedProperties.has("route")) {
|
||||
const [, tab, kind, ...key] = this.route.path.split("/");
|
||||
const oldTab = changedProperties.get("route")?.path.split("/")[1];
|
||||
if (oldTab !== undefined && oldTab !== tab) {
|
||||
this._showDismissedSuggestions = false;
|
||||
}
|
||||
if (!tab || !TABS.some((t) => t.path.endsWith(`/${tab}`))) {
|
||||
navigate(`${this.route.prefix}/electricity${location.search}`, {
|
||||
replace: true,
|
||||
@@ -175,6 +191,35 @@ class HaConfigEnergy extends LitElement {
|
||||
)}
|
||||
@click=${this._downloadDiagnostics}
|
||||
></ha-icon-button>
|
||||
${
|
||||
this._dismissedSuggestions
|
||||
? html`<ha-dropdown
|
||||
@wa-select=${this._toggleDismissedSuggestions}
|
||||
>
|
||||
<ha-icon-button
|
||||
slot="trigger"
|
||||
.label=${this.hass.localize("ui.common.menu")}
|
||||
.path=${mdiDotsVertical}
|
||||
></ha-icon-button>
|
||||
<ha-dropdown-item value="toggle_dismissed">
|
||||
<ha-svg-icon
|
||||
slot="icon"
|
||||
.path=${this._showDismissedSuggestions ? mdiEyeOff : mdiEye}
|
||||
></ha-svg-icon>
|
||||
${
|
||||
this._showDismissedSuggestions
|
||||
? this.hass.localize(
|
||||
"ui.panel.config.energy.suggestions.hide_dismissed"
|
||||
)
|
||||
: this.hass.localize(
|
||||
"ui.panel.config.energy.suggestions.show_dismissed",
|
||||
{ count: this._dismissedSuggestions }
|
||||
)
|
||||
}
|
||||
</ha-dropdown-item>
|
||||
</ha-dropdown>`
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
<ha-alert>
|
||||
${this.hass.localize("ui.panel.config.energy.new_device_info")}
|
||||
@@ -184,6 +229,8 @@ class HaConfigEnergy extends LitElement {
|
||||
.preferences=${this._preferences!}
|
||||
.listPath=${`${this.route.prefix}/${this._currTab}`}
|
||||
.tab=${this._currTab}
|
||||
.showDismissed=${this._showDismissedSuggestions}
|
||||
@energy-suggestions-dismissed-count=${this._dismissedSuggestionsChanged}
|
||||
></ha-energy-suggestions>
|
||||
${cache(this._renderTabContent())}
|
||||
</div>
|
||||
@@ -446,6 +493,19 @@ class HaConfigEnergy extends LitElement {
|
||||
this._statsMetadata = statsMetadata;
|
||||
}
|
||||
|
||||
private _dismissedSuggestionsChanged(
|
||||
ev: HASSDomEvent<HASSDomEvents["energy-suggestions-dismissed-count"]>
|
||||
) {
|
||||
this._dismissedSuggestions = ev.detail.count;
|
||||
if (!this._dismissedSuggestions) {
|
||||
this._showDismissedSuggestions = false;
|
||||
}
|
||||
}
|
||||
|
||||
private _toggleDismissedSuggestions() {
|
||||
this._showDismissedSuggestions = !this._showDismissedSuggestions;
|
||||
}
|
||||
|
||||
private _customise() {
|
||||
if (!this._preferences) {
|
||||
return;
|
||||
|
||||
+5
-46
@@ -16,12 +16,14 @@ import "../../../../../components/item/ha-list-item-base";
|
||||
import "../../../../../components/item/ha-list-item-button";
|
||||
import "../../../../../components/list/ha-list-base";
|
||||
import type {
|
||||
BluetoothAdapterDevice,
|
||||
BluetoothAllocationsData,
|
||||
BluetoothScannerState,
|
||||
BluetoothScannersDetails,
|
||||
HaScannerType,
|
||||
} from "../../../../../data/bluetooth";
|
||||
import {
|
||||
getBluetoothAdapters,
|
||||
isScannerStateMismatch,
|
||||
subscribeBluetoothConnectionAllocations,
|
||||
subscribeBluetoothScannerState,
|
||||
@@ -176,52 +178,11 @@ export class BluetoothAdapterInfoPage extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _getBluetoothDevices = memoizeOne(
|
||||
(devices: HomeAssistant["devices"], configEntries: ConfigEntry[]) => {
|
||||
const entryMap = new Map(configEntries.map((e) => [e.entry_id, e]));
|
||||
|
||||
const enabledDevices: {
|
||||
device: DeviceRegistryEntry;
|
||||
entry: ConfigEntry;
|
||||
}[] = [];
|
||||
const disabledDevices: {
|
||||
device: DeviceRegistryEntry;
|
||||
entry: ConfigEntry;
|
||||
}[] = [];
|
||||
const matchedEntryIds = new Set<string>();
|
||||
|
||||
for (const device of Object.values(devices)) {
|
||||
const btConnection = device.connections.find(
|
||||
(c) => c[0] === "bluetooth"
|
||||
);
|
||||
if (!btConnection) {
|
||||
continue;
|
||||
}
|
||||
const entry = device.config_entries
|
||||
.map((id) => entryMap.get(id))
|
||||
.find((e) => e !== undefined);
|
||||
if (!entry) {
|
||||
continue;
|
||||
}
|
||||
matchedEntryIds.add(entry.entry_id);
|
||||
if (entry.disabled_by !== null) {
|
||||
disabledDevices.push({ device, entry });
|
||||
} else {
|
||||
enabledDevices.push({ device, entry });
|
||||
}
|
||||
}
|
||||
|
||||
const disabledEntriesWithoutDevice = configEntries.filter(
|
||||
(e) => e.disabled_by !== null && !matchedEntryIds.has(e.entry_id)
|
||||
);
|
||||
|
||||
return { enabledDevices, disabledDevices, disabledEntriesWithoutDevice };
|
||||
}
|
||||
);
|
||||
private _getBluetoothAdapters = memoizeOne(getBluetoothAdapters);
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const { enabledDevices, disabledDevices, disabledEntriesWithoutDevice } =
|
||||
this._getBluetoothDevices(this.hass.devices, this._configEntries);
|
||||
this._getBluetoothAdapters(this.hass.devices, this._configEntries);
|
||||
|
||||
return html`
|
||||
<hass-subpage
|
||||
@@ -301,9 +262,7 @@ export class BluetoothAdapterInfoPage extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderAdaptersList(
|
||||
devices: { device: DeviceRegistryEntry; entry: ConfigEntry }[]
|
||||
) {
|
||||
private _renderAdaptersList(devices: BluetoothAdapterDevice[]) {
|
||||
if (devices.length === 0) {
|
||||
return html`<ha-list-item-base>
|
||||
<div slot="headline">
|
||||
|
||||
+122
-49
@@ -11,18 +11,24 @@ import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import type { CSSResultGroup, TemplateResult } from "lit";
|
||||
import { LitElement, css, html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import "../../../../../components/animation/ha-fade-in";
|
||||
import "../../../../../components/ha-alert";
|
||||
import "../../../../../components/ha-button";
|
||||
import "../../../../../components/ha-card";
|
||||
import "../../../../../components/ha-icon-next";
|
||||
import "../../../../../components/ha-svg-icon";
|
||||
import "../../../../../components/item/ha-list-item-button";
|
||||
import "../../../../../components/list/ha-list-nav";
|
||||
import "../../../../../components/skeleton/ha-skeleton";
|
||||
import "../../../../../components/skeleton/ha-skeleton-text";
|
||||
import type {
|
||||
BluetoothAllocationsData,
|
||||
BluetoothDeviceData,
|
||||
BluetoothScannerState,
|
||||
} from "../../../../../data/bluetooth";
|
||||
import {
|
||||
getBluetoothAdapters,
|
||||
isScannerStateMismatch,
|
||||
subscribeBluetoothAdvertisements,
|
||||
subscribeBluetoothConnectionAllocations,
|
||||
@@ -34,6 +40,7 @@ import "../../../../../layouts/hass-subpage";
|
||||
import { haStyle } from "../../../../../resources/styles";
|
||||
import type { HomeAssistant, Route } from "../../../../../types";
|
||||
import { brandsUrl } from "../../../../../util/brands-url";
|
||||
import { getWsErrorMessage } from "../../../../../util/ws-error";
|
||||
|
||||
@customElement("bluetooth-config-dashboard")
|
||||
export class BluetoothConfigDashboard extends LitElement {
|
||||
@@ -45,7 +52,9 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
|
||||
@property({ attribute: "is-wide", type: Boolean }) public isWide = false;
|
||||
|
||||
@state() private _configEntries: ConfigEntry[] = [];
|
||||
@state() private _configEntries?: ConfigEntry[];
|
||||
|
||||
@state() private _configEntriesError?: string;
|
||||
|
||||
@state() private _connectionAllocationData: BluetoothAllocationsData[] = [];
|
||||
|
||||
@@ -69,11 +78,17 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private async _loadConfigEntries(): Promise<void> {
|
||||
this._configEntries = await getConfigEntries(this.hass, {
|
||||
domain: "bluetooth",
|
||||
});
|
||||
}
|
||||
private _loadConfigEntries = async (): Promise<void> => {
|
||||
this._configEntriesError = undefined;
|
||||
try {
|
||||
this._configEntries = await getConfigEntries(this.hass, {
|
||||
domain: "bluetooth",
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
this._configEntriesError =
|
||||
getWsErrorMessage(err) || this.hass.localize("ui.common.unknown_error");
|
||||
}
|
||||
};
|
||||
|
||||
private async _subscribeBluetoothConnectionAllocations(): Promise<void> {
|
||||
if (this._unsubConnectionAllocations) {
|
||||
@@ -131,11 +146,17 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _getBluetoothAdapters = memoizeOne(getBluetoothAdapters);
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const enabledEntries = this._configEntries.filter(
|
||||
(e) => e.disabled_by === null
|
||||
);
|
||||
const adapterCount = enabledEntries.length;
|
||||
// The device registry is null until it has loaded.
|
||||
const adapterCount =
|
||||
this._configEntries && this.hass.devices
|
||||
? this._getBluetoothAdapters(this.hass.devices, this._configEntries)
|
||||
.enabledDevices.length
|
||||
: undefined;
|
||||
const error = this._configEntriesError;
|
||||
const loading = adapterCount === undefined && !error;
|
||||
const totalSlots = this._connectionAllocationData.reduce(
|
||||
(sum, a) => sum + a.slots,
|
||||
0
|
||||
@@ -163,40 +184,67 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
back-path="/config/connectivity"
|
||||
>
|
||||
<div class="container">
|
||||
<ha-card class="content network-status">
|
||||
<div class="card-content">
|
||||
<div class="heading">
|
||||
<div class="icon ${status}">
|
||||
<ha-svg-icon .path=${statusIcon}></ha-svg-icon>
|
||||
</div>
|
||||
<div class="details">
|
||||
${this.hass.localize(
|
||||
`ui.panel.config.bluetooth.status_${status}`
|
||||
)}<br />
|
||||
<small>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.bluetooth.connections_summary",
|
||||
{ used: usedSlots, total: totalSlots }
|
||||
)}
|
||||
</small>
|
||||
</div>
|
||||
<img
|
||||
class="logo"
|
||||
alt="Bluetooth"
|
||||
crossorigin="anonymous"
|
||||
referrerpolicy="no-referrer"
|
||||
src=${brandsUrl(
|
||||
{
|
||||
domain: "bluetooth",
|
||||
type: "icon",
|
||||
darkOptimized: this.hass.themes?.darkMode,
|
||||
},
|
||||
this.hass.auth.data.hassUrl
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</ha-card>
|
||||
${
|
||||
error
|
||||
? html`<ha-alert alert-type="error" class="content">
|
||||
${error}
|
||||
<ha-button
|
||||
slot="action"
|
||||
appearance="plain"
|
||||
@click=${this._loadConfigEntries}
|
||||
>
|
||||
${this.hass.localize("ui.common.retry")}
|
||||
</ha-button>
|
||||
</ha-alert>`
|
||||
: html`<ha-card class="content network-status">
|
||||
<div class="card-content">
|
||||
<div class="heading">
|
||||
${
|
||||
loading
|
||||
? html`<ha-fade-in .duration=${300} easing="ease-in">
|
||||
<ha-skeleton
|
||||
class="status-icon"
|
||||
role="progressbar"
|
||||
aria-label=${this.hass.localize("ui.common.loading")}
|
||||
></ha-skeleton>
|
||||
</ha-fade-in>`
|
||||
: html`<div class="icon ${status}">
|
||||
<ha-svg-icon .path=${statusIcon}></ha-svg-icon>
|
||||
</div>`
|
||||
}
|
||||
<div class="details">
|
||||
${
|
||||
loading
|
||||
? this._renderTextSkeleton()
|
||||
: this.hass.localize(
|
||||
`ui.panel.config.bluetooth.status_${status}`
|
||||
)
|
||||
}<br />
|
||||
<small>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.bluetooth.connections_summary",
|
||||
{ used: usedSlots, total: totalSlots }
|
||||
)}
|
||||
</small>
|
||||
</div>
|
||||
<img
|
||||
class="logo"
|
||||
alt="Bluetooth"
|
||||
crossorigin="anonymous"
|
||||
referrerpolicy="no-referrer"
|
||||
src=${brandsUrl(
|
||||
{
|
||||
domain: "bluetooth",
|
||||
type: "icon",
|
||||
darkOptimized: this.hass.themes?.darkMode,
|
||||
},
|
||||
this.hass.auth.data.hassUrl
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</ha-card>`
|
||||
}
|
||||
|
||||
<ha-card class="network-card">
|
||||
<div class="card-header">
|
||||
@@ -224,10 +272,17 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
.path=${mdiAccessPoint}
|
||||
></ha-svg-icon>
|
||||
<div slot="headline">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.bluetooth.adapters_count",
|
||||
{ count: adapterCount }
|
||||
)}
|
||||
${
|
||||
// A link needs its name, so no skeleton while loading
|
||||
adapterCount === undefined
|
||||
? this.hass.localize(
|
||||
"ui.panel.config.bluetooth.adapter_info_title"
|
||||
)
|
||||
: this.hass.localize(
|
||||
"ui.panel.config.bluetooth.adapters_count",
|
||||
{ count: adapterCount }
|
||||
)
|
||||
}
|
||||
</div>
|
||||
<ha-icon-next slot="end"></ha-icon-next>
|
||||
</ha-list-item-button>
|
||||
@@ -268,6 +323,15 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderTextSkeleton() {
|
||||
return html`<ha-fade-in .duration=${300} easing="ease-in">
|
||||
<ha-skeleton-text
|
||||
role="progressbar"
|
||||
aria-label=${this.hass.localize("ui.common.loading")}
|
||||
></ha-skeleton-text>
|
||||
</ha-fade-in>`;
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return [
|
||||
haStyle,
|
||||
@@ -276,7 +340,9 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
padding: var(--ha-space-2) var(--ha-content-gutter) var(--ha-space-4);
|
||||
}
|
||||
|
||||
ha-card {
|
||||
ha-card,
|
||||
ha-alert {
|
||||
display: block;
|
||||
margin: 0px auto var(--ha-space-4);
|
||||
max-width: var(--ha-content-width-narrow);
|
||||
}
|
||||
@@ -326,6 +392,13 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
--icon-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.network-status div.heading .status-icon {
|
||||
display: block;
|
||||
width: var(--ha-space-10);
|
||||
height: var(--ha-space-10);
|
||||
--ha-skeleton-border-radius: var(--ha-border-radius-2xl);
|
||||
}
|
||||
|
||||
.network-status div.heading .icon.online {
|
||||
--icon-color: var(--success-color);
|
||||
}
|
||||
|
||||
@@ -504,7 +504,7 @@ export class HaGridLayoutSlider extends LitElement {
|
||||
left 180ms ease-in-out,
|
||||
bottom 180ms ease-in-out;
|
||||
--handle-spacing: calc(2 * var(--handle-margin) + var(--handle-size));
|
||||
--slider-tooltip-margin: 0px;
|
||||
--slider-tooltip-margin: var(--ha-space-1);
|
||||
--slider-tooltip-range: 100%;
|
||||
--slider-tooltip-offset: 0px;
|
||||
--slider-tooltip-position: calc(
|
||||
|
||||
@@ -420,7 +420,7 @@ export class HuiCardLayoutEditor extends LitElement {
|
||||
}
|
||||
ha-grid-size-picker {
|
||||
display: block;
|
||||
margin: 16px auto;
|
||||
margin: var(--ha-space-4) auto;
|
||||
direction: ltr;
|
||||
}
|
||||
`,
|
||||
|
||||
@@ -138,10 +138,13 @@ export const statusesOfTab = (
|
||||
tab === "installed" ? INSTALLED_STATUS_ORDER : STATUS_ORDER;
|
||||
|
||||
// The filters are kept for every tab. A status picked on another tab that this
|
||||
// one can't list is left out here, instead of leaving the table empty.
|
||||
// one can't list is left out here, instead of leaving the table empty. So is
|
||||
// an integration category nothing on this tab is in, when the ones it lists
|
||||
// are given. Before the repositories load it lists none, so the URL keeps them.
|
||||
export const filtersOfTab = (
|
||||
filters: RepositoryFilters,
|
||||
tab: MarketplaceTab
|
||||
tab: MarketplaceTab,
|
||||
integrationCategories?: readonly string[]
|
||||
): RepositoryFilters => {
|
||||
const statuses: readonly string[] = statusesOfTab(tab);
|
||||
|
||||
@@ -150,25 +153,31 @@ export const filtersOfTab = (
|
||||
[STATUS_FILTER]: filters[STATUS_FILTER]?.filter((status) =>
|
||||
statuses.includes(status)
|
||||
),
|
||||
[INTEGRATION_CATEGORY_FILTER]: integrationCategories
|
||||
? filters[INTEGRATION_CATEGORY_FILTER]?.filter((slug) =>
|
||||
integrationCategories.includes(slug)
|
||||
)
|
||||
: filters[INTEGRATION_CATEGORY_FILTER],
|
||||
};
|
||||
};
|
||||
|
||||
// The status pane only sends what this tab lists, so statuses picked on another
|
||||
// tab that this one can't list are kept for when that tab is opened again
|
||||
// A pane only sends what it lists, so what was picked on another tab that this
|
||||
// one can't list is kept for when that tab is opened again
|
||||
export const paneFilterOfTab = (
|
||||
previous: string[] | undefined,
|
||||
listed: readonly string[],
|
||||
picked: string[] = []
|
||||
): string[] => [
|
||||
...(previous?.filter((value) => !listed.includes(value)) ?? []),
|
||||
...picked,
|
||||
];
|
||||
|
||||
export const statusFilterOfTab = (
|
||||
filters: RepositoryFilters,
|
||||
tab: MarketplaceTab,
|
||||
picked: string[] = []
|
||||
): string[] => {
|
||||
const statuses: readonly string[] = statusesOfTab(tab);
|
||||
|
||||
return [
|
||||
...(filters[STATUS_FILTER]?.filter(
|
||||
(status) => !statuses.includes(status)
|
||||
) ?? []),
|
||||
...picked,
|
||||
];
|
||||
};
|
||||
picked?: string[]
|
||||
): string[] =>
|
||||
paneFilterOfTab(filters[STATUS_FILTER], statusesOfTab(tab), picked);
|
||||
|
||||
const matchesFilters = (
|
||||
repository: RepositoryBase,
|
||||
|
||||
@@ -100,6 +100,7 @@ import {
|
||||
filterRepositories,
|
||||
filtersOfTab,
|
||||
marketplaceUpdateEntityIds,
|
||||
paneFilterOfTab,
|
||||
skippedUpdateRepositories,
|
||||
SOURCE_FILTER,
|
||||
SOURCE_ORDER,
|
||||
@@ -345,15 +346,7 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const marketplaceRepositories = this._applySkippedUpdates(
|
||||
this.marketplace.repositories,
|
||||
this._skippedUpdateRepositories(
|
||||
this._marketplaceUpdateEntityIds,
|
||||
this._entities,
|
||||
this._devices,
|
||||
this._states ?? {}
|
||||
)
|
||||
);
|
||||
const marketplaceRepositories = this._marketplaceRepositories();
|
||||
const tabs = this._tabs(
|
||||
this._i18n.localize,
|
||||
marketplaceRepositories.filter((repository) => repository.pending_upgrade)
|
||||
@@ -374,19 +367,22 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
</hass-tabs-subpage>`;
|
||||
}
|
||||
|
||||
const filters = this._filtersOfTab(this._filters, this.tab);
|
||||
const tabRepositories = this._repositoriesOfTab(
|
||||
marketplaceRepositories,
|
||||
this.tab
|
||||
);
|
||||
const integrationCategoryStates = this._tabIntegrationCategoryStates();
|
||||
const filters = this._filtersOfTab(
|
||||
this._filters,
|
||||
this.tab,
|
||||
this._stateValues(integrationCategoryStates)
|
||||
);
|
||||
const repositories = this._filterRepositories(
|
||||
this._repositoriesOfTab(marketplaceRepositories, this.tab),
|
||||
tabRepositories,
|
||||
this._i18n.localize,
|
||||
filters
|
||||
);
|
||||
|
||||
const integrationCategoryStates = this._integrationCategoryStates(
|
||||
this.marketplace.repositories,
|
||||
this._i18n.localize,
|
||||
this._integrationCategoryIcons
|
||||
);
|
||||
|
||||
return html`<hass-tabs-subpage-data-table
|
||||
.tabs=${tabs}
|
||||
.columns=${this._columns(
|
||||
@@ -506,7 +502,7 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
.label=${this._i18n.localize(
|
||||
"ui.panel.marketplace.filters.integration_category"
|
||||
)}
|
||||
.value=${this._filters[INTEGRATION_CATEGORY_FILTER]}
|
||||
.value=${filters[INTEGRATION_CATEGORY_FILTER]}
|
||||
.states=${integrationCategoryStates}
|
||||
.narrow=${this.narrow}
|
||||
@data-table-filter-changed=${this._integrationCategoryFilterChanged}
|
||||
@@ -591,6 +587,18 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
|
||||
private _tabs = memoize(marketplaceTabs);
|
||||
|
||||
private _marketplaceRepositories(): MarketplaceRepository[] {
|
||||
return this._applySkippedUpdates(
|
||||
this.marketplace.repositories,
|
||||
this._skippedUpdateRepositories(
|
||||
this._marketplaceUpdateEntityIds,
|
||||
this._entities,
|
||||
this._devices,
|
||||
this._states ?? {}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private _repositoriesOfTab = memoize(repositoriesOfTab);
|
||||
|
||||
private _skippedUpdateRepositories = memoize(skippedUpdateRepositories);
|
||||
@@ -607,6 +615,10 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
|
||||
private _filtersOfTab = memoize(filtersOfTab);
|
||||
|
||||
private _stateValues = memoize((options: { value: string }[]) =>
|
||||
options.map((option) => option.value)
|
||||
);
|
||||
|
||||
private _columns = memoize(
|
||||
(
|
||||
localizeFunc: LocalizeFunc,
|
||||
@@ -1123,6 +1135,14 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
}
|
||||
);
|
||||
|
||||
private _tabIntegrationCategoryStates() {
|
||||
return this._integrationCategoryStates(
|
||||
this._repositoriesOfTab(this._marketplaceRepositories(), this.tab),
|
||||
this._i18n.localize,
|
||||
this._integrationCategoryIcons
|
||||
);
|
||||
}
|
||||
|
||||
private _sourceStates = memoize((localize: LocalizeFunc) =>
|
||||
SOURCE_ORDER.map((source) => ({
|
||||
value: source,
|
||||
@@ -1219,15 +1239,24 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
private _integrationCategoryFilterChanged(
|
||||
ev: CustomEvent<{ value: string[] }>
|
||||
) {
|
||||
const listed = this._stateValues(this._tabIntegrationCategoryStates());
|
||||
const filters = {
|
||||
...this._filters,
|
||||
[INTEGRATION_CATEGORY_FILTER]: ev.detail.value,
|
||||
[INTEGRATION_CATEGORY_FILTER]: paneFilterOfTab(
|
||||
this._filters[INTEGRATION_CATEGORY_FILTER],
|
||||
listed,
|
||||
ev.detail.value
|
||||
),
|
||||
};
|
||||
|
||||
if (this._isUserChange(filters)) {
|
||||
this._storageFilters = {
|
||||
...this._storageFilters,
|
||||
[INTEGRATION_CATEGORY_FILTER]: ev.detail.value,
|
||||
[INTEGRATION_CATEGORY_FILTER]: paneFilterOfTab(
|
||||
this._storageFilters[INTEGRATION_CATEGORY_FILTER],
|
||||
listed,
|
||||
ev.detail.value
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -197,13 +197,12 @@ export class HaMarketplaceRepositoryDashboard extends LitElement {
|
||||
|
||||
private _settingPreReleases = new Set<string>();
|
||||
|
||||
private _loadingIntegrationCategoryIcons = false;
|
||||
|
||||
protected async firstUpdated(
|
||||
changedProperties: PropertyValues<this>
|
||||
): Promise<void> {
|
||||
super.firstUpdated(changedProperties);
|
||||
getIntegrationCategoryIcons(this._connection.connection).then((icons) => {
|
||||
this._integrationCategoryIcons = icons;
|
||||
});
|
||||
await this._loadRepository();
|
||||
}
|
||||
|
||||
@@ -324,24 +323,29 @@ export class HaMarketplaceRepositoryDashboard extends LitElement {
|
||||
this._fetchRepository(existing.id);
|
||||
}
|
||||
|
||||
protected willUpdate(changedProps: PropertyValues<this>): void {
|
||||
protected willUpdate(changedProps: PropertyValues): void {
|
||||
super.willUpdate(changedProps);
|
||||
|
||||
// The router reuses this element when going from one repository to
|
||||
// another, the first one is loaded by firstUpdated.
|
||||
const previousRoute = changedProps.get("route");
|
||||
const previousRoute = changedProps.get("route") as Route | undefined;
|
||||
if (
|
||||
!this.hasUpdated ||
|
||||
!previousRoute ||
|
||||
repositoryIdFromRoute(previousRoute) === repositoryIdFromRoute(this.route)
|
||||
this.hasUpdated &&
|
||||
previousRoute &&
|
||||
repositoryIdFromRoute(previousRoute) !== repositoryIdFromRoute(this.route)
|
||||
) {
|
||||
return;
|
||||
this._repository = undefined;
|
||||
this._error = undefined;
|
||||
this._refreshError = undefined;
|
||||
this._loadRepositoryFromRoute();
|
||||
}
|
||||
|
||||
this._repository = undefined;
|
||||
this._error = undefined;
|
||||
this._refreshError = undefined;
|
||||
this._loadRepositoryFromRoute();
|
||||
if (
|
||||
changedProps.has("_repository") &&
|
||||
this._repository?.integration_categories?.length
|
||||
) {
|
||||
this._loadIntegrationCategoryIcons();
|
||||
}
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues<this>): void {
|
||||
@@ -396,6 +400,24 @@ export class HaMarketplaceRepositoryDashboard extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
// Only integrations have categories, other repositories don't need them
|
||||
private async _loadIntegrationCategoryIcons(): Promise<void> {
|
||||
if (
|
||||
this._integrationCategoryIcons ||
|
||||
this._loadingIntegrationCategoryIcons
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this._loadingIntegrationCategoryIcons = true;
|
||||
try {
|
||||
this._integrationCategoryIcons = await getIntegrationCategoryIcons(
|
||||
this._connection.connection
|
||||
);
|
||||
} finally {
|
||||
this._loadingIntegrationCategoryIcons = false;
|
||||
}
|
||||
}
|
||||
|
||||
private _loadRepositoryFromRoute(): void {
|
||||
const repositoryId = repositoryIdFromRoute(this.route);
|
||||
if (!repositoryId) {
|
||||
|
||||
@@ -27,7 +27,6 @@ import {
|
||||
coverCurrentValue,
|
||||
coverHasTiltControls,
|
||||
coverModeAttribute,
|
||||
coverSupportsPosition,
|
||||
coverSupportsSetValue,
|
||||
coverSupportsTiltPosition,
|
||||
coverTiltOpenness,
|
||||
@@ -78,6 +77,17 @@ const pillHandle = (cx: number, cy: number, vertical: boolean) =>
|
||||
const swipeResistance = (distance: number) =>
|
||||
SWIPE_RESISTANCE * (1 - Math.exp(-Math.max(0, distance) / 30));
|
||||
|
||||
const OPEN_CLOSE_FEATURES: Record<
|
||||
CoverControlMode,
|
||||
Record<CoverSwipe["action"], CoverEntityFeature>
|
||||
> = {
|
||||
position: { open: CoverEntityFeature.OPEN, close: CoverEntityFeature.CLOSE },
|
||||
tilt: {
|
||||
open: CoverEntityFeature.OPEN_TILT,
|
||||
close: CoverEntityFeature.CLOSE_TILT,
|
||||
},
|
||||
};
|
||||
|
||||
const modeSprings = (): ModeSprings => ({
|
||||
position: new PercentSpring(),
|
||||
tilt: new PercentSpring(),
|
||||
@@ -190,11 +200,11 @@ export class HaStateControlCover extends LitElement {
|
||||
}
|
||||
|
||||
private get _openCloseOnly(): boolean {
|
||||
const features = OPEN_CLOSE_FEATURES[this.mode];
|
||||
return (
|
||||
this.mode === "position" &&
|
||||
!coverSupportsPosition(this.stateObj) &&
|
||||
(supportsFeature(this.stateObj, CoverEntityFeature.OPEN) ||
|
||||
supportsFeature(this.stateObj, CoverEntityFeature.CLOSE))
|
||||
!this._canSetValue &&
|
||||
(supportsFeature(this.stateObj, features.open) ||
|
||||
supportsFeature(this.stateObj, features.close))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -208,7 +218,9 @@ export class HaStateControlCover extends LitElement {
|
||||
private get _interactive(): boolean {
|
||||
return (
|
||||
this.stateObj.state !== UNAVAILABLE &&
|
||||
(this._canSetValue || (this._openCloseOnly && !this._valueUnknown))
|
||||
(this._canSetValue ||
|
||||
(this._openCloseOnly &&
|
||||
coverCurrentValue(this.stateObj, this.mode) !== undefined))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -412,11 +424,7 @@ export class HaStateControlCover extends LitElement {
|
||||
}
|
||||
|
||||
private _swipeAction(): CoverSwipe["action"] {
|
||||
const end =
|
||||
this.request?.mode === "position"
|
||||
? this.request.value
|
||||
: this._drawingGoal("position");
|
||||
return end >= 50 ? "close" : "open";
|
||||
return this._handleGoal(this.mode) >= 50 ? "close" : "open";
|
||||
}
|
||||
|
||||
private _startSwipe(
|
||||
@@ -424,14 +432,10 @@ export class HaStateControlCover extends LitElement {
|
||||
shape: CoverShape,
|
||||
startPointer: number
|
||||
) {
|
||||
const mode = this.mode;
|
||||
const action = this._swipeAction();
|
||||
const closing = action === "close";
|
||||
if (
|
||||
!supportsFeature(
|
||||
this.stateObj,
|
||||
closing ? CoverEntityFeature.CLOSE : CoverEntityFeature.OPEN
|
||||
)
|
||||
) {
|
||||
if (!supportsFeature(this.stateObj, OPEN_CLOSE_FEATURES[mode][action])) {
|
||||
return;
|
||||
}
|
||||
const direction = closing ? -1 : 1;
|
||||
@@ -462,13 +466,13 @@ export class HaStateControlCover extends LitElement {
|
||||
const passedHalfway = Boolean(this._drag?.swipe?.passedHalfway);
|
||||
this._setDrag(undefined);
|
||||
if (passedHalfway) {
|
||||
fireEvent(this, "cover-command", { mode: "position", action });
|
||||
fireEvent(this, "cover-command", { mode, action });
|
||||
}
|
||||
},
|
||||
tap: (e) => {
|
||||
const pointer = this._pointerValue(e, shape);
|
||||
if (pointer !== undefined && pointer >= 50 !== closing) {
|
||||
fireEvent(this, "cover-command", { mode: "position", action });
|
||||
fireEvent(this, "cover-command", { mode, action });
|
||||
}
|
||||
},
|
||||
cancel: () => this._setDrag(undefined),
|
||||
|
||||
@@ -28,12 +28,20 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
|
||||
private _startupToastKey?: string;
|
||||
|
||||
private _startupDetailsOpen = false;
|
||||
|
||||
private _disconnectedTimeout?: number;
|
||||
|
||||
protected firstUpdated(changedProps: PropertyValues<this>) {
|
||||
super.firstUpdated(changedProps);
|
||||
// Need to load in advance because when disconnected, can't dynamically load code.
|
||||
setTimeout(() => import("../managers/notification-manager"), 5000);
|
||||
this.addEventListener("dialog-closed", (ev) => {
|
||||
if (ev.detail.dialog === "dialog-startup-progress") {
|
||||
this._startupDetailsOpen = false;
|
||||
this._updateStartupProgress();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updated(changedProperties: PropertyValues<this>) {
|
||||
@@ -135,6 +143,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
// Wait until the translations are available.
|
||||
if (
|
||||
!this._startupProgressVisible ||
|
||||
this._startupDetailsOpen ||
|
||||
!this.hass!.localize("ui.startup_progress.starting")
|
||||
) {
|
||||
return;
|
||||
@@ -163,13 +172,19 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
? {
|
||||
text: { translationKey: "ui.startup_progress.details" },
|
||||
icon: mdiInformationOutline,
|
||||
keepOpen: true,
|
||||
action: () => showStartupProgressDialog(this),
|
||||
action: () => this._showStartupDetails(),
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
// Toasts always show above dialogs, so the toast is hidden while the details are open.
|
||||
private _showStartupDetails() {
|
||||
this._startupDetailsOpen = true;
|
||||
this._startupToastKey = undefined;
|
||||
showStartupProgressDialog(this);
|
||||
}
|
||||
|
||||
// Keeps the subscription, so the completion toast still reflects late failures.
|
||||
private _hideStartupProgress() {
|
||||
this._startupProgressVisible = false;
|
||||
@@ -193,6 +208,9 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
);
|
||||
this._hideStartupProgress();
|
||||
this._unsubscribeBootstrapProgress();
|
||||
if (this._startupDetailsOpen) {
|
||||
return;
|
||||
}
|
||||
const issues = failed.length;
|
||||
showToast(this, {
|
||||
id: SERVER_STARTUP_TOAST_ID,
|
||||
@@ -205,7 +223,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
action: this.hass!.user?.is_admin
|
||||
? {
|
||||
text: this.hass!.localize("ui.notification_toast.details"),
|
||||
action: () => showStartupProgressDialog(this),
|
||||
action: () => this._showStartupDetails(),
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
|
||||
@@ -2857,6 +2857,7 @@
|
||||
"in_use": "In use",
|
||||
"connecting": "Connecting",
|
||||
"not_supported_count": "Not supported by this camera ({count})",
|
||||
"enhanced_by_cloud": "Enhanced by Home Assistant Link",
|
||||
"description": {
|
||||
"web_rtc": "Real-time video with the lowest delay, usually below a second. The video takes the most direct way from the camera to your device, which can need extra network setup when you are away from home. Needed to talk to the camera.",
|
||||
"hls": "The video is sent in short pieces through Home Assistant. It works on almost every network and device, but is a few seconds behind. Used while WebRTC connects, or when WebRTC is not available.",
|
||||
@@ -3993,7 +3994,8 @@
|
||||
"location_settings": "Location settings",
|
||||
"retention_all": "Keep all backups",
|
||||
"retention_backups": "Keep {count} {count, plural,\n one {backup}\n other {backups}\n}",
|
||||
"retention_days": "Keep {count} {count, plural,\n one {day}\n other {days}\n}"
|
||||
"retention_days": "Keep {count} {count, plural,\n one {day}\n other {days}\n}",
|
||||
"retention_inactive": "Retention paused"
|
||||
},
|
||||
"data": {
|
||||
"ha_settings": "Home Assistant settings",
|
||||
@@ -4049,7 +4051,7 @@
|
||||
"retention": "Retention",
|
||||
"custom_retention": "Custom retention",
|
||||
"custom_retention_label": "Keep only",
|
||||
"retention_description": "Based on the maximum number of backups or how many days they should be kept.",
|
||||
"retention_description": "Based on the maximum number of backups or how many days they should be kept. Only applies to automatic backups, in the locations they are stored in.",
|
||||
"retention_presets": {
|
||||
"global": "Use global settings",
|
||||
"copies_3": "3 backups",
|
||||
@@ -4324,6 +4326,7 @@
|
||||
"save_error": "Error saving configuration: {error}",
|
||||
"retention_for_this_system": "Retention for this system",
|
||||
"retention_for_location": "Retention for {location}",
|
||||
"retention_inactive": "Automatic backups aren't stored in this location, so its retention settings are paused. Backups already in this location are kept until you delete them. Retention applies again when you turn the location back on for automatic backups.",
|
||||
"not_found": "Not found",
|
||||
"not_found_description": "Location matching ''{backupId}'' not found",
|
||||
"error": "Could not fetch location details",
|
||||
@@ -4793,6 +4796,13 @@
|
||||
"add": "Add",
|
||||
"dismiss": "Dismiss",
|
||||
"dismiss_failed": "Couldn't dismiss this meter",
|
||||
"show_dismissed": "Show dismissed meters ({count})",
|
||||
"hide_dismissed": "Hide dismissed meters",
|
||||
"dismissed": "Dismissed",
|
||||
"dismissed_title": "Dismissed meters",
|
||||
"dismissed_sub": "Restore a meter to have it suggested again, or add it right away.",
|
||||
"restore": "Restore",
|
||||
"restore_failed": "Couldn't restore this meter",
|
||||
"load_failed": "Couldn't check for meters that aren't in your energy dashboard yet.",
|
||||
"slots": {
|
||||
"grid_import": "Grid consumption",
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { HaDialog } from "../../src/components/ha-dialog";
|
||||
import "../../src/components/ha-dialog";
|
||||
|
||||
vi.mock("@home-assistant/webawesome/dist/components/dialog/dialog", () => {
|
||||
customElements.define("wa-dialog", class extends HTMLElement {});
|
||||
return {};
|
||||
});
|
||||
|
||||
vi.mock("../../src/components/ha-dialog-header", () => {
|
||||
customElements.define("ha-dialog-header", class extends HTMLElement {});
|
||||
return {};
|
||||
});
|
||||
|
||||
vi.mock("../../src/components/ha-icon-button", () => {
|
||||
customElements.define("ha-icon-button", class extends HTMLElement {});
|
||||
return {};
|
||||
});
|
||||
|
||||
// Lit counts the test run as a server, so this never gets an observer
|
||||
vi.mock("@lit-labs/observers/resize-controller", () => ({
|
||||
ResizeController: class {
|
||||
observe = vi.fn();
|
||||
|
||||
unobserve = vi.fn();
|
||||
},
|
||||
}));
|
||||
|
||||
let host: HTMLElement | undefined;
|
||||
|
||||
afterEach(() => {
|
||||
host?.remove();
|
||||
host = undefined;
|
||||
});
|
||||
|
||||
// Shows the dialog the way wa-dialog announces it opened
|
||||
const showDialog = async (dialog: HaDialog) => {
|
||||
await dialog.updateComplete;
|
||||
dialog
|
||||
.shadowRoot!.querySelector("wa-dialog")!
|
||||
.dispatchEvent(new Event("wa-show"));
|
||||
};
|
||||
|
||||
describe("ha-dialog", () => {
|
||||
it("focuses its own autofocus child", async () => {
|
||||
host = document.createElement("ha-dialog");
|
||||
host.innerHTML = "<input /><input autofocus />";
|
||||
document.body.append(host);
|
||||
|
||||
await showDialog(host as HaDialog);
|
||||
|
||||
await vi.waitFor(() =>
|
||||
expect(document.activeElement).toBe(host!.querySelector("[autofocus]"))
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["slotted in by a wrapper", "<input /><input autofocus />"],
|
||||
[
|
||||
"nested in content a wrapper slots in",
|
||||
"<input /><div><input autofocus /></div>",
|
||||
],
|
||||
])("focuses an autofocus element %s", async (_, content) => {
|
||||
// A wrapper like ha-adaptive-dialog passes its content through a slot
|
||||
host = document.createElement("div");
|
||||
host.attachShadow({ mode: "open" }).innerHTML =
|
||||
"<ha-dialog><slot></slot></ha-dialog>";
|
||||
host.innerHTML = content;
|
||||
document.body.append(host);
|
||||
|
||||
await showDialog(host.shadowRoot!.querySelector("ha-dialog")!);
|
||||
|
||||
await vi.waitFor(() =>
|
||||
expect(document.activeElement).toBe(host!.querySelector("[autofocus]"))
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { BluetoothScannerState } from "../../src/data/bluetooth";
|
||||
import { isScannerStateMismatch } from "../../src/data/bluetooth";
|
||||
import {
|
||||
getBluetoothAdapters,
|
||||
isScannerStateMismatch,
|
||||
} from "../../src/data/bluetooth";
|
||||
import type { ConfigEntry } from "../../src/data/config_entries";
|
||||
import type { DeviceRegistryEntry } from "../../src/data/device/device_registry";
|
||||
|
||||
const state = (
|
||||
overrides: Partial<BluetoothScannerState>
|
||||
@@ -63,3 +68,54 @@ describe("isScannerStateMismatch", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getBluetoothAdapters", () => {
|
||||
const entry = (
|
||||
entry_id: string,
|
||||
overrides: Partial<ConfigEntry> = {}
|
||||
): ConfigEntry =>
|
||||
({
|
||||
entry_id,
|
||||
domain: "bluetooth",
|
||||
source: "user",
|
||||
disabled_by: null,
|
||||
...overrides,
|
||||
}) as ConfigEntry;
|
||||
|
||||
const device = (
|
||||
id: string,
|
||||
configEntries: string[],
|
||||
connections: [string, string][] = [["bluetooth", id]]
|
||||
): DeviceRegistryEntry =>
|
||||
({
|
||||
id,
|
||||
config_entries: configEntries,
|
||||
connections,
|
||||
}) as DeviceRegistryEntry;
|
||||
|
||||
it("only counts entries with a Bluetooth device as adapters", () => {
|
||||
const entries = [
|
||||
entry("proxy"),
|
||||
entry("ignored", { source: "ignore" }),
|
||||
entry("removed"),
|
||||
entry("disabled", { disabled_by: "user" }),
|
||||
entry("disabled-without-device", { disabled_by: "user" }),
|
||||
];
|
||||
const devices = {
|
||||
proxy: device("proxy", ["esphome", "proxy"]),
|
||||
disabled: device("disabled", ["disabled"]),
|
||||
"no-bluetooth": device("no-bluetooth", ["proxy"], [["mac", "x"]]),
|
||||
other: device("other", ["other-integration"]),
|
||||
};
|
||||
|
||||
const result = getBluetoothAdapters(devices, entries);
|
||||
|
||||
expect(result.enabledDevices.map((a) => a.device.id)).toEqual(["proxy"]);
|
||||
expect(result.disabledDevices.map((a) => a.device.id)).toEqual([
|
||||
"disabled",
|
||||
]);
|
||||
expect(result.disabledEntriesWithoutDevice.map((e) => e.entry_id)).toEqual([
|
||||
"disabled-without-device",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { CoverEntity } from "../../src/data/cover";
|
||||
import { CoverEntityFeature, coverCurrentValue } from "../../src/data/cover";
|
||||
|
||||
const TILT_FEATURES =
|
||||
CoverEntityFeature.OPEN_TILT +
|
||||
CoverEntityFeature.CLOSE_TILT +
|
||||
CoverEntityFeature.STOP_TILT;
|
||||
|
||||
const cover = (
|
||||
state: string,
|
||||
supportedFeatures: number,
|
||||
attributes: Partial<CoverEntity["attributes"]> = {}
|
||||
): CoverEntity =>
|
||||
({
|
||||
entity_id: "cover.blind",
|
||||
state,
|
||||
attributes: { supported_features: supportedFeatures, ...attributes },
|
||||
}) as CoverEntity;
|
||||
|
||||
describe("coverCurrentValue", () => {
|
||||
it("uses the state for the tilt of a tilt-only cover without a tilt position", () => {
|
||||
expect(coverCurrentValue(cover("closed", TILT_FEATURES), "tilt")).toBe(0);
|
||||
expect(coverCurrentValue(cover("opening", TILT_FEATURES), "tilt")).toBe(0);
|
||||
expect(coverCurrentValue(cover("open", TILT_FEATURES), "tilt")).toBe(100);
|
||||
expect(coverCurrentValue(cover("closing", TILT_FEATURES), "tilt")).toBe(
|
||||
100
|
||||
);
|
||||
});
|
||||
|
||||
it("has no tilt when the state of a tilt-only cover is unknown", () => {
|
||||
expect(
|
||||
coverCurrentValue(cover("unknown", TILT_FEATURES), "tilt")
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
coverCurrentValue(cover("unavailable", TILT_FEATURES), "tilt")
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("prefers the reported tilt position", () => {
|
||||
expect(
|
||||
coverCurrentValue(
|
||||
cover("closed", TILT_FEATURES, { current_tilt_position: 30 }),
|
||||
"tilt"
|
||||
)
|
||||
).toBe(30);
|
||||
});
|
||||
|
||||
it("does not use the state for the tilt when the cover also moves up and down", () => {
|
||||
expect(
|
||||
coverCurrentValue(
|
||||
cover("closed", TILT_FEATURES + CoverEntityFeature.OPEN),
|
||||
"tilt"
|
||||
)
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not use the state for the tilt when the cover can set its tilt position", () => {
|
||||
expect(
|
||||
coverCurrentValue(
|
||||
cover("closed", TILT_FEATURES + CoverEntityFeature.SET_TILT_POSITION),
|
||||
"tilt"
|
||||
)
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
import type { EnergySuggestionInput } from "../../src/data/energy_suggestions";
|
||||
import {
|
||||
computeEnergySuggestions,
|
||||
restoreDismissedSuggestion,
|
||||
updateDismissedSuggestions,
|
||||
} from "../../src/data/energy_suggestions";
|
||||
import type { StatisticsMetaData } from "../../src/data/recorder";
|
||||
@@ -230,3 +231,11 @@ describe("updateDismissedSuggestions", () => {
|
||||
).toEqual(["sensor.kept", "sensor.new"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("restoreDismissedSuggestion", () => {
|
||||
it("removes only the restored statistic", () => {
|
||||
expect(
|
||||
restoreDismissedSuggestion(["sensor.a", "sensor.b"], "sensor.a")
|
||||
).toEqual(["sensor.b"]);
|
||||
});
|
||||
});
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
browseUrl,
|
||||
filterRepositories,
|
||||
filtersOfTab,
|
||||
paneFilterOfTab,
|
||||
marketplaceUpdateEntityIds,
|
||||
skippedUpdateRepositories,
|
||||
statusesOfTab,
|
||||
@@ -284,13 +285,6 @@ describe("browseLinkFromUrl", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("filters on no integration category for an empty one", () => {
|
||||
expect(
|
||||
browseLinkFromUrl("?integration_category=")?.filters
|
||||
.integration_category ?? []
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps what was picked for a link that says nothing about browsing", () => {
|
||||
expect(
|
||||
browseLinkFromUrl("?owner=hacs&repository=integration")
|
||||
@@ -299,11 +293,31 @@ describe("browseLinkFromUrl", () => {
|
||||
});
|
||||
|
||||
describe("filtersOfTab", () => {
|
||||
it("keeps the integration category on every tab", () => {
|
||||
it("leaves out an integration category nothing on the tab is in", () => {
|
||||
const filters = { integration_category: ["energy", "energy.solar"] };
|
||||
|
||||
expect(
|
||||
filtersOfTab({ integration_category: ["energy"] }, "installed")
|
||||
.integration_category
|
||||
filtersOfTab(filters, "installed", ["energy"]).integration_category
|
||||
).toEqual(["energy"]);
|
||||
expect(filtersOfTab(filters, "installed", []).integration_category).toEqual(
|
||||
[]
|
||||
);
|
||||
// Without the ones the tab lists, as before the repositories load
|
||||
expect(filtersOfTab(filters, "installed").integration_category).toEqual(
|
||||
filters.integration_category
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps an integration category picked on browse when the installed pane changes", () => {
|
||||
const picked = ["energy.solar", "climate"];
|
||||
|
||||
expect(
|
||||
paneFilterOfTab(picked, ["climate", "lighting"], ["lighting"])
|
||||
).toEqual(["energy.solar", "lighting"]);
|
||||
// The pane's clear button sends no value
|
||||
expect(paneFilterOfTab(picked, ["climate"], undefined)).toEqual([
|
||||
"energy.solar",
|
||||
]);
|
||||
});
|
||||
|
||||
it("only offers statuses something installed can have on the installed tab", () => {
|
||||
|
||||
@@ -274,6 +274,61 @@ it("shows what to discover on the discover tab, not the table", async () => {
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
it("offers the integration categories of the tab, leaving out one picked on another", async () => {
|
||||
window.history.replaceState(
|
||||
null,
|
||||
"",
|
||||
"/marketplace/browse?integration_category=energy"
|
||||
);
|
||||
const dashboard = await openDashboard([
|
||||
{
|
||||
id: "1",
|
||||
name: "One",
|
||||
category: "integration",
|
||||
installed: true,
|
||||
integration_categories: ["climate"],
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
name: "Two",
|
||||
category: "integration",
|
||||
installed: false,
|
||||
integration_categories: ["energy"],
|
||||
},
|
||||
]);
|
||||
window.history.replaceState(null, "", "/");
|
||||
const table = () =>
|
||||
dashboard.shadowRoot!.querySelector(
|
||||
"hass-tabs-subpage-data-table"
|
||||
) as unknown as { data: { id: string }[]; filters: number };
|
||||
const categoryFilter = () =>
|
||||
dashboard.shadowRoot!.querySelectorAll(
|
||||
"ha-filter-states"
|
||||
)[3] as unknown as {
|
||||
value?: string[];
|
||||
states: { value: string }[];
|
||||
};
|
||||
|
||||
expect(table().data.map((repository) => repository.id)).toEqual(["2"]);
|
||||
|
||||
dashboard.tab = "installed";
|
||||
await dashboard.updateComplete;
|
||||
|
||||
expect(categoryFilter().states.map((state) => state.value)).toEqual([
|
||||
"climate",
|
||||
]);
|
||||
expect(categoryFilter().value).toEqual([]);
|
||||
expect(table().filters).toBe(0);
|
||||
expect(table().data.map((repository) => repository.id)).toEqual(["1"]);
|
||||
|
||||
dashboard.tab = "browse";
|
||||
await dashboard.updateComplete;
|
||||
|
||||
expect(categoryFilter().value).toEqual(["energy"]);
|
||||
dashboard.remove();
|
||||
sessionStorage.clear();
|
||||
});
|
||||
|
||||
it("browses the way the link says", async () => {
|
||||
window.history.replaceState(
|
||||
null,
|
||||
|
||||
@@ -11,6 +11,8 @@ import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import { deferred } from "./dialog-host";
|
||||
import { markdownWithRepositoryContext } from "../../../src/panels/marketplace/tools/markdown";
|
||||
import type * as MarkdownModule from "../../../src/panels/marketplace/tools/markdown";
|
||||
import { getIntegrationCategoryIcons } from "../../../src/data/icons";
|
||||
import type * as IconsModule from "../../../src/data/icons";
|
||||
|
||||
// The real components need more browser than jsdom has, the page only hands
|
||||
// them properties.
|
||||
@@ -39,6 +41,10 @@ vi.mock(
|
||||
};
|
||||
}
|
||||
);
|
||||
vi.mock("../../../src/data/icons", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof IconsModule>()),
|
||||
getIntegrationCategoryIcons: vi.fn(async () => ({})),
|
||||
}));
|
||||
vi.mock("../../../src/components/chips/ha-assist-chip", () =>
|
||||
stubElement("ha-assist-chip")
|
||||
);
|
||||
@@ -212,6 +218,30 @@ describe("ha-marketplace-repository-dashboard", () => {
|
||||
expect(getInternals(page)._repository.id).toBe("2");
|
||||
});
|
||||
|
||||
it("loads the category icons once, only for repositories with categories", async () => {
|
||||
const { page } = await openRepositoryPage(
|
||||
async (repositoryId) =>
|
||||
repositoryInfo(
|
||||
repositoryId,
|
||||
repositoryId === "theme"
|
||||
? { category: "theme" }
|
||||
: { category: "integration", integration_categories: ["energy"] }
|
||||
),
|
||||
repositoryRoute("theme")
|
||||
);
|
||||
await settle(page);
|
||||
expect(getIntegrationCategoryIcons).not.toHaveBeenCalled();
|
||||
|
||||
page.route = repositoryRoute("1");
|
||||
await settle(page);
|
||||
page.route = repositoryRoute("2");
|
||||
await settle(page);
|
||||
page.reloadRepository();
|
||||
await settle(page);
|
||||
|
||||
expect(getIntegrationCategoryIcons).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("clears the error of the previous repository", async () => {
|
||||
const { page } = await openRepositoryPage(async (repositoryId) => {
|
||||
if (repositoryId === "1") {
|
||||
|
||||
Reference in new issue
Block a user