Skip to content

Commit

Permalink
Add capability example
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Feb 16, 2024
1 parent c2e7b98 commit 66b73c5
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions examples/capabiliy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
import type { Builder, Command, Describe } from 'landlubber'

import type { Handler } from './index.js'

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface Options {}

export const command: Command = 'locks'

export const describe: Describe = 'List locks'

export const builder: Builder = {}

export const handler: Handler<Options> = async ({ seam, logger }) => {
const devices = await seam.devices.list()

for (const device of devices) {
if (!device.can_program_online_access_codes) {
await seam.devices.update({
device_id: device.device_id,
is_managed: false,
})
}
}

const unmanagedDevices = await seam.devices.list()

for (const device of unmanagedDevices) {
if (device.can_program_online_access_codes) {
await seam.devices.unmanaged.update({
device_id: device.device_id,
is_managed: true,
})
}
}

const devicesWithNonFunctioningCapabilities = [
...devices,
...unmanagedDevices,
].filter(
(device) =>
'can_program_online_access_codes' in device &&
!device.can_program_online_access_codes,
)

for (const device of devicesWithNonFunctioningCapabilities) {
if (
device.warnings.some(
(warning) => warning.warning_code === 'missing_keypad',
)
) {
logger.info(
{ device },
'Inform user installing a keypad is required to program access codes',
)
}
}
}

0 comments on commit 66b73c5

Please sign in to comment.