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

feat(ui, zwaveclient): learn/secondary controller mode #4097

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Add learn mode support
ArtemKiyashko committed Jan 19, 2025
commit be7e4c1cc535c0a324877f7b06d79b5f305c7f6f
47 changes: 47 additions & 0 deletions api/lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
@@ -108,6 +108,9 @@ import {
ProvisioningEntryStatus,
AssociationCheckResult,
LinkReliabilityCheckResult,
JoinNetworkOptions,
JoinNetworkStrategy,
JoinNetworkResult,
} from 'zwave-js'
import { getEnumMemberName, parseQRCodeString } from 'zwave-js/Utils'
import { configDbDir, logsDir, nvmBackupsDir, storeDir } from '../config/app'
@@ -217,6 +220,8 @@ export const allowedApis = validateMethods([
'checkForConfigUpdates',
'installConfigUpdate',
'shutdownZwaveAPI',
'startLearnMode',
'stopLearnMode',
'pingNode',
'restart',
'grantSecurityClasses',
@@ -2891,6 +2896,48 @@ 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,
)

let joinNetworkOptions: JoinNetworkOptions = {
strategy: JoinNetworkStrategy.Default
}

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

throw new DriverNotReadyError()
}

/**
* Request an update of this value
*
15 changes: 15 additions & 0 deletions src/views/ControlPanel.vue
Original file line number Diff line number Diff line change
@@ -308,6 +308,21 @@ 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 lear mode on primary controller first and then click OK here.',
},
},
],
icon: 'join_inner',
desc: 'Instruct controller to run learning mode (can join pre-existing network)',
},
],
rules: {
required: (value) => {