Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20240628.0 #21223

Merged
merged 12 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"@babel/plugin-transform-runtime": "7.24.7",
"@babel/preset-env": "7.24.7",
"@babel/preset-typescript": "7.24.7",
"@bundle-stats/plugin-webpack-filter": "4.13.2",
"@bundle-stats/plugin-webpack-filter": "4.13.3",
"@koa/cors": "5.0.0",
"@lokalise/node-api": "12.5.0",
"@octokit/auth-oauth-device": "7.1.1",
Expand Down Expand Up @@ -185,8 +185,8 @@
"@types/tar": "6.1.13",
"@types/ua-parser-js": "0.7.39",
"@types/webspeechapi": "0.0.29",
"@typescript-eslint/eslint-plugin": "7.13.1",
"@typescript-eslint/parser": "7.13.1",
"@typescript-eslint/eslint-plugin": "7.14.1",
"@typescript-eslint/parser": "7.14.1",
"@web/dev-server": "0.1.38",
"@web/dev-server-rollup": "0.4.1",
"babel-loader": "9.1.3",
Expand Down Expand Up @@ -220,7 +220,7 @@
"lodash.template": "4.5.0",
"magic-string": "0.30.10",
"map-stream": "0.0.7",
"mocha": "10.4.0",
"mocha": "10.5.0",
"object-hash": "3.0.0",
"open": "10.1.0",
"pinst": "3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "home-assistant-frontend"
version = "20240627.0"
version = "20240628.0"
license = {text = "Apache-2.0"}
description = "The Home Assistant frontend"
readme = "README.md"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "@material/mwc-button";
import "@material/mwc-list/mwc-list-item";
import { mdiOpenInNew } from "@mdi/js";
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
Expand All @@ -11,6 +10,7 @@ import "../../../components/ha-combo-box";
import { createCloseHeading } from "../../../components/ha-dialog";
import "../../../components/ha-markdown";
import "../../../components/ha-textfield";
import "../../../components/ha-button";
import {
ApplicationCredential,
ApplicationCredentialsConfig,
Expand Down Expand Up @@ -231,10 +231,10 @@ export class DialogAddApplicationCredential extends LitElement {
</div>
`
: html`
<mwc-button slot="primaryAction" @click=${this._abortDialog}>
<ha-button slot="secondaryAction" @click=${this._abortDialog}>
${this.hass.localize("ui.common.cancel")}
</mwc-button>
<mwc-button
</ha-button>
<ha-button
slot="primaryAction"
.disabled=${!this._domain ||
!this._clientId ||
Expand All @@ -244,7 +244,7 @@ export class DialogAddApplicationCredential extends LitElement {
${this.hass.localize(
"ui.panel.config.application_credentials.editor.add"
)}
</mwc-button>
</ha-button>
`}
</ha-dialog>
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LocalizeFunc } from "../../../common/translations/localize";
import {
DataTableColumnContainer,
SelectionChangedEvent,
SortingChangedEvent,
} from "../../../components/data-table/ha-data-table";
import "../../../components/ha-fab";
import "../../../components/ha-help-tooltip";
Expand All @@ -27,6 +28,7 @@ import type { HaTabsSubpageDataTable } from "../../../layouts/hass-tabs-subpage-
import { HomeAssistant, Route } from "../../../types";
import { configSections } from "../ha-panel-config";
import { showAddApplicationCredentialDialog } from "./show-dialog-add-application-credential";
import { storage } from "../../../common/decorators/storage";

@customElement("ha-config-application-credentials")
export class HaConfigApplicationCredentials extends LitElement {
Expand All @@ -45,6 +47,35 @@ export class HaConfigApplicationCredentials extends LitElement {
@query("hass-tabs-subpage-data-table", true)
private _dataTable!: HaTabsSubpageDataTable;

@storage({
key: "application-credentials-table-sort",
state: false,
subscribe: false,
})
private _activeSorting?: SortingChangedEvent;

@storage({
key: "application-credentials-table-column-order",
state: false,
subscribe: false,
})
private _activeColumnOrder?: string[];

@storage({
key: "application-credentials-table-hidden-columns",
state: false,
subscribe: false,
})
private _activeHiddenColumns?: string[];

@storage({
storage: "sessionStorage",
key: "application-credentials-table-search",
state: true,
subscribe: false,
})
private _filter = "";

private _columns = memoizeOne(
(narrow: boolean, localize: LocalizeFunc): DataTableColumnContainer => {
const columns: DataTableColumnContainer<ApplicationCredential> = {
Expand All @@ -53,13 +84,15 @@ export class HaConfigApplicationCredentials extends LitElement {
"ui.panel.config.application_credentials.picker.headers.name"
),
sortable: true,
filterable: true,
direction: "asc",
grows: true,
},
client_id: {
title: localize(
"ui.panel.config.application_credentials.picker.headers.client_id"
),
filterable: true,
width: "30%",
hidden: narrow,
},
Expand All @@ -68,6 +101,7 @@ export class HaConfigApplicationCredentials extends LitElement {
"ui.panel.config.application_credentials.picker.headers.application"
),
sortable: true,
filterable: true,
width: "30%",
direction: "asc",
},
Expand All @@ -84,7 +118,7 @@ export class HaConfigApplicationCredentials extends LitElement {
path: mdiDelete,
warning: true,
label: this.hass.localize("ui.common.delete"),
action: () => this._removeCredential(credential),
action: () => this._deleteCredential(credential),
},
]}
>
Expand Down Expand Up @@ -128,11 +162,18 @@ export class HaConfigApplicationCredentials extends LitElement {
selectable
.selected=${this._selected.length}
@selection-changed=${this._handleSelectionChanged}
.initialSorting=${this._activeSorting}
.columnOrder=${this._activeColumnOrder}
.hiddenColumns=${this._activeHiddenColumns}
@columns-changed=${this._handleColumnsChanged}
@sorting-changed=${this._handleSortingChanged}
.filter=${this._filter}
@search-changed=${this._handleSearchChange}
>
<div class="header-btns" slot="selection-bar">
${!this.narrow
? html`
<mwc-button @click=${this._removeSelected} class="warning"
<mwc-button @click=${this._deleteSelected} class="warning"
>${this.hass.localize(
"ui.panel.config.application_credentials.picker.remove_selected.button"
)}</mwc-button
Expand All @@ -142,7 +183,7 @@ export class HaConfigApplicationCredentials extends LitElement {
<ha-icon-button
class="warning"
id="remove-btn"
@click=${this._removeSelected}
@click=${this._deleteSelected}
.path=${mdiDelete}
.label=${this.hass.localize("ui.common.remove")}
></ha-icon-button>
Expand Down Expand Up @@ -174,7 +215,7 @@ export class HaConfigApplicationCredentials extends LitElement {
this._selected = ev.detail.value;
}

private _removeCredential = async (credential) => {
private _deleteCredential = async (credential) => {
const confirm = await showConfirmationDialog(this, {
title: this.hass.localize(
`ui.panel.config.application_credentials.picker.remove.confirm_title`
Expand All @@ -190,9 +231,10 @@ export class HaConfigApplicationCredentials extends LitElement {
return;
}
await deleteApplicationCredential(this.hass, credential.id);
await this._fetchApplicationCredentials();
};

private _removeSelected() {
private _deleteSelected() {
showConfirmationDialog(this, {
title: this.hass.localize(
`ui.panel.config.application_credentials.picker.remove_selected.confirm_title`,
Expand Down Expand Up @@ -224,7 +266,7 @@ export class HaConfigApplicationCredentials extends LitElement {
return;
}
this._dataTable.clearSelection();
this._fetchApplicationCredentials();
await this._fetchApplicationCredentials();
},
});
}
Expand Down Expand Up @@ -252,6 +294,19 @@ export class HaConfigApplicationCredentials extends LitElement {
});
}

private _handleSortingChanged(ev: CustomEvent) {
this._activeSorting = ev.detail;
}

private _handleColumnsChanged(ev: CustomEvent) {
this._activeColumnOrder = ev.detail.columnOrder;
this._activeHiddenColumns = ev.detail.hiddenColumns;
}

private _handleSearchChange(ev: CustomEvent) {
this._filter = ev.detail.value;
}

static get styles(): CSSResultGroup {
return css`
.table-header {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/automation/ha-automation-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
const columns: DataTableColumnContainer<AutomationItem> = {
icon: {
title: "",
label: localize("ui.panel.config.automation.picker.headers.state"),
label: localize("ui.panel.config.automation.picker.headers.icon"),
type: "icon",
moveable: false,
showNarrow: true,
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/scene/ha-scene-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class HaSceneDashboard extends SubscribeMixin(LitElement) {
const columns: DataTableColumnContainer<SceneItem> = {
icon: {
title: "",
label: localize("ui.panel.config.scene.picker.headers.state"),
label: localize("ui.panel.config.scene.picker.headers.icon"),
moveable: false,
showNarrow: true,
type: "icon",
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/script/ha-script-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class HaScriptPicker extends SubscribeMixin(LitElement) {
title: "",
showNarrow: true,
moveable: false,
label: localize("ui.panel.config.script.picker.headers.state"),
label: localize("ui.panel.config.script.picker.headers.icon"),
type: "icon",
template: (script) =>
html`<ha-state-icon
Expand Down
5 changes: 5 additions & 0 deletions src/panels/config/users/dialog-add-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ export class DialogAddUser extends LitElement {
}

user.username = this._username;
user.credentials = [
{
type: "homeassistant",
},
];
this._params!.userAddedCallback(user);
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid non-null assertions.

Non-null assertions can lead to runtime errors. Use optional chaining (?.) or other checks instead.

- this._params!.userAddedCallback(user);
+ this._params?.userAddedCallback(user);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this._params!.userAddedCallback(user);
this._params?.userAddedCallback(user);
Tools
Biome

[error] 298-298: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

this._close();
}
Expand Down
26 changes: 17 additions & 9 deletions src/panels/lovelace/cards/hui-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export class HuiCard extends ReactiveElement {

@property({ attribute: false }) public hass?: HomeAssistant;

private _elementConfig?: LovelaceCardConfig;
Copy link
Contributor

Choose a reason for hiding this comment

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

New properties and methods look good, but consider type safety improvements.

The introduction of _elementConfig and methods like _updateElement enhance modularity and maintainability. However, consider replacing any types with more specific ones.

- catch (e: any) {
+ catch (e: Error) {

Also applies to: 86-93, 97-97, 147-154


public load() {
if (!this.config) {
throw new Error("Cannot build card without config");
Expand All @@ -43,9 +45,6 @@ export class HuiCard extends ReactiveElement {
private _listeners: MediaQueriesListener[] = [];

protected createRenderRoot() {
const style = document.createElement("style");
style.textContent = `hui-card { display: contents }`;
this.append(style);
return this;
}

Expand Down Expand Up @@ -84,8 +83,18 @@ export class HuiCard extends ReactiveElement {
return this._element?.getLayoutOptions?.() ?? {};
}

private _updateElement(config: LovelaceCardConfig) {
if (!this._element) {
return;
}
this._element.setConfig(config);
this._elementConfig = config;
fireEvent(this, "card-updated");
}

private _loadElement(config: LovelaceCardConfig) {
this._element = createCardElement(config);
this._elementConfig = config;
if (this.hass) {
this._element.hass = this.hass;
}
Expand Down Expand Up @@ -135,15 +144,14 @@ export class HuiCard extends ReactiveElement {
super.update(changedProps);

if (this._element) {
if (changedProps.has("config") && this.hasUpdated) {
const oldConfig = changedProps.get("config");
if (this.config !== oldConfig && this.config) {
const typeChanged = this.config?.type !== oldConfig?.type;
if (changedProps.has("config")) {
const elementConfig = this._elementConfig;
if (this.config !== elementConfig && this.config) {
const typeChanged = this.config?.type !== elementConfig?.type;
if (typeChanged) {
this._loadElement(this.config);
} else {
this._element?.setConfig(this.config);
fireEvent(this, "card-updated");
this._updateElement(this.config);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/panels/lovelace/cards/hui-horizontal-stack-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class HuiHorizontalStackCard extends HuiStackCard {
height: 100%;
gap: var(--horizontal-stack-card-gap, var(--stack-card-gap, 8px));
}
#root > hui-card {
display: contents;
}
#root > hui-card > * {
flex: 1 1 0;
min-width: 0;
Expand Down
9 changes: 6 additions & 3 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2733,7 +2733,8 @@
"actions": "Actions",
"state": "State",
"category": "Category",
"area": "Area"
"area": "Area",
"icon": "Icon"
},
"bulk_action": "Action",
"bulk_actions": {
Expand Down Expand Up @@ -3608,7 +3609,8 @@
"name": "Name",
"state": "State",
"category": "Category",
"area": "Area"
"area": "Area",
"icon": "Icon"
},
"edit_category": "[%key:ui::panel::config::automation::picker::edit_category%]",
"assign_category": "[%key:ui::panel::config::automation::picker::assign_category%]",
Expand Down Expand Up @@ -3727,7 +3729,8 @@
"name": "Name",
"last_activated": "Last activated",
"category": "Category",
"area": "Area"
"area": "Area",
"icon": "Icon"
},
"edit_category": "[%key:ui::panel::config::automation::picker::edit_category%]",
"assign_category": "[%key:ui::panel::config::automation::picker::assign_category%]",
Expand Down
Loading
Loading