mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-02 05:57:54 +00:00
Add targeted joins to ZHA config panel (#3048)
* initial targeted add * mains powered devices only * fix prop reference * import * fix targeted join
This commit is contained in:
parent
9f97b583a8
commit
8f5f14fada
@ -16,6 +16,7 @@ export interface ZHADevice {
|
|||||||
manufacturer_code: number;
|
manufacturer_code: number;
|
||||||
device_reg_id: string;
|
device_reg_id: string;
|
||||||
user_given_name?: string;
|
user_given_name?: string;
|
||||||
|
power_source?: string;
|
||||||
area_id?: string;
|
area_id?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,23 +18,28 @@ import {
|
|||||||
|
|
||||||
import { ZHADevice } from "../../../data/zha";
|
import { ZHADevice } from "../../../data/zha";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant, Route } from "../../../types";
|
||||||
|
|
||||||
@customElement("zha-add-devices-page")
|
@customElement("zha-add-devices-page")
|
||||||
class ZHAAddDevicesPage extends LitElement {
|
class ZHAAddDevicesPage extends LitElement {
|
||||||
@property() public hass!: HomeAssistant;
|
@property() public hass!: HomeAssistant;
|
||||||
@property() public isWide?: boolean;
|
@property() public isWide?: boolean;
|
||||||
|
@property() public route?: Route;
|
||||||
@property() private _error?: string;
|
@property() private _error?: string;
|
||||||
@property() private _discoveredDevices: ZHADevice[] = [];
|
@property() private _discoveredDevices: ZHADevice[] = [];
|
||||||
@property() private _formattedEvents: string = "";
|
@property() private _formattedEvents: string = "";
|
||||||
@property() private _active: boolean = false;
|
@property() private _active: boolean = false;
|
||||||
@property() private _showHelp: boolean = false;
|
@property() private _showHelp: boolean = false;
|
||||||
|
private _ieeeAddress?: string;
|
||||||
private _addDevicesTimeoutHandle: any = undefined;
|
private _addDevicesTimeoutHandle: any = undefined;
|
||||||
private _subscribed?: Promise<() => Promise<void>>;
|
private _subscribed?: Promise<() => Promise<void>>;
|
||||||
|
|
||||||
public connectedCallback(): void {
|
public connectedCallback(): void {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
this._subscribe();
|
if (this.route && this.route.path && this.route.path !== "") {
|
||||||
|
this._ieeeAddress = this.route.path.substring(1);
|
||||||
|
}
|
||||||
|
this._subscribe(this._ieeeAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public disconnectedCallback(): void {
|
public disconnectedCallback(): void {
|
||||||
@ -151,10 +156,14 @@ class ZHAAddDevicesPage extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _subscribe(): void {
|
private _subscribe(ieeeAddress: string | undefined): void {
|
||||||
|
const data: any = { type: "zha/devices/permit" };
|
||||||
|
if (ieeeAddress) {
|
||||||
|
data.ieee = ieeeAddress;
|
||||||
|
}
|
||||||
this._subscribed = this.hass!.connection.subscribeMessage(
|
this._subscribed = this.hass!.connection.subscribeMessage(
|
||||||
(message) => this._handleMessage(message),
|
(message) => this._handleMessage(message),
|
||||||
{ type: "zha/devices/permit" }
|
data
|
||||||
);
|
);
|
||||||
this._active = true;
|
this._active = true;
|
||||||
this._addDevicesTimeoutHandle = setTimeout(
|
this._addDevicesTimeoutHandle = setTimeout(
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import "../../../components/buttons/ha-call-service-button";
|
import "../../../components/buttons/ha-call-service-button";
|
||||||
|
import "../../../components/ha-service-description";
|
||||||
import "../../../components/entity/state-badge";
|
import "../../../components/entity/state-badge";
|
||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
import "@polymer/paper-card/paper-card";
|
import "@polymer/paper-card/paper-card";
|
||||||
@ -34,6 +35,7 @@ import { reconfigureNode, ZHADevice } from "../../../data/zha";
|
|||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { ItemSelectedEvent, NodeServiceData } from "./types";
|
import { ItemSelectedEvent, NodeServiceData } from "./types";
|
||||||
|
import { navigate } from "../../../common/navigate";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
// for fire event
|
// for fire event
|
||||||
@ -222,6 +224,23 @@ class ZHADeviceCard extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
|
${this.device!.power_source === "Mains"
|
||||||
|
? html`
|
||||||
|
<mwc-button @click=${this._onAddDevicesClick}>
|
||||||
|
Add Devices
|
||||||
|
</mwc-button>
|
||||||
|
${this.showHelp
|
||||||
|
? html`
|
||||||
|
<ha-service-description
|
||||||
|
.hass="${this.hass}"
|
||||||
|
domain="zha"
|
||||||
|
service="permit"
|
||||||
|
class="help-text2"
|
||||||
|
/>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: ""
|
: ""
|
||||||
@ -281,6 +300,10 @@ class ZHADeviceCard extends LitElement {
|
|||||||
this.device!.area_id = newAreaId;
|
this.device!.area_id = newAreaId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _onAddDevicesClick() {
|
||||||
|
navigate(this, "add/" + this.device!.ieee);
|
||||||
|
}
|
||||||
|
|
||||||
static get styles(): CSSResult[] {
|
static get styles(): CSSResult[] {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user