amaran-light-cli 1.10.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +154 -17
- package/dist/__tests__/autoCct.test.js +35 -4
- package/dist/__tests__/autoCct.test.js.map +1 -1
- package/dist/__tests__/autoCctMaxLux.test.js +11 -9
- package/dist/__tests__/autoCctMaxLux.test.js.map +1 -1
- package/dist/__tests__/autostart.test.js +18 -0
- package/dist/__tests__/autostart.test.js.map +1 -1
- package/dist/__tests__/bleHttpControl.test.d.ts +2 -0
- package/dist/__tests__/bleHttpControl.test.d.ts.map +1 -0
- package/dist/__tests__/bleHttpControl.test.js +230 -0
- package/dist/__tests__/bleHttpControl.test.js.map +1 -0
- package/dist/__tests__/bleStack.test.d.ts +2 -0
- package/dist/__tests__/bleStack.test.d.ts.map +1 -0
- package/dist/__tests__/bleStack.test.js +1239 -0
- package/dist/__tests__/bleStack.test.js.map +1 -0
- package/dist/__tests__/cctUtil.test.js +11 -5
- package/dist/__tests__/cctUtil.test.js.map +1 -1
- package/dist/__tests__/circadianDashboardSettings.test.d.ts +2 -0
- package/dist/__tests__/circadianDashboardSettings.test.d.ts.map +1 -0
- package/dist/__tests__/circadianDashboardSettings.test.js +82 -0
- package/dist/__tests__/circadianDashboardSettings.test.js.map +1 -0
- package/dist/__tests__/circadianIsolation.test.d.ts +2 -0
- package/dist/__tests__/circadianIsolation.test.d.ts.map +1 -0
- package/dist/__tests__/circadianIsolation.test.js +30 -0
- package/dist/__tests__/circadianIsolation.test.js.map +1 -0
- package/dist/__tests__/cli.config.test.d.ts +2 -0
- package/dist/__tests__/cli.config.test.d.ts.map +1 -0
- package/dist/__tests__/cli.config.test.js +114 -0
- package/dist/__tests__/cli.config.test.js.map +1 -0
- package/dist/__tests__/cli.smoke.test.js +70 -17
- package/dist/__tests__/cli.smoke.test.js.map +1 -1
- package/dist/__tests__/currentCct.test.d.ts +2 -0
- package/dist/__tests__/currentCct.test.d.ts.map +1 -0
- package/dist/__tests__/currentCct.test.js +29 -0
- package/dist/__tests__/currentCct.test.js.map +1 -0
- package/dist/__tests__/dashboard.test.d.ts +2 -0
- package/dist/__tests__/dashboard.test.d.ts.map +1 -0
- package/dist/__tests__/dashboard.test.js +126 -0
- package/dist/__tests__/dashboard.test.js.map +1 -0
- package/dist/__tests__/daylightSimulationParseUtils.test.d.ts +2 -0
- package/dist/__tests__/daylightSimulationParseUtils.test.d.ts.map +1 -0
- package/dist/__tests__/daylightSimulationParseUtils.test.js +16 -0
- package/dist/__tests__/daylightSimulationParseUtils.test.js.map +1 -0
- package/dist/__tests__/desktopImport.test.d.ts +2 -0
- package/dist/__tests__/desktopImport.test.d.ts.map +1 -0
- package/dist/__tests__/desktopImport.test.js +234 -0
- package/dist/__tests__/desktopImport.test.js.map +1 -0
- package/dist/__tests__/lightControl.basic.test.d.ts +2 -0
- package/dist/__tests__/lightControl.basic.test.d.ts.map +1 -0
- package/dist/__tests__/lightControl.basic.test.js +119 -0
- package/dist/__tests__/lightControl.basic.test.js.map +1 -0
- package/dist/__tests__/lightControl.colorEffects.test.d.ts +2 -0
- package/dist/__tests__/lightControl.colorEffects.test.d.ts.map +1 -0
- package/dist/__tests__/lightControl.colorEffects.test.js +170 -0
- package/dist/__tests__/lightControl.colorEffects.test.js.map +1 -0
- package/dist/__tests__/lightControl.management.test.d.ts +2 -0
- package/dist/__tests__/lightControl.management.test.d.ts.map +1 -0
- package/dist/__tests__/lightControl.management.test.js +90 -0
- package/dist/__tests__/lightControl.management.test.js.map +1 -0
- package/dist/__tests__/lightControlTestUtils.d.ts +10 -0
- package/dist/__tests__/lightControlTestUtils.d.ts.map +1 -0
- package/dist/__tests__/lightControlTestUtils.js +57 -0
- package/dist/__tests__/lightControlTestUtils.js.map +1 -0
- package/dist/__tests__/maxLuxInterpolation.test.js +4 -2
- package/dist/__tests__/maxLuxInterpolation.test.js.map +1 -1
- package/dist/__tests__/meshConfiguration.test.d.ts +2 -0
- package/dist/__tests__/meshConfiguration.test.d.ts.map +1 -0
- package/dist/__tests__/meshConfiguration.test.js +78 -0
- package/dist/__tests__/meshConfiguration.test.js.map +1 -0
- package/dist/__tests__/nativeGroups.test.d.ts +2 -0
- package/dist/__tests__/nativeGroups.test.d.ts.map +1 -0
- package/dist/__tests__/nativeGroups.test.js +104 -0
- package/dist/__tests__/nativeGroups.test.js.map +1 -0
- package/dist/__tests__/packageExports.test.d.ts +2 -0
- package/dist/__tests__/packageExports.test.d.ts.map +1 -0
- package/dist/__tests__/packageExports.test.js +33 -0
- package/dist/__tests__/packageExports.test.js.map +1 -0
- package/dist/__tests__/programApi.test.d.ts +2 -0
- package/dist/__tests__/programApi.test.d.ts.map +1 -0
- package/dist/__tests__/programApi.test.js +73 -0
- package/dist/__tests__/programApi.test.js.map +1 -0
- package/dist/__tests__/programs.test.d.ts +2 -0
- package/dist/__tests__/programs.test.d.ts.map +1 -0
- package/dist/__tests__/programs.test.js +176 -0
- package/dist/__tests__/programs.test.js.map +1 -0
- package/dist/__tests__/scheduleMaker.test.d.ts +2 -0
- package/dist/__tests__/scheduleMaker.test.d.ts.map +1 -0
- package/dist/__tests__/scheduleMaker.test.js +25 -0
- package/dist/__tests__/scheduleMaker.test.js.map +1 -0
- package/dist/__tests__/simulateSchedule.test.js +7 -3
- package/dist/__tests__/simulateSchedule.test.js.map +1 -1
- package/dist/ble/async.d.ts +2 -0
- package/dist/ble/async.d.ts.map +1 -0
- package/dist/ble/async.js +15 -0
- package/dist/ble/async.js.map +1 -0
- package/dist/ble/colors.d.ts +5 -0
- package/dist/ble/colors.d.ts.map +1 -0
- package/dist/ble/colors.js +44 -0
- package/dist/ble/colors.js.map +1 -0
- package/dist/ble/configuration.d.ts +22 -0
- package/dist/ble/configuration.d.ts.map +1 -0
- package/dist/ble/configuration.js +122 -0
- package/dist/ble/configuration.js.map +1 -0
- package/dist/ble/controller.d.ts +118 -0
- package/dist/ble/controller.d.ts.map +1 -0
- package/dist/ble/controller.js +931 -0
- package/dist/ble/controller.js.map +1 -0
- package/dist/ble/crypto.d.ts +34 -0
- package/dist/ble/crypto.d.ts.map +1 -0
- package/dist/ble/crypto.js +178 -0
- package/dist/ble/crypto.js.map +1 -0
- package/dist/ble/daemon.d.ts +2 -0
- package/dist/ble/daemon.d.ts.map +1 -0
- package/dist/ble/daemon.js +76 -0
- package/dist/ble/daemon.js.map +1 -0
- package/dist/ble/dashboard.d.ts +331 -0
- package/dist/ble/dashboard.d.ts.map +1 -0
- package/dist/ble/dashboard.js +280 -0
- package/dist/ble/dashboard.js.map +1 -0
- package/dist/ble/desktop.d.ts +4 -0
- package/dist/ble/desktop.d.ts.map +1 -0
- package/dist/ble/desktop.js +33 -0
- package/dist/ble/desktop.js.map +1 -0
- package/dist/ble/desktopLibrary.d.ts +12 -0
- package/dist/ble/desktopLibrary.d.ts.map +1 -0
- package/dist/ble/desktopLibrary.js +346 -0
- package/dist/ble/desktopLibrary.js.map +1 -0
- package/dist/ble/effects.d.ts +34 -0
- package/dist/ble/effects.d.ts.map +1 -0
- package/dist/ble/effects.js +138 -0
- package/dist/ble/effects.js.map +1 -0
- package/dist/ble/fan.d.ts +244 -0
- package/dist/ble/fan.d.ts.map +1 -0
- package/dist/ble/fan.js +46 -0
- package/dist/ble/fan.js.map +1 -0
- package/dist/ble/library.d.ts +341 -0
- package/dist/ble/library.d.ts.map +1 -0
- package/dist/ble/library.js +201 -0
- package/dist/ble/library.js.map +1 -0
- package/dist/ble/media.d.ts +133 -0
- package/dist/ble/media.d.ts.map +1 -0
- package/dist/ble/media.js +186 -0
- package/dist/ble/media.js.map +1 -0
- package/dist/ble/nativeGroups.d.ts +22 -0
- package/dist/ble/nativeGroups.d.ts.map +1 -0
- package/dist/ble/nativeGroups.js +114 -0
- package/dist/ble/nativeGroups.js.map +1 -0
- package/dist/ble/packets.d.ts +3 -0
- package/dist/ble/packets.d.ts.map +1 -0
- package/dist/ble/packets.js +15 -0
- package/dist/ble/packets.js.map +1 -0
- package/dist/ble/programs.d.ts +318 -0
- package/dist/ble/programs.d.ts.map +1 -0
- package/dist/ble/programs.js +329 -0
- package/dist/ble/programs.js.map +1 -0
- package/dist/ble/provisioning.d.ts +13 -0
- package/dist/ble/provisioning.d.ts.map +1 -0
- package/dist/ble/provisioning.js +39 -0
- package/dist/ble/provisioning.js.map +1 -0
- package/dist/ble/server.d.ts +18 -0
- package/dist/ble/server.d.ts.map +1 -0
- package/dist/ble/server.js +548 -0
- package/dist/ble/server.js.map +1 -0
- package/dist/ble/service.d.ts +2 -0
- package/dist/ble/service.d.ts.map +1 -0
- package/dist/ble/service.js +77 -0
- package/dist/ble/service.js.map +1 -0
- package/dist/ble/settings.d.ts +18 -0
- package/dist/ble/settings.d.ts.map +1 -0
- package/dist/ble/settings.js +25 -0
- package/dist/ble/settings.js.map +1 -0
- package/dist/ble/setup.d.ts +2 -0
- package/dist/ble/setup.d.ts.map +1 -0
- package/dist/ble/setup.js +31 -0
- package/dist/ble/setup.js.map +1 -0
- package/dist/ble/storage.d.ts +94 -0
- package/dist/ble/storage.d.ts.map +1 -0
- package/dist/ble/storage.js +132 -0
- package/dist/ble/storage.js.map +1 -0
- package/dist/ble/telink.d.ts +63 -0
- package/dist/ble/telink.d.ts.map +1 -0
- package/dist/ble/telink.js +108 -0
- package/dist/ble/telink.js.map +1 -0
- package/dist/ble/transitions.d.ts +3 -0
- package/dist/ble/transitions.d.ts.map +1 -0
- package/dist/ble/transitions.js +28 -0
- package/dist/ble/transitions.js.map +1 -0
- package/dist/ble/transport.d.ts +48 -0
- package/dist/ble/transport.d.ts.map +1 -0
- package/dist/ble/transport.js +370 -0
- package/dist/ble/transport.js.map +1 -0
- package/dist/circadian.d.ts +19 -0
- package/dist/circadian.d.ts.map +1 -0
- package/dist/circadian.js +13 -0
- package/dist/circadian.js.map +1 -0
- package/dist/cli.d.ts +5 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +159 -33
- package/dist/cli.js.map +1 -1
- package/dist/commands/__tests__/integration.test.js +28 -0
- package/dist/commands/__tests__/integration.test.js.map +1 -1
- package/dist/commands/__tests__/newCommands.test.js +3 -4
- package/dist/commands/__tests__/newCommands.test.js.map +1 -1
- package/dist/commands/cmdUtils.d.ts +8 -2
- package/dist/commands/cmdUtils.d.ts.map +1 -1
- package/dist/commands/cmdUtils.js +40 -2
- package/dist/commands/cmdUtils.js.map +1 -1
- package/dist/commands/daylightSimulation/autoCct.d.ts.map +1 -1
- package/dist/commands/daylightSimulation/autoCct.js +74 -172
- package/dist/commands/daylightSimulation/autoCct.js.map +1 -1
- package/dist/commands/daylightSimulation/graphSchedule.d.ts +1 -1
- package/dist/commands/daylightSimulation/graphSchedule.d.ts.map +1 -1
- package/dist/commands/daylightSimulation/graphSchedule.js +2 -0
- package/dist/commands/daylightSimulation/graphSchedule.js.map +1 -1
- package/dist/commands/daylightSimulation/printSchedule.d.ts +1 -1
- package/dist/commands/daylightSimulation/printSchedule.d.ts.map +1 -1
- package/dist/commands/daylightSimulation/printSchedule.js +4 -2
- package/dist/commands/daylightSimulation/printSchedule.js.map +1 -1
- package/dist/commands/daylightSimulation/service.d.ts +1 -1
- package/dist/commands/daylightSimulation/service.d.ts.map +1 -1
- package/dist/commands/daylightSimulation/service.js +20 -10
- package/dist/commands/daylightSimulation/service.js.map +1 -1
- package/dist/commands/daylightSimulation/simulateSchedule.d.ts +1 -1
- package/dist/commands/daylightSimulation/simulateSchedule.d.ts.map +1 -1
- package/dist/commands/daylightSimulation/simulateSchedule.js +31 -13
- package/dist/commands/daylightSimulation/simulateSchedule.js.map +1 -1
- package/dist/commands/daylightSimulation/weather.d.ts.map +1 -1
- package/dist/commands/daylightSimulation/weather.js +19 -4
- package/dist/commands/daylightSimulation/weather.js.map +1 -1
- package/dist/commands/deviceControl/ble.d.ts +4 -0
- package/dist/commands/deviceControl/ble.d.ts.map +1 -0
- package/dist/commands/deviceControl/ble.js +214 -0
- package/dist/commands/deviceControl/ble.js.map +1 -0
- package/dist/commands/deviceControl/cct.d.ts.map +1 -1
- package/dist/commands/deviceControl/cct.js +47 -19
- package/dist/commands/deviceControl/cct.js.map +1 -1
- package/dist/commands/deviceControl/color.d.ts.map +1 -1
- package/dist/commands/deviceControl/color.js +16 -12
- package/dist/commands/deviceControl/color.js.map +1 -1
- package/dist/commands/deviceControl/config.d.ts.map +1 -1
- package/dist/commands/deviceControl/config.js +94 -58
- package/dist/commands/deviceControl/config.js.map +1 -1
- package/dist/commands/deviceControl/{discover.d.ts → desktop.d.ts} +3 -2
- package/dist/commands/deviceControl/desktop.d.ts.map +1 -0
- package/dist/commands/deviceControl/desktop.js +66 -0
- package/dist/commands/deviceControl/desktop.js.map +1 -0
- package/dist/commands/deviceControl/effect.d.ts.map +1 -1
- package/dist/commands/deviceControl/effect.js +90 -159
- package/dist/commands/deviceControl/effect.js.map +1 -1
- package/dist/commands/deviceControl/fan.d.ts.map +1 -1
- package/dist/commands/deviceControl/fan.js +77 -95
- package/dist/commands/deviceControl/fan.js.map +1 -1
- package/dist/commands/deviceControl/group.d.ts.map +1 -1
- package/dist/commands/deviceControl/group.js +43 -6
- package/dist/commands/deviceControl/group.js.map +1 -1
- package/dist/commands/deviceControl/hsi.d.ts.map +1 -1
- package/dist/commands/deviceControl/hsi.js +6 -10
- package/dist/commands/deviceControl/hsi.js.map +1 -1
- package/dist/commands/deviceControl/info.d.ts.map +1 -1
- package/dist/commands/deviceControl/info.js +0 -50
- package/dist/commands/deviceControl/info.js.map +1 -1
- package/dist/commands/deviceControl/intensity.d.ts.map +1 -1
- package/dist/commands/deviceControl/intensity.js +38 -16
- package/dist/commands/deviceControl/intensity.js.map +1 -1
- package/dist/commands/deviceControl/list.d.ts.map +1 -1
- package/dist/commands/deviceControl/list.js +21 -15
- package/dist/commands/deviceControl/list.js.map +1 -1
- package/dist/commands/deviceControl/power.d.ts.map +1 -1
- package/dist/commands/deviceControl/power.js +19 -28
- package/dist/commands/deviceControl/power.js.map +1 -1
- package/dist/commands/deviceControl/preset.d.ts.map +1 -1
- package/dist/commands/deviceControl/preset.js +56 -19
- package/dist/commands/deviceControl/preset.js.map +1 -1
- package/dist/commands/deviceControl/program.d.ts +4 -0
- package/dist/commands/deviceControl/program.d.ts.map +1 -0
- package/dist/commands/deviceControl/program.js +199 -0
- package/dist/commands/deviceControl/program.js.map +1 -0
- package/dist/commands/deviceControl/quickshot.d.ts.map +1 -1
- package/dist/commands/deviceControl/quickshot.js +75 -13
- package/dist/commands/deviceControl/quickshot.js.map +1 -1
- package/dist/commands/deviceControl/scene.d.ts.map +1 -1
- package/dist/commands/deviceControl/scene.js +72 -9
- package/dist/commands/deviceControl/scene.js.map +1 -1
- package/dist/commands/deviceControl/status.d.ts.map +1 -1
- package/dist/commands/deviceControl/status.js +29 -6
- package/dist/commands/deviceControl/status.js.map +1 -1
- package/dist/commands/parseUtils.d.ts +6 -0
- package/dist/commands/parseUtils.d.ts.map +1 -0
- package/dist/commands/parseUtils.js +32 -0
- package/dist/commands/parseUtils.js.map +1 -0
- package/dist/commands-api.d.ts +28 -0
- package/dist/commands-api.d.ts.map +1 -0
- package/dist/commands-api.js +27 -0
- package/dist/commands-api.js.map +1 -0
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +4 -2
- package/dist/commands.js.map +1 -1
- package/dist/config.d.ts +165 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +125 -0
- package/dist/config.js.map +1 -0
- package/dist/daylightSimulation/cctUtil.d.ts.map +1 -1
- package/dist/daylightSimulation/cctUtil.js +23 -22
- package/dist/daylightSimulation/cctUtil.js.map +1 -1
- package/dist/daylightSimulation/constants.d.ts +10 -0
- package/dist/daylightSimulation/constants.d.ts.map +1 -1
- package/dist/daylightSimulation/constants.js +4 -0
- package/dist/daylightSimulation/constants.js.map +1 -1
- package/dist/daylightSimulation/currentCct.d.ts +42 -0
- package/dist/daylightSimulation/currentCct.d.ts.map +1 -0
- package/dist/daylightSimulation/currentCct.js +217 -0
- package/dist/daylightSimulation/currentCct.js.map +1 -0
- package/dist/daylightSimulation/curves/realistic.d.ts +6 -6
- package/dist/daylightSimulation/curves/realistic.d.ts.map +1 -1
- package/dist/daylightSimulation/curves/realistic.js +36 -6
- package/dist/daylightSimulation/curves/realistic.js.map +1 -1
- package/dist/daylightSimulation/dashboardSettings.d.ts +47 -0
- package/dist/daylightSimulation/dashboardSettings.d.ts.map +1 -0
- package/dist/daylightSimulation/dashboardSettings.js +95 -0
- package/dist/daylightSimulation/dashboardSettings.js.map +1 -0
- package/dist/daylightSimulation/dashboardStatus.d.ts +72 -0
- package/dist/daylightSimulation/dashboardStatus.d.ts.map +1 -0
- package/dist/daylightSimulation/dashboardStatus.js +191 -0
- package/dist/daylightSimulation/dashboardStatus.js.map +1 -0
- package/dist/daylightSimulation/mathUtil.d.ts.map +1 -1
- package/dist/daylightSimulation/mathUtil.js +6 -2
- package/dist/daylightSimulation/mathUtil.js.map +1 -1
- package/dist/daylightSimulation/parseUtils.d.ts +3 -0
- package/dist/daylightSimulation/parseUtils.d.ts.map +1 -0
- package/dist/daylightSimulation/parseUtils.js +25 -0
- package/dist/daylightSimulation/parseUtils.js.map +1 -0
- package/dist/daylightSimulation/scheduleMaker.d.ts +6 -2
- package/dist/daylightSimulation/scheduleMaker.d.ts.map +1 -1
- package/dist/daylightSimulation/scheduleMaker.js +9 -11
- package/dist/daylightSimulation/scheduleMaker.js.map +1 -1
- package/dist/daylightSimulation/types.d.ts +15 -2
- package/dist/daylightSimulation/types.d.ts.map +1 -1
- package/dist/daylightSimulation/types.js +0 -2
- package/dist/daylightSimulation/types.js.map +1 -1
- package/dist/daylightSimulation/weatherUtil.d.ts.map +1 -1
- package/dist/daylightSimulation/weatherUtil.js +31 -0
- package/dist/daylightSimulation/weatherUtil.js.map +1 -1
- package/dist/device-control.d.ts +8 -0
- package/dist/device-control.d.ts.map +1 -0
- package/dist/device-control.js +8 -0
- package/dist/device-control.js.map +1 -0
- package/dist/deviceControl/autostart.d.ts.map +1 -1
- package/dist/deviceControl/autostart.js +15 -16
- package/dist/deviceControl/autostart.js.map +1 -1
- package/dist/deviceControl/bleHttpControl.d.ts +129 -0
- package/dist/deviceControl/bleHttpControl.d.ts.map +1 -0
- package/dist/deviceControl/bleHttpControl.js +753 -0
- package/dist/deviceControl/bleHttpControl.js.map +1 -0
- package/dist/deviceControl/lightControl.d.ts +9 -68
- package/dist/deviceControl/lightControl.d.ts.map +1 -1
- package/dist/deviceControl/lightControl.js +25 -255
- package/dist/deviceControl/lightControl.js.map +1 -1
- package/dist/deviceControl/lightControlCommands.d.ts +68 -0
- package/dist/deviceControl/lightControlCommands.d.ts.map +1 -0
- package/dist/deviceControl/lightControlCommands.js +244 -0
- package/dist/deviceControl/lightControlCommands.js.map +1 -0
- package/dist/deviceControl/types.d.ts +83 -4
- package/dist/deviceControl/types.d.ts.map +1 -1
- package/dist/deviceControl/types.js +1 -0
- package/dist/deviceControl/types.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/test/MockLightServer.d.ts +1 -0
- package/dist/test/MockLightServer.d.ts.map +1 -1
- package/dist/test/MockLightServer.js +5 -0
- package/dist/test/MockLightServer.js.map +1 -1
- package/docs/CHANGELOG.md +171 -0
- package/docs/DIRECT_BLE.md +359 -0
- package/package.json +39 -8
- package/scripts/ble-cli-check.ts +129 -0
- package/scripts/ble-config-probe.ts +109 -0
- package/scripts/ble-effects-check.ts +82 -0
- package/scripts/ble-extended-probe.ts +44 -0
- package/scripts/ble-fan-check.ts +129 -0
- package/scripts/ble-feature-probe.ts +37 -0
- package/scripts/ble-followup-check.ts +165 -0
- package/scripts/ble-hardware-check.ts +99 -0
- package/scripts/ble-live-extended-check.ts +205 -0
- package/scripts/ble-non-ota-check.ts +193 -0
- package/scripts/ble-probe.ts +45 -0
- package/scripts/calibrate-webcam.ts +152 -0
- package/scripts/desktop-reference.ts +85 -0
- package/scripts/webcam.ts +129 -0
- package/dist/__tests__/lightControl.test.d.ts +0 -2
- package/dist/__tests__/lightControl.test.d.ts.map +0 -1
- package/dist/__tests__/lightControl.test.js +0 -424
- package/dist/__tests__/lightControl.test.js.map +0 -1
- package/dist/commands/deviceControl/discover.d.ts.map +0 -1
- package/dist/commands/deviceControl/discover.js +0 -29
- package/dist/commands/deviceControl/discover.js.map +0 -1
|
@@ -0,0 +1,753 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { FanStateSchema, FanStatesSchema } from '../ble/fan.js';
|
|
3
|
+
import { parseFanMode, validateFanRpm } from '../ble/telink.js';
|
|
4
|
+
const DEFAULT_BLE_URL = 'http://localhost:2708';
|
|
5
|
+
const REQUEST_TIMEOUT_MS = 60_000;
|
|
6
|
+
const UNSUPPORTED_MESSAGE = 'Command is not supported by the BLE backend';
|
|
7
|
+
export default class BleHttpController {
|
|
8
|
+
baseUrl;
|
|
9
|
+
apiKey;
|
|
10
|
+
devices = [];
|
|
11
|
+
features = {};
|
|
12
|
+
constructor(baseUrl = DEFAULT_BLE_URL, apiKey) {
|
|
13
|
+
this.baseUrl = trimTrailingSlashes(baseUrl);
|
|
14
|
+
this.apiKey = apiKey;
|
|
15
|
+
}
|
|
16
|
+
static async connect(baseUrl, apiKey) {
|
|
17
|
+
const controller = new BleHttpController(baseUrl, apiKey);
|
|
18
|
+
await controller.refreshDevices();
|
|
19
|
+
return controller;
|
|
20
|
+
}
|
|
21
|
+
async disconnect() {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
getDevices() {
|
|
25
|
+
return this.devices;
|
|
26
|
+
}
|
|
27
|
+
getFixtureList(callback) {
|
|
28
|
+
this.getDeviceList(callback);
|
|
29
|
+
}
|
|
30
|
+
getDeviceList(callback) {
|
|
31
|
+
this.refreshDevices()
|
|
32
|
+
.then(() => callback?.(true, 'OK', { data: this.devices }))
|
|
33
|
+
.catch((error) => callback?.(false, error.message));
|
|
34
|
+
}
|
|
35
|
+
async getHealth(callback) {
|
|
36
|
+
try {
|
|
37
|
+
const response = await this.request('/', { method: 'GET' });
|
|
38
|
+
if (response.ok !== true)
|
|
39
|
+
throw new Error(response.error || 'BLE backend returned an error');
|
|
40
|
+
callback?.(true, 'OK', { data: response });
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
callback?.(false, error.message);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
turnLightOn(nodeId, callback) {
|
|
47
|
+
return this.postLightCommand(nodeId, 'on', undefined, callback);
|
|
48
|
+
}
|
|
49
|
+
turnLightOff(nodeId, callback) {
|
|
50
|
+
return this.postLightCommand(nodeId, 'off', undefined, callback);
|
|
51
|
+
}
|
|
52
|
+
async turnOnAllLights(callback) {
|
|
53
|
+
await this.postEachLightCommand('on', {}, callback);
|
|
54
|
+
}
|
|
55
|
+
async turnOffAllLights(callback) {
|
|
56
|
+
await this.postEachLightCommand('off', {}, callback);
|
|
57
|
+
}
|
|
58
|
+
setIntensity(nodeId, intensity, callback) {
|
|
59
|
+
return this.postLightCommand(nodeId, 'brightness', { value: this.apiIntensityToPercent(intensity) }, callback);
|
|
60
|
+
}
|
|
61
|
+
async setIntensityForAllLights(intensity, callback) {
|
|
62
|
+
await this.postEachLightCommand('brightness', { value: this.apiIntensityToPercent(intensity) }, callback);
|
|
63
|
+
}
|
|
64
|
+
setCCT(nodeId, cct, intensity, callback) {
|
|
65
|
+
return this.postLightCommand(nodeId, 'cct', this.cctBody(cct, intensity), callback);
|
|
66
|
+
}
|
|
67
|
+
async setAutomaticCCT(nodeId, cct, intensity, callback) {
|
|
68
|
+
if (!this.features.automaticCct) {
|
|
69
|
+
await this.setCCT(nodeId, cct, intensity, callback);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const response = await this.request(`/lights/${encodeURIComponent(nodeId)}/auto-cct`, {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
body: JSON.stringify(this.cctBody(cct, intensity)),
|
|
76
|
+
});
|
|
77
|
+
if (response.ok !== true)
|
|
78
|
+
throw new Error(response.error || 'Automatic CCT failed');
|
|
79
|
+
const result = z
|
|
80
|
+
.discriminatedUnion('skipped', [
|
|
81
|
+
z.object({
|
|
82
|
+
skipped: z.literal(true),
|
|
83
|
+
reason: z.enum(['manual-override', 'light-off', 'thermal-protection', 'stopped-cooling']),
|
|
84
|
+
}),
|
|
85
|
+
z.object({ skipped: z.literal(false), state: z.unknown() }),
|
|
86
|
+
])
|
|
87
|
+
.parse(response.result);
|
|
88
|
+
if (!result.skipped && response.verified !== true)
|
|
89
|
+
throw new Error('Automatic CCT was not verified');
|
|
90
|
+
if (!result.skipped) {
|
|
91
|
+
const state = this.stateRecord(result.state);
|
|
92
|
+
if (state.mode !== 'cct' || typeof state.cct !== 'number')
|
|
93
|
+
throw new Error('Automatic CCT returned invalid state');
|
|
94
|
+
}
|
|
95
|
+
callback?.(true, result.skipped ? `Skipped: ${result.reason}` : 'OK', result);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
callback?.(false, error.message);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
overrides(targets, minutes, callback) {
|
|
102
|
+
return this.libraryRequest('/overrides', 'POST', { targets, ...(minutes === undefined ? {} : { minutes }) }, callback);
|
|
103
|
+
}
|
|
104
|
+
getProductInfo(nodeId, callback) {
|
|
105
|
+
return this.libraryRequest(`/lights/${encodeURIComponent(nodeId)}/info`, 'GET', undefined, callback);
|
|
106
|
+
}
|
|
107
|
+
renameGroup(groupId, name, callback) {
|
|
108
|
+
return this.libraryRequest(`/groups/${encodeURIComponent(groupId)}/rename`, 'POST', { name }, callback);
|
|
109
|
+
}
|
|
110
|
+
getGroup(groupId, callback) {
|
|
111
|
+
return this.libraryRequest(`/groups/${encodeURIComponent(groupId)}`, 'GET', undefined, callback);
|
|
112
|
+
}
|
|
113
|
+
nativeGroup(groupId, action, address, callback) {
|
|
114
|
+
return this.libraryRequest(`/groups/${encodeURIComponent(groupId)}/native`, 'POST', { action, ...(address === undefined ? {} : { address }) }, callback);
|
|
115
|
+
}
|
|
116
|
+
inspectMesh(callback) {
|
|
117
|
+
return this.libraryRequest('/mesh/inspect', 'GET', undefined, callback);
|
|
118
|
+
}
|
|
119
|
+
discoverUnprovisioned(callback) {
|
|
120
|
+
return this.libraryRequest('/mesh/discover', 'GET', undefined, callback);
|
|
121
|
+
}
|
|
122
|
+
importDeviceKeys(database, callback) {
|
|
123
|
+
return this.libraryRequest('/mesh/keys', 'POST', { database }, callback);
|
|
124
|
+
}
|
|
125
|
+
importDesktop(database, options, callback) {
|
|
126
|
+
return this.libraryRequest('/desktop/import', 'POST', { database, ...options }, callback);
|
|
127
|
+
}
|
|
128
|
+
startProgram(program, callback) {
|
|
129
|
+
return this.libraryRequest('/programs', 'POST', program, callback);
|
|
130
|
+
}
|
|
131
|
+
getPrograms(id, callback) {
|
|
132
|
+
return this.libraryRequest(id ? `/programs/${encodeURIComponent(id)}` : '/programs', 'GET', undefined, callback);
|
|
133
|
+
}
|
|
134
|
+
stopProgram(id, callback) {
|
|
135
|
+
return this.libraryRequest(`/programs/${encodeURIComponent(id)}`, 'DELETE', undefined, callback);
|
|
136
|
+
}
|
|
137
|
+
programSample(id, sample, callback) {
|
|
138
|
+
return this.libraryRequest(`/programs/${encodeURIComponent(id)}/sample`, 'POST', sample, callback);
|
|
139
|
+
}
|
|
140
|
+
updateSaved(collection, key, name, callback) {
|
|
141
|
+
return this.libraryRequest(`/library/${collection}/${encodeURIComponent(key)}`, 'POST', { ...(name === undefined ? {} : { name }) }, callback);
|
|
142
|
+
}
|
|
143
|
+
replaceSaved(collection, key, name, keys, callback) {
|
|
144
|
+
return this.libraryRequest(`/library/${collection}/${encodeURIComponent(key)}`, 'POST', { ...(name === undefined ? {} : { name }), ...(keys === undefined ? {} : { keys }) }, callback);
|
|
145
|
+
}
|
|
146
|
+
saveSaved(collection, name, keys, callback) {
|
|
147
|
+
return this.libraryRequest(`/library/${collection}`, 'POST', { name, ...(keys === undefined ? {} : { keys }) }, callback);
|
|
148
|
+
}
|
|
149
|
+
getSaved(collection, key, callback) {
|
|
150
|
+
return this.libraryRequest(`/library/${collection}/${encodeURIComponent(key)}`, 'GET', undefined, callback);
|
|
151
|
+
}
|
|
152
|
+
transition(targets, action, args, seconds, callback) {
|
|
153
|
+
return this.runCommand('/transition', { targets, action, args, seconds }, callback);
|
|
154
|
+
}
|
|
155
|
+
transitionScene(key, seconds, callback) {
|
|
156
|
+
return this.recallSaved('scenes', key, { seconds }, callback);
|
|
157
|
+
}
|
|
158
|
+
recallSaved(collection, key, options, callback) {
|
|
159
|
+
return this.runCommand(`/library/${collection}/${encodeURIComponent(key)}/recall`, options, callback);
|
|
160
|
+
}
|
|
161
|
+
async setCCTAndIntensityForAllLights(cct, intensity, callback) {
|
|
162
|
+
await this.postEachLightCommand('cct', this.cctBody(cct, intensity), callback);
|
|
163
|
+
}
|
|
164
|
+
setHSI(nodeId, hue, sat, intensity, cct, gm, callback) {
|
|
165
|
+
if (cct !== undefined || gm !== undefined) {
|
|
166
|
+
callback?.(false, 'The 150c supports basic HSI, not advanced HSI CCT/G/M adjustments');
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
return this.postLightCommand(nodeId, 'hsi', { brightness: this.apiIntensityToPercent(intensity), hue, saturation: sat }, callback);
|
|
170
|
+
}
|
|
171
|
+
async setHSIForAllLights(hue, sat, intensity, cct, gm, callback) {
|
|
172
|
+
if (cct !== undefined || gm !== undefined) {
|
|
173
|
+
callback?.(false, 'The 150c supports basic HSI, not advanced HSI CCT/G/M adjustments');
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
await this.postEachLightCommand('hsi', { brightness: this.apiIntensityToPercent(intensity), hue, saturation: sat }, callback);
|
|
177
|
+
}
|
|
178
|
+
async getNodeConfig(nodeId, callback) {
|
|
179
|
+
const device = this.devices.find((entry) => entry.node_id === nodeId || entry.id === nodeId);
|
|
180
|
+
if (!device) {
|
|
181
|
+
callback?.(false, `Device "${nodeId}" not found`);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const capabilities = typeof device.capabilities === 'object' && device.capabilities ? device.capabilities : {};
|
|
185
|
+
if (this.features.state) {
|
|
186
|
+
await this.readState(nodeId, (success, message, state) => {
|
|
187
|
+
callback?.(success, message, success ? { data: { ...device, ...capabilities, ...z.record(z.unknown()).parse(state) } } : undefined);
|
|
188
|
+
}, true);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
callback?.(true, 'OK', { data: { ...device, ...capabilities } });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
getSceneList(callback) {
|
|
195
|
+
return this.libraryRequest('/library/scenes', 'GET', undefined, callback);
|
|
196
|
+
}
|
|
197
|
+
getLightSleepStatus(nodeId, callback) {
|
|
198
|
+
return this.readState(nodeId, callback);
|
|
199
|
+
}
|
|
200
|
+
getIntensity(nodeId, callback) {
|
|
201
|
+
return this.readState(nodeId, callback);
|
|
202
|
+
}
|
|
203
|
+
getCCT(nodeId, callback) {
|
|
204
|
+
return this.readState(nodeId, callback);
|
|
205
|
+
}
|
|
206
|
+
getHSI(nodeId, callback) {
|
|
207
|
+
return this.readState(nodeId, callback);
|
|
208
|
+
}
|
|
209
|
+
async toggleAllLights(callback) {
|
|
210
|
+
if (!this.features.toggle) {
|
|
211
|
+
this.unsupported(callback);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
await this.postEachLightCommand('toggle', {}, callback);
|
|
215
|
+
}
|
|
216
|
+
toggleLight(nodeId, callback) {
|
|
217
|
+
if (!this.features.toggle) {
|
|
218
|
+
this.unsupported(callback);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
return this.postLightCommand(nodeId, 'toggle', {}, callback);
|
|
222
|
+
}
|
|
223
|
+
incrementIntensity(nodeId, delta, callback) {
|
|
224
|
+
return this.postLightCommand(nodeId, 'increment-brightness', { delta: delta / 10 }, callback);
|
|
225
|
+
}
|
|
226
|
+
async incrementIntensityForAllLights(delta, callback) {
|
|
227
|
+
await this.postEachLightCommand('increment-brightness', { delta: delta / 10 }, callback);
|
|
228
|
+
}
|
|
229
|
+
incrementCCT(nodeId, delta, intensity, callback) {
|
|
230
|
+
return this.postLightCommand(nodeId, 'increment-cct', { delta, ...this.optionalBrightness(intensity) }, callback);
|
|
231
|
+
}
|
|
232
|
+
async incrementCCTForAllLights(delta, intensity, callback) {
|
|
233
|
+
await this.postEachLightCommand('increment-cct', { delta, ...this.optionalBrightness(intensity) }, callback);
|
|
234
|
+
}
|
|
235
|
+
setColor(nodeId, color, intensity, callback) {
|
|
236
|
+
return this.postLightCommand(nodeId, 'color', { color, ...this.optionalBrightness(intensity) }, callback);
|
|
237
|
+
}
|
|
238
|
+
async setColorForAllLights(color, intensity, callback) {
|
|
239
|
+
await this.postEachLightCommand('color', { color, ...this.optionalBrightness(intensity) }, callback);
|
|
240
|
+
}
|
|
241
|
+
getRGB(_nodeId, callback) {
|
|
242
|
+
this.unsupported(callback);
|
|
243
|
+
}
|
|
244
|
+
setRGB(_nodeId, _r, _g, _b, _intensity, callback) {
|
|
245
|
+
this.unsupported(callback);
|
|
246
|
+
}
|
|
247
|
+
getXY(_nodeId, callback) {
|
|
248
|
+
this.unsupported(callback);
|
|
249
|
+
}
|
|
250
|
+
setXY(_nodeId, _x, _y, _intensity, callback) {
|
|
251
|
+
this.unsupported(callback);
|
|
252
|
+
}
|
|
253
|
+
getSystemEffect(nodeId, callback) {
|
|
254
|
+
return this.readState(nodeId, callback);
|
|
255
|
+
}
|
|
256
|
+
getSystemEffectList(callback) {
|
|
257
|
+
return this.libraryRequest('/effects', 'GET', undefined, callback);
|
|
258
|
+
}
|
|
259
|
+
setSystemEffect(nodeId, effectType, intensity, callback) {
|
|
260
|
+
return this.postLightCommand(nodeId, 'effect', { name: effectType, ...this.optionalBrightness(intensity) }, callback);
|
|
261
|
+
}
|
|
262
|
+
async setSystemEffectForAllLights(effectType, intensity, callback) {
|
|
263
|
+
await this.postEachLightCommand('effect', { name: effectType, ...this.optionalBrightness(intensity) }, callback);
|
|
264
|
+
}
|
|
265
|
+
getEffect(nodeId, callback) {
|
|
266
|
+
return this.readState(nodeId, callback);
|
|
267
|
+
}
|
|
268
|
+
setEffect(nodeId, effectName, args, callback) {
|
|
269
|
+
return this.postLightCommand(nodeId, 'effect', { ...args, name: effectName }, callback);
|
|
270
|
+
}
|
|
271
|
+
setEffectSpeed(nodeId, speed, callback) {
|
|
272
|
+
return this.postLightCommand(nodeId, 'effect-speed', { value: speed }, callback);
|
|
273
|
+
}
|
|
274
|
+
setEffectAnimationSpeed(nodeId, speed, callback) {
|
|
275
|
+
return this.postLightCommand(nodeId, 'effect-animation-speed', { value: speed }, callback);
|
|
276
|
+
}
|
|
277
|
+
setEffectIntensity(nodeId, intensity, callback) {
|
|
278
|
+
return this.postLightCommand(nodeId, 'effect-intensity', { value: this.apiIntensityToPercent(intensity) }, callback);
|
|
279
|
+
}
|
|
280
|
+
getFanMode(nodeId, callback) {
|
|
281
|
+
return this.fanValue(nodeId, 'mode', callback);
|
|
282
|
+
}
|
|
283
|
+
async getFanInfo(nodeId, callback) {
|
|
284
|
+
if (nodeId.startsWith('group:'))
|
|
285
|
+
return this.fanStates([nodeId], undefined, callback);
|
|
286
|
+
if (!this.features.fan) {
|
|
287
|
+
this.unsupported(callback);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
const response = await this.request(`/lights/${encodeURIComponent(nodeId)}/fan`, {
|
|
292
|
+
method: 'GET',
|
|
293
|
+
});
|
|
294
|
+
if (response.ok !== true)
|
|
295
|
+
throw new Error(response.error || 'BLE fan query failed');
|
|
296
|
+
const state = FanStateSchema.parse(response.result);
|
|
297
|
+
callback?.(true, 'OK', state);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
callback?.(false, error.message);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
setFanMode(nodeId, mode, callback) {
|
|
304
|
+
if (nodeId.startsWith('group:'))
|
|
305
|
+
return this.fanStates([nodeId], mode, callback);
|
|
306
|
+
return this.postLightCommand(nodeId, 'fan', { mode }, callback);
|
|
307
|
+
}
|
|
308
|
+
async fanStates(targets, mode, callback, rpm) {
|
|
309
|
+
try {
|
|
310
|
+
if (mode === undefined && rpm !== undefined)
|
|
311
|
+
throw new Error('RPM requires manual fan mode');
|
|
312
|
+
if (mode !== undefined)
|
|
313
|
+
validateFanRpm(parseFanMode(mode), rpm);
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
callback?.(false, error.message);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (rpm !== undefined && !this.features.fanManualRpm) {
|
|
320
|
+
callback?.(false, 'Manual RPM control requires the updated BLE daemon');
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (!this.features.fanTargets) {
|
|
324
|
+
if (targets !== 'all' && targets.length === 1 && !targets[0].startsWith('group:')) {
|
|
325
|
+
const wrap = (ok, message, state) => {
|
|
326
|
+
if (!ok) {
|
|
327
|
+
callback?.(false, message);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const parsed = FanStateSchema.safeParse(state);
|
|
331
|
+
if (!parsed.success) {
|
|
332
|
+
callback?.(false, parsed.error.message);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
callback?.(true, message, { states: { [targets[0]]: parsed.data } });
|
|
336
|
+
};
|
|
337
|
+
if (mode !== undefined) {
|
|
338
|
+
await this.postLightCommand(targets[0], 'fan', { mode, ...(rpm === undefined ? {} : { rpm }) }, wrap);
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
await this.getFanInfo(targets[0], wrap);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
else
|
|
345
|
+
callback?.(false, 'Fan group/all control requires the updated BLE daemon');
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const response = await this.executeCommand('/fans', {
|
|
349
|
+
targets,
|
|
350
|
+
...(mode === undefined ? {} : { mode }),
|
|
351
|
+
...(rpm === undefined ? {} : { rpm }),
|
|
352
|
+
});
|
|
353
|
+
if (!response.success) {
|
|
354
|
+
callback?.(false, response.message);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const parsed = FanStatesSchema.safeParse(response.data);
|
|
358
|
+
if (!parsed.success) {
|
|
359
|
+
callback?.(false, parsed.error.message);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
callback?.(true, 'OK', parsed.data);
|
|
363
|
+
}
|
|
364
|
+
getFanSpeed(nodeId, callback) {
|
|
365
|
+
return this.fanValue(nodeId, 'speed', callback);
|
|
366
|
+
}
|
|
367
|
+
setFanSpeed(nodeId, speed, callback) {
|
|
368
|
+
return this.fanStates([nodeId], 'manual', callback, speed);
|
|
369
|
+
}
|
|
370
|
+
getPresetList(callback) {
|
|
371
|
+
return this.libraryRequest('/library/presets', 'GET', undefined, callback);
|
|
372
|
+
}
|
|
373
|
+
recallPreset(nodeId, presetId, callback) {
|
|
374
|
+
return this.recallSaved('presets', presetId, { target: nodeId }, callback);
|
|
375
|
+
}
|
|
376
|
+
setPreset(nodeId, presetId, callback) {
|
|
377
|
+
return this.recallPreset(nodeId, presetId, callback);
|
|
378
|
+
}
|
|
379
|
+
getQuickshotList(callback) {
|
|
380
|
+
return this.libraryRequest('/library/quickshots', 'GET', undefined, callback);
|
|
381
|
+
}
|
|
382
|
+
setQuickshot(quickshotId, callback) {
|
|
383
|
+
return this.recallSaved('quickshots', quickshotId, {}, callback);
|
|
384
|
+
}
|
|
385
|
+
saveScene(name, callback) {
|
|
386
|
+
return this.libraryRequest('/library/scenes', 'POST', { name }, callback);
|
|
387
|
+
}
|
|
388
|
+
deleteScene(sceneId, callback) {
|
|
389
|
+
return this.libraryRequest(`/library/scenes/${encodeURIComponent(sceneId)}`, 'DELETE', undefined, callback);
|
|
390
|
+
}
|
|
391
|
+
recallScene(sceneId, callback) {
|
|
392
|
+
return this.runCommand(`/library/scenes/${encodeURIComponent(sceneId)}/recall`, {}, callback);
|
|
393
|
+
}
|
|
394
|
+
updateScene(sceneId, name, callback) {
|
|
395
|
+
return this.libraryRequest(`/library/scenes/${encodeURIComponent(sceneId)}`, 'POST', { name }, callback);
|
|
396
|
+
}
|
|
397
|
+
getGroupList(callback) {
|
|
398
|
+
return this.libraryRequest('/groups', 'GET', undefined, callback);
|
|
399
|
+
}
|
|
400
|
+
createGroup(name, callback) {
|
|
401
|
+
return this.libraryRequest('/groups', 'POST', { name }, callback);
|
|
402
|
+
}
|
|
403
|
+
deleteGroup(groupId, callback) {
|
|
404
|
+
return this.libraryRequest(`/groups/${encodeURIComponent(groupId)}`, 'DELETE', undefined, callback);
|
|
405
|
+
}
|
|
406
|
+
addToGroup(groupId, nodeId, callback) {
|
|
407
|
+
return this.libraryRequest(`/groups/${encodeURIComponent(groupId)}/members`, 'POST', { member: nodeId }, callback);
|
|
408
|
+
}
|
|
409
|
+
removeFromGroup(groupId, nodeId, callback) {
|
|
410
|
+
return this.libraryRequest(`/groups/${encodeURIComponent(groupId)}/members`, 'POST', { member: nodeId, remove: true }, callback);
|
|
411
|
+
}
|
|
412
|
+
setGM(nodeId, value, callback) {
|
|
413
|
+
return this.postLightCommand(nodeId, 'gm', { value }, callback);
|
|
414
|
+
}
|
|
415
|
+
stopEffect(nodeId, callback) {
|
|
416
|
+
return this.postLightCommand(nodeId, 'effect-stop', {}, callback);
|
|
417
|
+
}
|
|
418
|
+
triggerEffect(nodeId, callback) {
|
|
419
|
+
return this.postLightCommand(nodeId, 'effect-trigger', {}, callback);
|
|
420
|
+
}
|
|
421
|
+
batch(targets, action, args, broadcast, callback) {
|
|
422
|
+
return this.runCommand('/batch', { targets, action, args, broadcast }, callback);
|
|
423
|
+
}
|
|
424
|
+
fade(targets, brightness, seconds, callback) {
|
|
425
|
+
return this.runCommand('/fade', { targets, brightness, seconds }, callback);
|
|
426
|
+
}
|
|
427
|
+
savePreset(nodeId, name, callback) {
|
|
428
|
+
return this.libraryRequest('/library/presets', 'POST', { name, keys: [nodeId] }, callback);
|
|
429
|
+
}
|
|
430
|
+
saveQuickshot(name, callback) {
|
|
431
|
+
return this.libraryRequest('/library/quickshots', 'POST', { name }, callback);
|
|
432
|
+
}
|
|
433
|
+
deleteSaved(collection, key, callback) {
|
|
434
|
+
return this.libraryRequest(`/library/${collection}/${encodeURIComponent(key)}`, 'DELETE', undefined, callback);
|
|
435
|
+
}
|
|
436
|
+
getDeviceInfo(nodeId, callback) {
|
|
437
|
+
this.getNodeConfig(nodeId, callback);
|
|
438
|
+
}
|
|
439
|
+
updateFirmware(_nodeId, callback) {
|
|
440
|
+
this.unsupported(callback);
|
|
441
|
+
}
|
|
442
|
+
async refreshDevices() {
|
|
443
|
+
const response = await this.request('/', { method: 'GET' });
|
|
444
|
+
if (response.ok !== true) {
|
|
445
|
+
throw new Error(response.error || 'BLE backend returned an error');
|
|
446
|
+
}
|
|
447
|
+
const lights = z
|
|
448
|
+
.array(z
|
|
449
|
+
.object({
|
|
450
|
+
key: z.string().min(1),
|
|
451
|
+
name: z.string().min(1),
|
|
452
|
+
mac: z.string().optional(),
|
|
453
|
+
address: z.number().optional(),
|
|
454
|
+
model: z.string().optional(),
|
|
455
|
+
capabilities: z.record(z.unknown()).optional(),
|
|
456
|
+
})
|
|
457
|
+
.passthrough())
|
|
458
|
+
.parse(response.lights);
|
|
459
|
+
this.features = z.record(z.boolean()).parse(response.features ?? {});
|
|
460
|
+
this.devices = lights.map((light) => ({
|
|
461
|
+
...light,
|
|
462
|
+
id: light.key,
|
|
463
|
+
node_id: light.key,
|
|
464
|
+
device_name: light.name,
|
|
465
|
+
name: light.name,
|
|
466
|
+
device_type: 'ble-light',
|
|
467
|
+
backend: 'ble',
|
|
468
|
+
}));
|
|
469
|
+
const groups = z
|
|
470
|
+
.array(z.object({ id: z.string(), name: z.string(), members: z.array(z.string()) }))
|
|
471
|
+
.parse(response.groups ?? []);
|
|
472
|
+
this.devices.push(...groups.map((group) => ({
|
|
473
|
+
...group,
|
|
474
|
+
node_id: group.id,
|
|
475
|
+
device_name: group.name,
|
|
476
|
+
device_type: 'ble-group',
|
|
477
|
+
backend: 'ble',
|
|
478
|
+
})));
|
|
479
|
+
}
|
|
480
|
+
async postLightCommand(nodeId, command, body, callback) {
|
|
481
|
+
if (!this.supportsCommand(command)) {
|
|
482
|
+
this.unsupported(callback);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
await this.runCommand(`/lights/${encodeURIComponent(nodeId)}/${command}`, body ?? {}, callback);
|
|
486
|
+
}
|
|
487
|
+
async postEachLightCommand(command, body, callback) {
|
|
488
|
+
if (!this.supportsCommand(command)) {
|
|
489
|
+
this.unsupported(callback);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (this.features.batch && command !== 'toggle') {
|
|
493
|
+
await this.batch('all', command, body, false, callback);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const targets = this.devices.flatMap((device) => {
|
|
497
|
+
if (device.device_type === 'ble-group')
|
|
498
|
+
return [];
|
|
499
|
+
const nodeId = typeof device.node_id === 'string' ? device.node_id : typeof device.id === 'string' ? device.id : undefined;
|
|
500
|
+
if (!nodeId)
|
|
501
|
+
return [];
|
|
502
|
+
return [
|
|
503
|
+
{
|
|
504
|
+
nodeId,
|
|
505
|
+
name: String(device.device_name || device.name || device.id || device.node_id || 'Unknown'),
|
|
506
|
+
},
|
|
507
|
+
];
|
|
508
|
+
});
|
|
509
|
+
if (targets.length === 0) {
|
|
510
|
+
callback?.(false, 'No BLE lights available');
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const failures = [];
|
|
514
|
+
for (const target of targets) {
|
|
515
|
+
const result = await this.executeCommand(`/lights/${encodeURIComponent(target.nodeId)}/${command}`, body);
|
|
516
|
+
if (!result.success) {
|
|
517
|
+
failures.push(`${String(target.name)}: ${result.message}`);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (failures.length > 0) {
|
|
521
|
+
callback?.(false, failures.join('; '));
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
callback?.(true, 'OK');
|
|
525
|
+
}
|
|
526
|
+
async runCommand(path, body, callback) {
|
|
527
|
+
const result = await this.executeCommand(path, body);
|
|
528
|
+
callback?.(result.success, result.message, result.data);
|
|
529
|
+
}
|
|
530
|
+
async libraryRequest(path, method, body, callback) {
|
|
531
|
+
const feature = path.startsWith('/programs')
|
|
532
|
+
? 'programs'
|
|
533
|
+
: path === '/desktop/import'
|
|
534
|
+
? 'desktopImport'
|
|
535
|
+
: path.startsWith('/mesh/')
|
|
536
|
+
? 'meshConfig'
|
|
537
|
+
: path === '/effects'
|
|
538
|
+
? 'effects'
|
|
539
|
+
: path === '/overrides'
|
|
540
|
+
? 'automaticCct'
|
|
541
|
+
: path.startsWith('/lights/') && path.endsWith('/info')
|
|
542
|
+
? 'productInfo'
|
|
543
|
+
: 'library';
|
|
544
|
+
if (!this.features[feature]) {
|
|
545
|
+
this.unsupported(callback);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
try {
|
|
549
|
+
const response = await this.request(path, {
|
|
550
|
+
method,
|
|
551
|
+
...(body ? { body: JSON.stringify(body) } : {}),
|
|
552
|
+
});
|
|
553
|
+
if (response.ok !== true)
|
|
554
|
+
throw new Error(response.error || 'BLE library operation failed');
|
|
555
|
+
callback?.(true, 'OK', { data: response.result });
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
callback?.(false, error.message);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
async fanValue(nodeId, field, callback) {
|
|
562
|
+
if (nodeId.startsWith('group:')) {
|
|
563
|
+
callback?.(false, 'A group has separate fan states; use fan info for per-fixture telemetry');
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
if (!this.features.fan) {
|
|
567
|
+
this.unsupported(callback);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
try {
|
|
571
|
+
const response = await this.request(`/lights/${encodeURIComponent(nodeId)}/fan`, {
|
|
572
|
+
method: 'GET',
|
|
573
|
+
});
|
|
574
|
+
if (response.ok !== true)
|
|
575
|
+
throw new Error(response.error || 'BLE fan query failed');
|
|
576
|
+
const state = FanStateSchema.parse(response.result);
|
|
577
|
+
callback?.(true, 'OK', state[field]);
|
|
578
|
+
}
|
|
579
|
+
catch (error) {
|
|
580
|
+
callback?.(false, error.message);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
async executeCommand(path, body) {
|
|
584
|
+
const feature = path === '/transition'
|
|
585
|
+
? 'transitions'
|
|
586
|
+
: path === '/batch'
|
|
587
|
+
? 'batch'
|
|
588
|
+
: path === '/fade'
|
|
589
|
+
? 'fade'
|
|
590
|
+
: path === '/fans'
|
|
591
|
+
? 'fanTargets'
|
|
592
|
+
: path.startsWith('/library/')
|
|
593
|
+
? 'library'
|
|
594
|
+
: undefined;
|
|
595
|
+
if (feature && !this.features[feature])
|
|
596
|
+
return { success: false, message: UNSUPPORTED_MESSAGE };
|
|
597
|
+
try {
|
|
598
|
+
const response = await this.request(path, {
|
|
599
|
+
method: 'POST',
|
|
600
|
+
body: JSON.stringify(body),
|
|
601
|
+
});
|
|
602
|
+
if (response.ok !== true) {
|
|
603
|
+
return { success: false, message: response.error || 'BLE backend returned an error' };
|
|
604
|
+
}
|
|
605
|
+
if (this.features.verifiedCommands && response.verified !== true) {
|
|
606
|
+
return { success: false, message: 'BLE daemon did not verify this command' };
|
|
607
|
+
}
|
|
608
|
+
return { success: true, message: 'OK', data: response.result };
|
|
609
|
+
}
|
|
610
|
+
catch (error) {
|
|
611
|
+
return { success: false, message: error.message };
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
async request(path, init) {
|
|
615
|
+
const headers = { ...(init.body ? { 'content-type': 'application/json' } : {}) };
|
|
616
|
+
if (this.apiKey) {
|
|
617
|
+
headers.authorization = `Bearer ${this.apiKey}`;
|
|
618
|
+
}
|
|
619
|
+
const url = `${this.baseUrl}${path}`;
|
|
620
|
+
const controller = new AbortController();
|
|
621
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
622
|
+
try {
|
|
623
|
+
const response = await fetch(url, { ...init, headers, signal: controller.signal });
|
|
624
|
+
const raw = await response.text();
|
|
625
|
+
const data = this.parseResponseBody(response.status === 204 && !raw ? '{"ok":true}' : raw, response.status, url);
|
|
626
|
+
if (!response.ok)
|
|
627
|
+
throw new Error(data.error || `BLE backend HTTP ${response.status}`);
|
|
628
|
+
return data;
|
|
629
|
+
}
|
|
630
|
+
catch (error) {
|
|
631
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
632
|
+
throw new Error(`BLE backend request timed out after ${REQUEST_TIMEOUT_MS}ms: ${url}`);
|
|
633
|
+
}
|
|
634
|
+
if (error instanceof TypeError)
|
|
635
|
+
throw new Error(this.formatRequestError(url, error));
|
|
636
|
+
throw error;
|
|
637
|
+
}
|
|
638
|
+
finally {
|
|
639
|
+
clearTimeout(timeout);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
formatRequestError(url, error) {
|
|
643
|
+
if (error instanceof Error) {
|
|
644
|
+
if (error instanceof TypeError && error.message === 'fetch failed') {
|
|
645
|
+
return `Unable to reach BLE backend at ${url}. Make sure the BLE service is running.`;
|
|
646
|
+
}
|
|
647
|
+
return `Unable to reach BLE backend at ${url}: ${error.message}`;
|
|
648
|
+
}
|
|
649
|
+
return `Unable to reach BLE backend at ${url}`;
|
|
650
|
+
}
|
|
651
|
+
parseResponseBody(raw, status, url) {
|
|
652
|
+
if (!raw) {
|
|
653
|
+
throw new Error(`Empty JSON response from BLE backend (${status}) at ${url}`);
|
|
654
|
+
}
|
|
655
|
+
try {
|
|
656
|
+
return JSON.parse(raw);
|
|
657
|
+
}
|
|
658
|
+
catch (error) {
|
|
659
|
+
throw new Error(`Invalid JSON response from BLE backend (${status}) at ${url}: ${error.message}`);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
cctBody(cct, intensity) {
|
|
663
|
+
return {
|
|
664
|
+
kelvin: cct,
|
|
665
|
+
...(intensity !== undefined ? { brightness: this.apiIntensityToPercent(intensity) } : {}),
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
optionalBrightness(intensity) {
|
|
669
|
+
return intensity === undefined ? {} : { brightness: this.apiIntensityToPercent(intensity) };
|
|
670
|
+
}
|
|
671
|
+
supportsCommand(command) {
|
|
672
|
+
const feature = {
|
|
673
|
+
gm: 'gm',
|
|
674
|
+
fan: 'fan',
|
|
675
|
+
color: 'color',
|
|
676
|
+
effect: 'effects',
|
|
677
|
+
'effect-speed': 'effects',
|
|
678
|
+
'effect-animation-speed': 'effects',
|
|
679
|
+
'effect-intensity': 'effects',
|
|
680
|
+
'effect-stop': 'effects',
|
|
681
|
+
'effect-trigger': 'effectTrigger',
|
|
682
|
+
'increment-cct': 'relative',
|
|
683
|
+
'increment-brightness': 'relative',
|
|
684
|
+
};
|
|
685
|
+
return !Object.hasOwn(feature, command) || this.features[feature[command]] === true;
|
|
686
|
+
}
|
|
687
|
+
apiIntensityToPercent(intensity) {
|
|
688
|
+
if (!Number.isFinite(intensity) || intensity < 0 || intensity > 1000)
|
|
689
|
+
throw new Error('Intensity must be between 0 and 1000');
|
|
690
|
+
return intensity / 10;
|
|
691
|
+
}
|
|
692
|
+
stateRecord(value) {
|
|
693
|
+
const state = z
|
|
694
|
+
.object({
|
|
695
|
+
sleep: z.boolean(),
|
|
696
|
+
intensity: z.number().min(0).max(1000),
|
|
697
|
+
mode: z.enum(['cct', 'hsi', 'effect']),
|
|
698
|
+
cct: z.number().optional(),
|
|
699
|
+
gm: z.number().optional(),
|
|
700
|
+
hue: z.number().optional(),
|
|
701
|
+
sat: z.number().optional(),
|
|
702
|
+
effect: z.string().optional(),
|
|
703
|
+
frequency: z.number().optional(),
|
|
704
|
+
speed: z.number().optional(),
|
|
705
|
+
palette: z.number().optional(),
|
|
706
|
+
observedAt: z.string(),
|
|
707
|
+
})
|
|
708
|
+
.parse(value);
|
|
709
|
+
return { ...state, work_mode: state.mode, effect_type: state.effect, effect_name: state.effect };
|
|
710
|
+
}
|
|
711
|
+
async readState(nodeId, callback, allowGroup = false) {
|
|
712
|
+
if (!this.features.state) {
|
|
713
|
+
callback?.(false, 'State readback is not available from this BLE daemon');
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
const group = this.devices.find((device) => device.node_id === nodeId)?.device_type === 'ble-group';
|
|
717
|
+
if (group && !allowGroup) {
|
|
718
|
+
callback?.(false, 'A group has separate fixture states; use status <group> to inspect its members');
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
try {
|
|
722
|
+
const response = await this.request(`/lights/${encodeURIComponent(nodeId)}/state`, {
|
|
723
|
+
method: 'GET',
|
|
724
|
+
});
|
|
725
|
+
if (response.ok !== true)
|
|
726
|
+
throw new Error(response.error || 'BLE state query failed');
|
|
727
|
+
if (group) {
|
|
728
|
+
const members = Object.fromEntries(Object.entries(z.record(z.unknown()).parse(response.result)).map(([key, value]) => {
|
|
729
|
+
const device = this.devices.find((entry) => entry.node_id === key);
|
|
730
|
+
const caps = z.record(z.unknown()).parse(device?.capabilities ?? {});
|
|
731
|
+
return [key, { ...caps, ...this.stateRecord(value) }];
|
|
732
|
+
}));
|
|
733
|
+
callback?.(true, 'OK', { work_mode: 'group', member_states: members });
|
|
734
|
+
}
|
|
735
|
+
else
|
|
736
|
+
callback?.(true, 'OK', this.stateRecord(response.result));
|
|
737
|
+
}
|
|
738
|
+
catch (error) {
|
|
739
|
+
callback?.(false, error.message);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
unsupported(callback) {
|
|
743
|
+
callback?.(false, UNSUPPORTED_MESSAGE);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
export function trimTrailingSlashes(value) {
|
|
747
|
+
let end = value.length;
|
|
748
|
+
while (end > 0 && value[end - 1] === '/') {
|
|
749
|
+
end--;
|
|
750
|
+
}
|
|
751
|
+
return value.slice(0, end);
|
|
752
|
+
}
|
|
753
|
+
//# sourceMappingURL=bleHttpControl.js.map
|