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

Fix address string in CreateEntityDialog #41

Merged
merged 1 commit into from
Dec 31, 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
6 changes: 3 additions & 3 deletions src/dialogs/lcn-create-entity-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { stopPropagation } from "@ha/common/dom/stop_propagation";
import { haStyleDialog } from "@ha/resources/styles";
import type { HomeAssistant } from "@ha/types";
import type { LCN, LcnDeviceConfig, LcnEntityConfig } from "types/lcn";
import { addressToString, stringToAddress } from "helpers/address_conversion";
import { addressToString, stringToAddress, addressToHumanString } from "helpers/address_conversion";
import "./lcn-config-binary-sensor";
import "./lcn-config-climate";
import "./lcn-config-cover";
Expand Down Expand Up @@ -74,7 +74,7 @@ export class CreateEntityDialog extends LitElement {
}

protected render() {
if (!this._params) {
if (!this._params || !this.lcn || !this._deviceConfig) {
return nothing;
}
return html`
Expand All @@ -100,7 +100,7 @@ export class CreateEntityDialog extends LitElement {
(deviceConfig) => html`
<ha-list-item .value=${addressToString(deviceConfig.address)}>
<div class="primary">${deviceConfig.name}</div>
<div class="secondary">(${addressToString(deviceConfig.address)})</div>
<div class="secondary">(${addressToHumanString(deviceConfig.address)})</div>
</ha-list-item>
`,
)}
Expand Down
8 changes: 4 additions & 4 deletions src/dialogs/show-dialog-create-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { LCN, LcnEntityConfig, LcnDeviceConfig } from "types/lcn";

export interface LcnEntityDialogParams {
lcn: LCN;
deviceConfig: LcnDeviceConfig;
createEntity: (values: Partial<LcnEntityConfig>) => Promise<unknown>;
deviceConfig: LcnDeviceConfig | undefined;
createEntity: (entityParams: Partial<LcnEntityConfig>) => Promise<boolean>;
}

export const loadLCNCreateEntityDialog = () => import("./lcn-create-entity-dialog");

export const showLCNCreateEntityDialog = (
element: HTMLElement,
lcnEntityParams: LcnEntityDialogParams,
lcnEntityDialogParams: LcnEntityDialogParams,
): void => {
fireEvent(element, "show-dialog", {
dialogTag: "lcn-create-entity-dialog",
dialogImport: loadLCNCreateEntityDialog,
dialogParams: lcnEntityParams,
dialogParams: lcnEntityDialogParams,
});
};
4 changes: 4 additions & 0 deletions src/helpers/address_conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export function stringToAddress(address_str: string): LcnAddress {
const address: LcnAddress = [address_id, segment_id, is_group];
return address;
}

export function addressToHumanString(address: LcnAddress): string {
return `S${address[0]} ${address[2] ? "G" : "M"}${address[1]}`;
}
2 changes: 1 addition & 1 deletion src/lcn-entities-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ export class LCNEntitiesPage extends LitElement {
private async _addEntity() {
showLCNCreateEntityDialog(this, {
lcn: this.lcn,
deviceConfig: <LcnDeviceConfig>this._deviceConfig,
deviceConfig: <LcnDeviceConfig | undefined>this._deviceConfig,
createEntity: async (entityParams) => {
if (await addEntity(this.hass, this.lcn.config_entry, entityParams)) {
updateEntityConfigs(this);
Expand Down
Loading