-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 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
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', | ||
) | ||
} | ||
} | ||
} |