Skip to content

Commit

Permalink
Merge pull request #26 from pyinsteon/fix_add_device
Browse files Browse the repository at this point in the history
Fix add device
  • Loading branch information
teharris1 authored Mar 7, 2023
2 parents 019de79 + c4b7cce commit 16d8fe8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
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 = "insteon-frontend-home-assistant"
version = "0.3.2"
version = "0.3.3"
license = {text = "MIT License"}
description = "The Insteon frontend for Home Assistant"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion src/data/insteon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export const addDeviceSchema = (multiple: boolean): HaFormSchema[] => [
type: "boolean",
},
{
name: "address",
name: "device_address",
required: false,
type: multiple ? "constant" : "string",
},
Expand Down
26 changes: 19 additions & 7 deletions src/device/dialog-insteon-add-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ class DialogInsteonAddDevice extends LitElement {

@state() private _title?: string;

@state() private _callback?: (address: string, multiple: boolean) => Promise<void>;
@state() private _callback?: (
device_address: string | undefined,
multiple: boolean
) => Promise<void>;

@state() private _errors?: { [key: string]: string };

@state() private _formData = { multiple: false, address: "" };
@state() private _formData = { multiple: false, device_address: "" };

@state() private _opened = false;

Expand All @@ -37,7 +40,7 @@ class DialogInsteonAddDevice extends LitElement {
this._title = params.title;
this._errors = {};
this._opened = true;
this._formData = { multiple: false, address: "" };
this._formData = { multiple: false, device_address: "" };
}

private _schema(multiple: boolean): HaFormSchema[] {
Expand Down Expand Up @@ -89,8 +92,11 @@ class DialogInsteonAddDevice extends LitElement {
// eslint-disable-next-line no-console
console.info("Should be calling callback");
this._close();
const address = this._formData.address == "" ? undefined : this._formData.address;
await this._callback!(address, this._formData.multiple);
const device_address =
this._formData.device_address == ""
? undefined
: this._formData.device_address;
await this._callback!(device_address, this._formData.multiple);
} else {
this._errors!.base = this.insteon!.localize("common.error.base");
}
Expand All @@ -105,10 +111,16 @@ class DialogInsteonAddDevice extends LitElement {
}

private _checkData(): boolean {
if (this._formData.address == "" || check_address(this._formData.address)) return true;
if (
this._formData.device_address == "" ||
check_address(this._formData.device_address)
)
return true;

this._errors = {};
this._errors.address = this.insteon!.localize("common.error.address");
this._errors.device_address = this.insteon!.localize(
"common.error.address"
);
return false;
}

Expand Down
15 changes: 11 additions & 4 deletions src/device/dialog-insteon-adding-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import "../../homeassistant-frontend/src/components/ha-code-editor";
import { createCloseHeading } from "../../homeassistant-frontend/src/components/ha-dialog";
import { haStyleDialog } from "../../homeassistant-frontend/src/resources/styles";
import { HomeAssistant } from "../../homeassistant-frontend/src/types";
import { Insteon, cancelAddInsteonDevice, deviceAddedMessage } from "../data/insteon";
import {
Insteon,
cancelAddInsteonDevice,
deviceAddedMessage,
} from "../data/insteon";
import "../../homeassistant-frontend/src/components/ha-form/ha-form";
import { InsteonAddingDeviceDialogParams } from "./show-dialog-adding-device";

Expand Down Expand Up @@ -34,7 +38,9 @@ class DialogInsteonAddingDevice extends LitElement {

private _refreshLinkingTimeoutHandle?: number;

public async showDialog(params: InsteonAddingDeviceDialogParams): Promise<void> {
public async showDialog(
params: InsteonAddingDeviceDialogParams
): Promise<void> {
this.hass = params.hass;
this.insteon = params.insteon;
this._address = params.address;
Expand Down Expand Up @@ -69,7 +75,8 @@ class DialogInsteonAddingDevice extends LitElement {
}

private _showInstructions() {
if (this.insteon && !this._subscribed) return this.insteon.localize("device.add.complete");
if (this.insteon && !this._subscribed)
return this.insteon.localize("device.add.complete");
if (this._address) return this._addressText(this._address);
if (this._multiple) return this.insteon!.localize("device.add.multiple");
return this.insteon!.localize("device.add.single");
Expand Down Expand Up @@ -133,7 +140,7 @@ class DialogInsteonAddingDevice extends LitElement {
{
type: "insteon/device/add",
multiple: this._multiple,
address: this._address,
device_address: this._address,
}
);
this._refreshLinkingTimeoutHandle = window.setTimeout(
Expand Down
6 changes: 4 additions & 2 deletions src/device/show-dialog-insteon-add-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export interface InsteonAddDeviceDialogParams {
hass: HomeAssistant;
insteon: Insteon;
title: string;
callback: (address: string, multiple: boolean) => Promise<void>;
callback: (address: string | undefined, multiple: boolean) => Promise<void>;
}

export const loadInsteonAddDeviceDialog = () =>
import(/* webpackChunkName: "dialog-insteon-add-device" */ "./dialog-insteon-add-device");
import(
/* webpackChunkName: "dialog-insteon-add-device" */ "./dialog-insteon-add-device"
);

export const showInsteonAddDeviceDialog = (
element: HTMLElement,
Expand Down
2 changes: 1 addition & 1 deletion src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"stop": "Stop"
},
"fields": {
"address": "Insteon device address (optional)",
"device_address": "Insteon device address (optional)",
"multiple": "Link mutiple devices"
},
"add": {
Expand Down

0 comments on commit 16d8fe8

Please sign in to comment.