Skip to content
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
49 changes: 49 additions & 0 deletions api/lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ import {
ProvisioningEntryStatus,
AssociationCheckResult,
LinkReliabilityCheckResult,
JoinNetworkOptions,
JoinNetworkStrategy,
JoinNetworkResult,
DriverMode,
} from 'zwave-js'
import { getEnumMemberName, parseQRCodeString } from 'zwave-js/Utils'
Expand Down Expand Up @@ -221,6 +224,8 @@ export const allowedApis = validateMethods([
'checkForConfigUpdates',
'installConfigUpdate',
'shutdownZwaveAPI',
'startLearnMode',
'stopLearnMode',
'pingNode',
'restart',
'grantSecurityClasses',
Expand Down Expand Up @@ -2998,6 +3003,50 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
}
}

/**
* Stops learn mode
*/
stopLearnMode(): Promise<boolean> {
if (this.driverReady) {
if (this.commandsTimeout) {
clearTimeout(this.commandsTimeout)
this.commandsTimeout = null
}
return this._driver.controller.stopJoiningNetwork()
}

throw new DriverNotReadyError()
}

/**
* Starts learn mode
*/
async startLearnMode(): Promise<JoinNetworkResult> {
if (this.driverReady) {
if (this.commandsTimeout) {
clearTimeout(this.commandsTimeout)
this.commandsTimeout = null
}

this.commandsTimeout = setTimeout(
() => {
this.stopLearnMode().catch(logger.error)
},
(this.cfg.commandsTimeout || 0) * 1000 || 30000,
)

const joinNetworkOptions: JoinNetworkOptions = {
strategy: JoinNetworkStrategy.Default,
}

return this._driver.controller.beginJoiningNetwork(
joinNetworkOptions,
)
}

throw new DriverNotReadyError()
}

/**
* Request an update of this value
*
Expand Down
19 changes: 19 additions & 0 deletions src/views/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,25 @@ export default {
color: 'warning',
desc: 'Allows to shutdown the Zwave API to safely unplug the Zwave stick.',
},
{
text: 'Learn mode',
options: [
{
name: 'Start',
action: 'startLearnMode',
args: {
confirm:
'Initiate learn mode on primary controller first and then click OK here.',
},
},
Comment on lines +326 to +333
Copy link
Member

Choose a reason for hiding this comment

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

I would also add the stop action here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added
image

{
name: 'Stop',
action: 'stopLearnMode',
},
],
icon: 'join_inner',
desc: 'Instruct controller to run learning mode (can join pre-existing network)',
},
],
rules: {
required: (value) => {
Expand Down
Loading