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 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
47 changes: 47 additions & 0 deletions api/lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
ProvisioningEntryStatus,
AssociationCheckResult,
LinkReliabilityCheckResult,
JoinNetworkOptions,
JoinNetworkStrategy,
JoinNetworkResult,
} from 'zwave-js'
import { getEnumMemberName, parseQRCodeString } from 'zwave-js/Utils'
import { configDbDir, logsDir, nvmBackupsDir, storeDir } from '../config/app'
Expand Down Expand Up @@ -217,6 +220,8 @@
'checkForConfigUpdates',
'installConfigUpdate',
'shutdownZwaveAPI',
'startLearnMode',
'stopLearnMode',
'pingNode',
'restart',
'grantSecurityClasses',
Expand Down Expand Up @@ -2891,6 +2896,48 @@
}
}

/**
* 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)

Check failure on line 2935 in api/lib/ZwaveClient.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Replace `joinNetworkOptions` with `⏎↹↹↹↹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 @@ -321,6 +321,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 +327 to +334
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
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