-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Z-Wave controller hard reset device action (certification req) (#…
…18216) Co-authored-by: Bram Kragten <[email protected]>
- Loading branch information
1 parent
1cb238e
commit d8d16c4
Showing
6 changed files
with
198 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
.../config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { mdiCheckCircle, mdiDeleteForever, mdiRestore } from "@mdi/js"; | ||
import "@material/mwc-button/mwc-button"; | ||
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; | ||
import { customElement, property, state } from "lit/decorators"; | ||
import { fireEvent } from "../../../../../common/dom/fire_event"; | ||
import { createCloseHeading } from "../../../../../components/ha-dialog"; | ||
import "../../../../../components/ha-svg-icon"; | ||
import { hardResetController } from "../../../../../data/zwave_js"; | ||
import { haStyleDialog } from "../../../../../resources/styles"; | ||
import { HomeAssistant } from "../../../../../types"; | ||
import { ZWaveJSHardResetControllerDialogParams } from "./show-dialog-zwave_js-hard-reset-controller"; | ||
import { showConfirmationDialog } from "../../../../../dialogs/generic/show-dialog-box"; | ||
import { navigate } from "../../../../../common/navigate"; | ||
|
||
enum ResetStatus { | ||
NotStarted, | ||
InProgress, | ||
Done, | ||
} | ||
|
||
const iconMap = { | ||
[ResetStatus.NotStarted]: mdiDeleteForever, | ||
[ResetStatus.InProgress]: mdiRestore, | ||
[ResetStatus.Done]: mdiCheckCircle, | ||
}; | ||
|
||
@customElement("dialog-zwave_js-hard-reset-controller") | ||
class DialogZWaveJSHardResetController extends LitElement { | ||
@property({ attribute: false }) public hass!: HomeAssistant; | ||
|
||
@state() private _entryId?: string; | ||
|
||
@state() private _resetStatus = ResetStatus.NotStarted; | ||
|
||
public showDialog(params: ZWaveJSHardResetControllerDialogParams): void { | ||
this._entryId = params.entryId; | ||
} | ||
|
||
public closeDialog(): void { | ||
this._entryId = undefined; | ||
this._resetStatus = ResetStatus.NotStarted; | ||
|
||
fireEvent(this, "dialog-closed", { dialog: this.localName }); | ||
} | ||
|
||
protected render() { | ||
if (!this._entryId) { | ||
return nothing; | ||
} | ||
|
||
return html`<ha-dialog | ||
open | ||
@closed=${this.closeDialog} | ||
.heading=${createCloseHeading( | ||
this.hass, | ||
this.hass.localize( | ||
`ui.panel.config.zwave_js.hard_reset_controller.${ | ||
ResetStatus[this._resetStatus] | ||
}.title` | ||
) | ||
)} | ||
> | ||
<div class="flex-container"> | ||
<div> | ||
<ha-svg-icon | ||
.path=${iconMap[this._resetStatus]} | ||
.class="icon" | ||
></ha-svg-icon> | ||
</div> | ||
<p> | ||
${this.hass.localize( | ||
`ui.panel.config.zwave_js.hard_reset_controller.${ | ||
ResetStatus[this._resetStatus] | ||
}.body` | ||
)} | ||
</p> | ||
</div> | ||
${this._resetStatus === ResetStatus.NotStarted | ||
? html`<mwc-button | ||
slot="primaryAction" | ||
@click=${this._hardResetController} | ||
> | ||
${this.hass.localize("ui.common.continue")} | ||
</mwc-button> | ||
<mwc-button slot="secondaryAction" @click=${this.closeDialog}> | ||
${this.hass.localize("ui.common.cancel")} | ||
</mwc-button>` | ||
: nothing} | ||
</ha-dialog>`; | ||
} | ||
|
||
private async _hardResetController(): Promise<void> { | ||
if ( | ||
await showConfirmationDialog(this, { | ||
text: this.hass.localize( | ||
`ui.panel.config.zwave_js.hard_reset_controller.confirmation` | ||
), | ||
dismissText: this.hass.localize("ui.common.cancel"), | ||
confirmText: this.hass.localize("ui.common.continue"), | ||
destructive: true, | ||
}) | ||
) { | ||
this._resetStatus = ResetStatus.InProgress; | ||
const deviceId = await hardResetController(this.hass, this._entryId!); | ||
setTimeout(() => navigate(`/config/devices/device/${deviceId}`), 0); | ||
this._resetStatus = ResetStatus.Done; | ||
} | ||
} | ||
|
||
static get styles(): CSSResultGroup { | ||
return [ | ||
haStyleDialog, | ||
css` | ||
.icon { | ||
color: var(--label-badge-red); | ||
} | ||
.flex-container { | ||
display: flex; | ||
align-items: center; | ||
margin-bottom: 5px; | ||
} | ||
ha-svg-icon { | ||
width: 68px; | ||
height: 48px; | ||
} | ||
`, | ||
]; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"dialog-zwave_js-hard-reset-controller": DialogZWaveJSHardResetController; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ig/integrations/integration-panels/zwave_js/show-dialog-zwave_js-hard-reset-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fireEvent } from "../../../../../common/dom/fire_event"; | ||
|
||
export interface ZWaveJSHardResetControllerDialogParams { | ||
entryId: string; | ||
} | ||
|
||
export const loadHardResetControllerDialog = () => | ||
import("./dialog-zwave_js-hard-reset-controller"); | ||
|
||
export const showZWaveJSHardResetControllerDialog = ( | ||
element: HTMLElement, | ||
hardResetControllerDialogParams: ZWaveJSHardResetControllerDialogParams | ||
): void => { | ||
fireEvent(element, "show-dialog", { | ||
dialogTag: "dialog-zwave_js-hard-reset-controller", | ||
dialogImport: loadHardResetControllerDialog, | ||
dialogParams: hardResetControllerDialogParams, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters