@switchbot/homebridge-switchbot 5.0.0-beta.70 → 5.0.0-beta.72
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/.github/ISSUE_TEMPLATE/e2e-verification.md +36 -0
- package/.github/workflows/ci.yml +61 -0
- package/.github/workflows/manual-e2e.yml +103 -0
- package/CHANGELOG.md +20 -0
- package/E2E-VERIFICATION.md +121 -0
- package/MIGRATION.md +44 -0
- package/README.md +11 -0
- package/config.schema.json +99 -1940
- package/dist/deviceFactory.d.ts +13 -0
- package/dist/deviceFactory.d.ts.map +1 -0
- package/dist/deviceFactory.js +81 -0
- package/dist/deviceFactory.js.map +1 -0
- package/dist/devices/deviceBase.d.ts +50 -0
- package/dist/devices/deviceBase.d.ts.map +1 -0
- package/dist/devices/deviceBase.js +119 -0
- package/dist/devices/deviceBase.js.map +1 -0
- package/dist/devices/genericDevice.d.ts +283 -0
- package/dist/devices/genericDevice.d.ts.map +1 -0
- package/dist/devices/genericDevice.js +1035 -0
- package/dist/devices/genericDevice.js.map +1 -0
- package/dist/homebridge-ui/public/index.html +72 -440
- package/dist/homebridge-ui/server.d.ts +3 -1
- package/dist/homebridge-ui/server.d.ts.map +1 -1
- package/dist/homebridge-ui/server.js +47 -10
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/platform.d.ts +27 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +404 -0
- package/dist/platform.js.map +1 -0
- package/dist/settings.d.ts +10 -317
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +5 -30
- package/dist/settings.js.map +1 -1
- package/dist/switchbotClient.d.ts +32 -0
- package/dist/switchbotClient.d.ts.map +1 -0
- package/dist/switchbotClient.js +259 -0
- package/dist/switchbotClient.js.map +1 -0
- package/dist/utils.d.ts +36 -248
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +38 -1367
- package/dist/utils.js.map +1 -1
- package/docs/assets/icons.js +1 -1
- package/docs/assets/icons.svg +1 -1
- package/docs/assets/style.css +3 -3
- package/docs/index.html +50 -15
- package/docs/variables/default.html +1 -1
- package/package.json +19 -18
- package/scripts/e2e/README.md +25 -0
- package/scripts/e2e/curtain-e2e.sh +70 -0
- package/scripts/e2e/fan-e2e.sh +75 -0
- package/scripts/e2e/light-advanced-e2e.sh +97 -0
- package/scripts/e2e/light-e2e.sh +75 -0
- package/scripts/e2e/list-accessories.sh +19 -0
- package/scripts/e2e/lock-e2e.sh +65 -0
- package/scripts/generate-matter-maps.js +60 -0
- package/scripts/run-e2e-local.sh +14 -0
- package/src/deviceFactory.ts +122 -0
- package/src/devices/deviceBase.ts +141 -0
- package/src/devices/genericDevice.ts +965 -0
- package/src/homebridge-ui/public/index.html +72 -440
- package/src/homebridge-ui/server.ts +52 -10
- package/src/index.ts +1 -3
- package/src/platform.ts +395 -0
- package/src/settings.ts +12 -352
- package/src/switchbotClient.ts +266 -0
- package/src/utils.ts +47 -1456
- package/test/accessory-restore.spec.ts +73 -0
- package/test/device-mapping.spec.ts +37 -0
- package/test/deviceFactory.spec.ts +18 -0
- package/test/e2e/run-e2e.spec.ts +50 -0
- package/test/fan-swing.spec.ts +29 -0
- package/test/helpers/matter-harness.ts +53 -0
- package/test/lock-users.spec.ts +44 -0
- package/test/matter-childbridge.spec.ts +55 -0
- package/test/matter-descriptors.spec.ts +97 -0
- package/test/matter-device-state.spec.ts +101 -0
- package/test/matter-integration.spec.ts +70 -0
- package/test/platform.integration.spec.ts +55 -0
- package/test/switchbot-client-debounce.spec.ts +131 -0
- package/test/switchbot-client-openapi.spec.ts +56 -0
- package/test/switchbotClient.spec.ts +10 -0
- package/test/utils.spec.ts +20 -0
- package/vitest.config.ts +7 -0
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -15847
- package/coverage/coverage-final.json +0 -42
- package/coverage/docs/assets/dmt/dmt-component-data.js.html +0 -85
- package/coverage/docs/assets/dmt/dmt-components.js.html +0 -286
- package/coverage/docs/assets/dmt/index.html +0 -131
- package/coverage/docs/assets/hierarchy.js.html +0 -85
- package/coverage/docs/assets/icons.js.html +0 -136
- package/coverage/docs/assets/index.html +0 -146
- package/coverage/docs/assets/main.js.html +0 -265
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -191
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/coverage/src/device/blindtilt.ts.html +0 -3238
- package/coverage/src/device/bot.ts.html +0 -2803
- package/coverage/src/device/ceilinglight.ts.html +0 -2338
- package/coverage/src/device/colorbulb.ts.html +0 -2824
- package/coverage/src/device/contact.ts.html +0 -1465
- package/coverage/src/device/curtain.ts.html +0 -2869
- package/coverage/src/device/device.ts.html +0 -2500
- package/coverage/src/device/fan.ts.html +0 -2242
- package/coverage/src/device/hub.ts.html +0 -1408
- package/coverage/src/device/humidifier.ts.html +0 -2116
- package/coverage/src/device/index.html +0 -416
- package/coverage/src/device/iosensor.ts.html +0 -1375
- package/coverage/src/device/lightstrip.ts.html +0 -2617
- package/coverage/src/device/lock.ts.html +0 -1963
- package/coverage/src/device/meter.ts.html +0 -1372
- package/coverage/src/device/meterplus.ts.html +0 -1384
- package/coverage/src/device/meterpro.ts.html +0 -1618
- package/coverage/src/device/motion.ts.html +0 -1264
- package/coverage/src/device/plug.ts.html +0 -1372
- package/coverage/src/device/relayswitch.ts.html +0 -2284
- package/coverage/src/device/robotvacuumcleaner.ts.html +0 -1810
- package/coverage/src/device/waterdetector.ts.html +0 -1294
- package/coverage/src/homebridge-ui/index.html +0 -116
- package/coverage/src/homebridge-ui/server.ts.html +0 -229
- package/coverage/src/index.html +0 -161
- package/coverage/src/index.ts.html +0 -124
- package/coverage/src/irdevice/airconditioner.ts.html +0 -1687
- package/coverage/src/irdevice/airpurifier.ts.html +0 -844
- package/coverage/src/irdevice/camera.ts.html +0 -475
- package/coverage/src/irdevice/fan.ts.html +0 -766
- package/coverage/src/irdevice/index.html +0 -251
- package/coverage/src/irdevice/irdevice.ts.html +0 -1117
- package/coverage/src/irdevice/light.ts.html +0 -826
- package/coverage/src/irdevice/other.ts.html +0 -2458
- package/coverage/src/irdevice/tv.ts.html +0 -1222
- package/coverage/src/irdevice/vacuumcleaner.ts.html +0 -466
- package/coverage/src/irdevice/waterheater.ts.html +0 -469
- package/coverage/src/platform.ts.html +0 -8776
- package/coverage/src/settings.ts.html +0 -934
- package/coverage/src/utils.ts.html +0 -2092
- package/dist/devices-hap/airpurifier.d.ts +0 -54
- package/dist/devices-hap/airpurifier.d.ts.map +0 -1
- package/dist/devices-hap/airpurifier.js +0 -533
- package/dist/devices-hap/airpurifier.js.map +0 -1
- package/dist/devices-hap/blindtilt.d.ts +0 -90
- package/dist/devices-hap/blindtilt.d.ts.map +0 -1
- package/dist/devices-hap/blindtilt.js +0 -974
- package/dist/devices-hap/blindtilt.js.map +0 -1
- package/dist/devices-hap/bot.d.ts +0 -102
- package/dist/devices-hap/bot.d.ts.map +0 -1
- package/dist/devices-hap/bot.js +0 -822
- package/dist/devices-hap/bot.js.map +0 -1
- package/dist/devices-hap/ceilinglight.d.ts +0 -85
- package/dist/devices-hap/ceilinglight.d.ts.map +0 -1
- package/dist/devices-hap/ceilinglight.js +0 -707
- package/dist/devices-hap/ceilinglight.js.map +0 -1
- package/dist/devices-hap/colorbulb.d.ts +0 -88
- package/dist/devices-hap/colorbulb.d.ts.map +0 -1
- package/dist/devices-hap/colorbulb.js +0 -921
- package/dist/devices-hap/colorbulb.js.map +0 -1
- package/dist/devices-hap/contact.d.ts +0 -44
- package/dist/devices-hap/contact.d.ts.map +0 -1
- package/dist/devices-hap/contact.js +0 -409
- package/dist/devices-hap/contact.js.map +0 -1
- package/dist/devices-hap/curtain.d.ts +0 -73
- package/dist/devices-hap/curtain.d.ts.map +0 -1
- package/dist/devices-hap/curtain.js +0 -869
- package/dist/devices-hap/curtain.js.map +0 -1
- package/dist/devices-hap/device.d.ts +0 -108
- package/dist/devices-hap/device.d.ts.map +0 -1
- package/dist/devices-hap/device.js +0 -821
- package/dist/devices-hap/device.js.map +0 -1
- package/dist/devices-hap/fan.d.ts +0 -69
- package/dist/devices-hap/fan.d.ts.map +0 -1
- package/dist/devices-hap/fan.js +0 -655
- package/dist/devices-hap/fan.js.map +0 -1
- package/dist/devices-hap/hub.d.ts +0 -37
- package/dist/devices-hap/hub.d.ts.map +0 -1
- package/dist/devices-hap/hub.js +0 -393
- package/dist/devices-hap/hub.js.map +0 -1
- package/dist/devices-hap/humidifier.d.ts +0 -73
- package/dist/devices-hap/humidifier.d.ts.map +0 -1
- package/dist/devices-hap/humidifier.js +0 -716
- package/dist/devices-hap/humidifier.js.map +0 -1
- package/dist/devices-hap/iosensor.d.ts +0 -42
- package/dist/devices-hap/iosensor.d.ts.map +0 -1
- package/dist/devices-hap/iosensor.js +0 -397
- package/dist/devices-hap/iosensor.js.map +0 -1
- package/dist/devices-hap/lightstrip.d.ts +0 -79
- package/dist/devices-hap/lightstrip.d.ts.map +0 -1
- package/dist/devices-hap/lightstrip.js +0 -827
- package/dist/devices-hap/lightstrip.js.map +0 -1
- package/dist/devices-hap/lock.d.ts +0 -53
- package/dist/devices-hap/lock.d.ts.map +0 -1
- package/dist/devices-hap/lock.js +0 -569
- package/dist/devices-hap/lock.js.map +0 -1
- package/dist/devices-hap/meter.d.ts +0 -37
- package/dist/devices-hap/meter.d.ts.map +0 -1
- package/dist/devices-hap/meter.js +0 -380
- package/dist/devices-hap/meter.js.map +0 -1
- package/dist/devices-hap/meterplus.d.ts +0 -42
- package/dist/devices-hap/meterplus.d.ts.map +0 -1
- package/dist/devices-hap/meterplus.js +0 -385
- package/dist/devices-hap/meterplus.js.map +0 -1
- package/dist/devices-hap/meterpro.d.ts +0 -43
- package/dist/devices-hap/meterpro.d.ts.map +0 -1
- package/dist/devices-hap/meterpro.js +0 -469
- package/dist/devices-hap/meterpro.js.map +0 -1
- package/dist/devices-hap/motion.d.ts +0 -42
- package/dist/devices-hap/motion.d.ts.map +0 -1
- package/dist/devices-hap/motion.js +0 -345
- package/dist/devices-hap/motion.js.map +0 -1
- package/dist/devices-hap/plug.d.ts +0 -49
- package/dist/devices-hap/plug.d.ts.map +0 -1
- package/dist/devices-hap/plug.js +0 -400
- package/dist/devices-hap/plug.js.map +0 -1
- package/dist/devices-hap/relayswitch.d.ts +0 -96
- package/dist/devices-hap/relayswitch.d.ts.map +0 -1
- package/dist/devices-hap/relayswitch.js +0 -642
- package/dist/devices-hap/relayswitch.js.map +0 -1
- package/dist/devices-hap/robotvacuumcleaner.d.ts +0 -54
- package/dist/devices-hap/robotvacuumcleaner.d.ts.map +0 -1
- package/dist/devices-hap/robotvacuumcleaner.js +0 -530
- package/dist/devices-hap/robotvacuumcleaner.js.map +0 -1
- package/dist/devices-hap/waterdetector.d.ts +0 -41
- package/dist/devices-hap/waterdetector.d.ts.map +0 -1
- package/dist/devices-hap/waterdetector.js +0 -356
- package/dist/devices-hap/waterdetector.js.map +0 -1
- package/dist/devices-matter/BaseMatterAccessory.d.ts +0 -90
- package/dist/devices-matter/BaseMatterAccessory.d.ts.map +0 -1
- package/dist/devices-matter/BaseMatterAccessory.js +0 -264
- package/dist/devices-matter/BaseMatterAccessory.js.map +0 -1
- package/dist/devices-matter/ColorLightAccessory.d.ts +0 -20
- package/dist/devices-matter/ColorLightAccessory.d.ts.map +0 -1
- package/dist/devices-matter/ColorLightAccessory.js +0 -95
- package/dist/devices-matter/ColorLightAccessory.js.map +0 -1
- package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts +0 -18
- package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +0 -1
- package/dist/devices-matter/ColorTemperatureLightAccessory.js +0 -76
- package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +0 -1
- package/dist/devices-matter/ContactSensorAccessory.d.ts +0 -12
- package/dist/devices-matter/ContactSensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/ContactSensorAccessory.js +0 -34
- package/dist/devices-matter/ContactSensorAccessory.js.map +0 -1
- package/dist/devices-matter/DimmableLightAccessory.d.ts +0 -58
- package/dist/devices-matter/DimmableLightAccessory.d.ts.map +0 -1
- package/dist/devices-matter/DimmableLightAccessory.js +0 -167
- package/dist/devices-matter/DimmableLightAccessory.js.map +0 -1
- package/dist/devices-matter/DoorLockAccessory.d.ts +0 -14
- package/dist/devices-matter/DoorLockAccessory.d.ts.map +0 -1
- package/dist/devices-matter/DoorLockAccessory.js +0 -50
- package/dist/devices-matter/DoorLockAccessory.js.map +0 -1
- package/dist/devices-matter/ExtendedColorLightAccessory.d.ts +0 -21
- package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +0 -1
- package/dist/devices-matter/ExtendedColorLightAccessory.js +0 -106
- package/dist/devices-matter/ExtendedColorLightAccessory.js.map +0 -1
- package/dist/devices-matter/FanAccessory.d.ts +0 -16
- package/dist/devices-matter/FanAccessory.d.ts.map +0 -1
- package/dist/devices-matter/FanAccessory.js +0 -81
- package/dist/devices-matter/FanAccessory.js.map +0 -1
- package/dist/devices-matter/HumiditySensorAccessory.d.ts +0 -12
- package/dist/devices-matter/HumiditySensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/HumiditySensorAccessory.js +0 -34
- package/dist/devices-matter/HumiditySensorAccessory.js.map +0 -1
- package/dist/devices-matter/LeakSensorAccessory.d.ts +0 -12
- package/dist/devices-matter/LeakSensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/LeakSensorAccessory.js +0 -33
- package/dist/devices-matter/LeakSensorAccessory.js.map +0 -1
- package/dist/devices-matter/LightSensorAccessory.d.ts +0 -12
- package/dist/devices-matter/LightSensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/LightSensorAccessory.js +0 -34
- package/dist/devices-matter/LightSensorAccessory.js.map +0 -1
- package/dist/devices-matter/OccupancySensorAccessory.d.ts +0 -12
- package/dist/devices-matter/OccupancySensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/OccupancySensorAccessory.js +0 -39
- package/dist/devices-matter/OccupancySensorAccessory.js.map +0 -1
- package/dist/devices-matter/OnOffLightAccessory.d.ts +0 -38
- package/dist/devices-matter/OnOffLightAccessory.d.ts.map +0 -1
- package/dist/devices-matter/OnOffLightAccessory.js +0 -110
- package/dist/devices-matter/OnOffLightAccessory.js.map +0 -1
- package/dist/devices-matter/OnOffOutletAccessory.d.ts +0 -14
- package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +0 -1
- package/dist/devices-matter/OnOffOutletAccessory.js +0 -43
- package/dist/devices-matter/OnOffOutletAccessory.js.map +0 -1
- package/dist/devices-matter/OnOffSwitchAccessory.d.ts +0 -14
- package/dist/devices-matter/OnOffSwitchAccessory.d.ts.map +0 -1
- package/dist/devices-matter/OnOffSwitchAccessory.js +0 -42
- package/dist/devices-matter/OnOffSwitchAccessory.js.map +0 -1
- package/dist/devices-matter/RoboticVacuumAccessory.d.ts +0 -61
- package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +0 -1
- package/dist/devices-matter/RoboticVacuumAccessory.js +0 -544
- package/dist/devices-matter/RoboticVacuumAccessory.js.map +0 -1
- package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts +0 -11
- package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts.map +0 -1
- package/dist/devices-matter/SmokeCOAlarmAccessory.js +0 -49
- package/dist/devices-matter/SmokeCOAlarmAccessory.js.map +0 -1
- package/dist/devices-matter/TemperatureSensorAccessory.d.ts +0 -12
- package/dist/devices-matter/TemperatureSensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/TemperatureSensorAccessory.js +0 -36
- package/dist/devices-matter/TemperatureSensorAccessory.js.map +0 -1
- package/dist/devices-matter/ThermostatAccessory.d.ts +0 -19
- package/dist/devices-matter/ThermostatAccessory.d.ts.map +0 -1
- package/dist/devices-matter/ThermostatAccessory.js +0 -95
- package/dist/devices-matter/ThermostatAccessory.js.map +0 -1
- package/dist/devices-matter/VenetianBlindAccessory.d.ts +0 -19
- package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +0 -1
- package/dist/devices-matter/VenetianBlindAccessory.js +0 -99
- package/dist/devices-matter/VenetianBlindAccessory.js.map +0 -1
- package/dist/devices-matter/WindowBlindAccessory.d.ts +0 -17
- package/dist/devices-matter/WindowBlindAccessory.d.ts.map +0 -1
- package/dist/devices-matter/WindowBlindAccessory.js +0 -131
- package/dist/devices-matter/WindowBlindAccessory.js.map +0 -1
- package/dist/devices-matter/custom/PowerStripAccessory.d.ts +0 -97
- package/dist/devices-matter/custom/PowerStripAccessory.d.ts.map +0 -1
- package/dist/devices-matter/custom/PowerStripAccessory.js +0 -265
- package/dist/devices-matter/custom/PowerStripAccessory.js.map +0 -1
- package/dist/devices-matter/custom/index.d.ts +0 -8
- package/dist/devices-matter/custom/index.d.ts.map +0 -1
- package/dist/devices-matter/custom/index.js +0 -8
- package/dist/devices-matter/custom/index.js.map +0 -1
- package/dist/devices-matter/index.d.ts +0 -29
- package/dist/devices-matter/index.d.ts.map +0 -1
- package/dist/devices-matter/index.js +0 -28
- package/dist/devices-matter/index.js.map +0 -1
- package/dist/irdevice/airconditioner.d.ts +0 -61
- package/dist/irdevice/airconditioner.d.ts.map +0 -1
- package/dist/irdevice/airconditioner.js +0 -472
- package/dist/irdevice/airconditioner.js.map +0 -1
- package/dist/irdevice/airpurifier.d.ts +0 -50
- package/dist/irdevice/airpurifier.d.ts.map +0 -1
- package/dist/irdevice/airpurifier.js +0 -213
- package/dist/irdevice/airpurifier.js.map +0 -1
- package/dist/irdevice/camera.d.ts +0 -32
- package/dist/irdevice/camera.d.ts.map +0 -1
- package/dist/irdevice/camera.js +0 -107
- package/dist/irdevice/camera.js.map +0 -1
- package/dist/irdevice/fan.d.ts +0 -36
- package/dist/irdevice/fan.d.ts.map +0 -1
- package/dist/irdevice/fan.js +0 -200
- package/dist/irdevice/fan.js.map +0 -1
- package/dist/irdevice/irdevice.d.ts +0 -69
- package/dist/irdevice/irdevice.d.ts.map +0 -1
- package/dist/irdevice/irdevice.js +0 -339
- package/dist/irdevice/irdevice.js.map +0 -1
- package/dist/irdevice/light.d.ts +0 -36
- package/dist/irdevice/light.d.ts.map +0 -1
- package/dist/irdevice/light.js +0 -206
- package/dist/irdevice/light.js.map +0 -1
- package/dist/irdevice/other.d.ts +0 -57
- package/dist/irdevice/other.d.ts.map +0 -1
- package/dist/irdevice/other.js +0 -778
- package/dist/irdevice/other.js.map +0 -1
- package/dist/irdevice/tv.d.ts +0 -45
- package/dist/irdevice/tv.d.ts.map +0 -1
- package/dist/irdevice/tv.js +0 -327
- package/dist/irdevice/tv.js.map +0 -1
- package/dist/irdevice/vacuumcleaner.d.ts +0 -28
- package/dist/irdevice/vacuumcleaner.d.ts.map +0 -1
- package/dist/irdevice/vacuumcleaner.js +0 -104
- package/dist/irdevice/vacuumcleaner.js.map +0 -1
- package/dist/irdevice/waterheater.d.ts +0 -30
- package/dist/irdevice/waterheater.d.ts.map +0 -1
- package/dist/irdevice/waterheater.js +0 -105
- package/dist/irdevice/waterheater.js.map +0 -1
- package/dist/platform-hap.d.ts +0 -160
- package/dist/platform-hap.d.ts.map +0 -1
- package/dist/platform-hap.js +0 -3041
- package/dist/platform-hap.js.map +0 -1
- package/dist/platform-matter.d.ts +0 -188
- package/dist/platform-matter.d.ts.map +0 -1
- package/dist/platform-matter.js +0 -2545
- package/dist/platform-matter.js.map +0 -1
- package/dist/test/apiRequestTracker.test.d.ts +0 -2
- package/dist/test/apiRequestTracker.test.d.ts.map +0 -1
- package/dist/test/apiRequestTracker.test.js +0 -392
- package/dist/test/apiRequestTracker.test.js.map +0 -1
- package/dist/test/hap/device-webhook-context.test.d.ts +0 -2
- package/dist/test/hap/device-webhook-context.test.d.ts.map +0 -1
- package/dist/test/hap/device-webhook-context.test.js +0 -128
- package/dist/test/hap/device-webhook-context.test.js.map +0 -1
- package/dist/test/hap/platform-hap.logging.test.d.ts +0 -2
- package/dist/test/hap/platform-hap.logging.test.d.ts.map +0 -1
- package/dist/test/hap/platform-hap.logging.test.js +0 -33
- package/dist/test/hap/platform-hap.logging.test.js.map +0 -1
- package/dist/test/hap/platform-hap.test.d.ts +0 -2
- package/dist/test/hap/platform-hap.test.d.ts.map +0 -1
- package/dist/test/hap/platform-hap.test.js +0 -62
- package/dist/test/hap/platform-hap.test.js.map +0 -1
- package/dist/test/helpers/platform-fixtures.d.ts +0 -9
- package/dist/test/helpers/platform-fixtures.d.ts.map +0 -1
- package/dist/test/helpers/platform-fixtures.js +0 -30
- package/dist/test/helpers/platform-fixtures.js.map +0 -1
- package/dist/test/homebridge-ui/server.test.d.ts +0 -2
- package/dist/test/homebridge-ui/server.test.d.ts.map +0 -1
- package/dist/test/homebridge-ui/server.test.js +0 -445
- package/dist/test/homebridge-ui/server.test.js.map +0 -1
- package/dist/test/index.test.d.ts +0 -2
- package/dist/test/index.test.d.ts.map +0 -1
- package/dist/test/index.test.js +0 -19
- package/dist/test/index.test.js.map +0 -1
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.d.ts +0 -2
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.d.ts.map +0 -1
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.js +0 -71
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.js.map +0 -1
- package/dist/test/matter/platform-matter.additional.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.additional.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.additional.test.js +0 -35
- package/dist/test/matter/platform-matter.additional.test.js.map +0 -1
- package/dist/test/matter/platform-matter.bleparse.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.bleparse.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.bleparse.test.js +0 -43
- package/dist/test/matter/platform-matter.bleparse.test.js.map +0 -1
- package/dist/test/matter/platform-matter.cleanup.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.cleanup.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.cleanup.test.js +0 -70
- package/dist/test/matter/platform-matter.cleanup.test.js.map +0 -1
- package/dist/test/matter/platform-matter.keepstale.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.keepstale.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.keepstale.test.js +0 -27
- package/dist/test/matter/platform-matter.keepstale.test.js.map +0 -1
- package/dist/test/matter/platform-matter.logging.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.logging.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.logging.test.js +0 -29
- package/dist/test/matter/platform-matter.logging.test.js.map +0 -1
- package/dist/test/matter/platform-matter.mapping.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.mapping.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.mapping.test.js +0 -43
- package/dist/test/matter/platform-matter.mapping.test.js.map +0 -1
- package/dist/test/matter/platform-matter.openapi-mapping.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.openapi-mapping.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.openapi-mapping.test.js +0 -84
- package/dist/test/matter/platform-matter.openapi-mapping.test.js.map +0 -1
- package/dist/test/matter/platform-matter.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.test.js +0 -117
- package/dist/test/matter/platform-matter.test.js.map +0 -1
- package/dist/test/matter/platform-matter.unregister.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.unregister.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.unregister.test.js +0 -30
- package/dist/test/matter/platform-matter.unregister.test.js.map +0 -1
- package/dist/test/matter/platform-matter.webhook.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.webhook.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.webhook.test.js +0 -46
- package/dist/test/matter/platform-matter.webhook.test.js.map +0 -1
- package/dist/test/utils.test.d.ts +0 -2
- package/dist/test/utils.test.d.ts.map +0 -1
- package/dist/test/utils.test.js +0 -95
- package/dist/test/utils.test.js.map +0 -1
- package/dist/test/verifyconfig.test.d.ts +0 -2
- package/dist/test/verifyconfig.test.d.ts.map +0 -1
- package/dist/test/verifyconfig.test.js +0 -167
- package/dist/test/verifyconfig.test.js.map +0 -1
- package/src/custom.d.ts +0 -7
- package/src/devices-hap/airpurifier.ts +0 -568
- package/src/devices-hap/blindtilt.ts +0 -1049
- package/src/devices-hap/bot.ts +0 -910
- package/src/devices-hap/ceilinglight.ts +0 -747
- package/src/devices-hap/colorbulb.ts +0 -940
- package/src/devices-hap/contact.ts +0 -457
- package/src/devices-hap/curtain.ts +0 -944
- package/src/devices-hap/device.ts +0 -890
- package/src/devices-hap/fan.ts +0 -716
- package/src/devices-hap/hub.ts +0 -440
- package/src/devices-hap/humidifier.ts +0 -762
- package/src/devices-hap/iosensor.ts +0 -442
- package/src/devices-hap/lightstrip.ts +0 -863
- package/src/devices-hap/lock.ts +0 -627
- package/src/devices-hap/meter.ts +0 -427
- package/src/devices-hap/meterplus.ts +0 -431
- package/src/devices-hap/meterpro.ts +0 -523
- package/src/devices-hap/motion.ts +0 -390
- package/src/devices-hap/plug.ts +0 -427
- package/src/devices-hap/relayswitch.ts +0 -727
- package/src/devices-hap/robotvacuumcleaner.ts +0 -574
- package/src/devices-hap/waterdetector.ts +0 -400
- package/src/devices-matter/BaseMatterAccessory.ts +0 -302
- package/src/devices-matter/ColorLightAccessory.ts +0 -110
- package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -90
- package/src/devices-matter/ContactSensorAccessory.ts +0 -41
- package/src/devices-matter/DimmableLightAccessory.ts +0 -192
- package/src/devices-matter/DoorLockAccessory.ts +0 -60
- package/src/devices-matter/ExtendedColorLightAccessory.ts +0 -122
- package/src/devices-matter/FanAccessory.ts +0 -95
- package/src/devices-matter/HumiditySensorAccessory.ts +0 -41
- package/src/devices-matter/LeakSensorAccessory.ts +0 -40
- package/src/devices-matter/LightSensorAccessory.ts +0 -41
- package/src/devices-matter/OccupancySensorAccessory.ts +0 -48
- package/src/devices-matter/OnOffLightAccessory.ts +0 -125
- package/src/devices-matter/OnOffOutletAccessory.ts +0 -51
- package/src/devices-matter/OnOffSwitchAccessory.ts +0 -51
- package/src/devices-matter/RoboticVacuumAccessory.ts +0 -621
- package/src/devices-matter/SmokeCOAlarmAccessory.ts +0 -59
- package/src/devices-matter/TemperatureSensorAccessory.ts +0 -43
- package/src/devices-matter/ThermostatAccessory.ts +0 -110
- package/src/devices-matter/VenetianBlindAccessory.ts +0 -115
- package/src/devices-matter/WindowBlindAccessory.ts +0 -135
- package/src/devices-matter/custom/PowerStripAccessory.ts +0 -309
- package/src/devices-matter/custom/index.ts +0 -8
- package/src/devices-matter/index.ts +0 -29
- package/src/irdevice/airconditioner.ts +0 -533
- package/src/irdevice/airpurifier.ts +0 -252
- package/src/irdevice/camera.ts +0 -129
- package/src/irdevice/fan.ts +0 -226
- package/src/irdevice/irdevice.ts +0 -383
- package/src/irdevice/light.ts +0 -246
- package/src/irdevice/other.ts +0 -790
- package/src/irdevice/tv.ts +0 -378
- package/src/irdevice/vacuumcleaner.ts +0 -126
- package/src/irdevice/waterheater.ts +0 -127
- package/src/platform-hap.ts +0 -3193
- package/src/platform-matter.ts +0 -2703
- package/src/test/apiRequestTracker.test.ts +0 -417
- package/src/test/hap/device-webhook-context.test.ts +0 -136
- package/src/test/hap/platform-hap.logging.test.ts +0 -36
- package/src/test/hap/platform-hap.test.ts +0 -70
- package/src/test/helpers/platform-fixtures.ts +0 -33
- package/src/test/homebridge-ui/server.test.ts +0 -486
- package/src/test/index.test.ts +0 -24
- package/src/test/matter/devices-matter/baseMatterAccessory.test.ts +0 -88
- package/src/test/matter/platform-matter.additional.test.ts +0 -44
- package/src/test/matter/platform-matter.bleparse.test.ts +0 -47
- package/src/test/matter/platform-matter.cleanup.test.ts +0 -86
- package/src/test/matter/platform-matter.keepstale.test.ts +0 -37
- package/src/test/matter/platform-matter.logging.test.ts +0 -33
- package/src/test/matter/platform-matter.mapping.test.ts +0 -57
- package/src/test/matter/platform-matter.openapi-mapping.test.ts +0 -109
- package/src/test/matter/platform-matter.test.ts +0 -144
- package/src/test/matter/platform-matter.unregister.test.ts +0 -39
- package/src/test/matter/platform-matter.webhook.test.ts +0 -54
- package/src/test/utils.test.ts +0 -96
- package/src/test/verifyconfig.test.ts +0 -198
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
import type { API, Logging } from 'homebridge'
|
|
2
|
-
|
|
3
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, unlinkSync } from 'node:fs'
|
|
4
|
-
import { tmpdir } from 'node:os'
|
|
5
|
-
import { join } from 'node:path'
|
|
6
|
-
|
|
7
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
8
|
-
|
|
9
|
-
import { ApiRequestTracker } from '../utils.js'
|
|
10
|
-
|
|
11
|
-
// Helper to create isolated test environment for each test
|
|
12
|
-
function createTestEnvironment(pluginName = 'SwitchBotTest') {
|
|
13
|
-
const testId = Math.random().toString(36).substring(7)
|
|
14
|
-
const testDir = join(tmpdir(), `switchbot-test-${testId}`)
|
|
15
|
-
|
|
16
|
-
// Create test directory
|
|
17
|
-
if (!existsSync(testDir)) {
|
|
18
|
-
mkdirSync(testDir, { recursive: true })
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const testStatsFile = join(testDir, `${pluginName.toLowerCase()}-api-stats.json`)
|
|
22
|
-
|
|
23
|
-
// Mock API with a unique storage path per test
|
|
24
|
-
const mockApi = {
|
|
25
|
-
user: {
|
|
26
|
-
storagePath: () => testDir,
|
|
27
|
-
},
|
|
28
|
-
} as unknown as API
|
|
29
|
-
|
|
30
|
-
// Mock logger
|
|
31
|
-
const mockLog = {
|
|
32
|
-
info: vi.fn(),
|
|
33
|
-
warn: vi.fn(),
|
|
34
|
-
error: vi.fn(),
|
|
35
|
-
debug: vi.fn(),
|
|
36
|
-
} as unknown as Logging
|
|
37
|
-
|
|
38
|
-
return { mockApi, mockLog, testStatsFile, testDir }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Cleanup helper
|
|
42
|
-
function cleanup(testDir: string) {
|
|
43
|
-
try {
|
|
44
|
-
if (existsSync(testDir)) {
|
|
45
|
-
const files = readdirSync(testDir)
|
|
46
|
-
for (const file of files) {
|
|
47
|
-
try {
|
|
48
|
-
unlinkSync(join(testDir, file))
|
|
49
|
-
} catch {
|
|
50
|
-
// ignore
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
rmdirSync(testDir)
|
|
54
|
-
}
|
|
55
|
-
} catch {
|
|
56
|
-
// ignore
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
describe('apiRequestTracker', () => {
|
|
61
|
-
describe('initialization', () => {
|
|
62
|
-
it('should create a new tracker with default limits', () => {
|
|
63
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
64
|
-
try {
|
|
65
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
|
|
66
|
-
expect(tracker).toBeDefined()
|
|
67
|
-
expect(tracker.getCount()).toBe(0)
|
|
68
|
-
expect(tracker.getDate()).toBe(new Date().toISOString().split('T')[0])
|
|
69
|
-
} finally {
|
|
70
|
-
cleanup(testDir)
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('should respect custom daily limit', () => {
|
|
75
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
76
|
-
try {
|
|
77
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
78
|
-
dailyLimit: 5000,
|
|
79
|
-
reserveForCommands: 500,
|
|
80
|
-
})
|
|
81
|
-
expect(tracker).toBeDefined()
|
|
82
|
-
} finally {
|
|
83
|
-
cleanup(testDir)
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('should load existing stats from file', () => {
|
|
88
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
89
|
-
try {
|
|
90
|
-
// Create a tracker, increment, and verify persistence
|
|
91
|
-
const tracker1 = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
|
|
92
|
-
tracker1.track()
|
|
93
|
-
tracker1.track()
|
|
94
|
-
expect(tracker1.getCount()).toBe(2)
|
|
95
|
-
|
|
96
|
-
// Create a new tracker instance and verify it loads the count
|
|
97
|
-
const tracker2 = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
|
|
98
|
-
expect(tracker2.getCount()).toBe(2)
|
|
99
|
-
} finally {
|
|
100
|
-
cleanup(testDir)
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
describe('track() - legacy method', () => {
|
|
106
|
-
it('should increment the counter', () => {
|
|
107
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
108
|
-
try {
|
|
109
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
|
|
110
|
-
expect(tracker.getCount()).toBe(0)
|
|
111
|
-
tracker.track()
|
|
112
|
-
expect(tracker.getCount()).toBe(1)
|
|
113
|
-
tracker.track()
|
|
114
|
-
expect(tracker.getCount()).toBe(2)
|
|
115
|
-
} finally {
|
|
116
|
-
cleanup(testDir)
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('should persist count to file', () => {
|
|
121
|
-
const { mockApi, mockLog, testStatsFile, testDir } = createTestEnvironment()
|
|
122
|
-
try {
|
|
123
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
|
|
124
|
-
tracker.track()
|
|
125
|
-
tracker.track()
|
|
126
|
-
tracker.track()
|
|
127
|
-
|
|
128
|
-
// Read the stats file directly
|
|
129
|
-
const statsContent = readFileSync(testStatsFile, 'utf8')
|
|
130
|
-
const stats = JSON.parse(statsContent)
|
|
131
|
-
expect(stats.count).toBe(3)
|
|
132
|
-
expect(stats.date).toBe(new Date().toISOString().split('T')[0])
|
|
133
|
-
} finally {
|
|
134
|
-
cleanup(testDir)
|
|
135
|
-
}
|
|
136
|
-
})
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
describe('trySpend() - budget enforcement', () => {
|
|
140
|
-
it('should allow commands when under soft cap', () => {
|
|
141
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
142
|
-
try {
|
|
143
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
144
|
-
dailyLimit: 100,
|
|
145
|
-
reserveForCommands: 20,
|
|
146
|
-
})
|
|
147
|
-
// Use 50 requests (well under soft cap of 80)
|
|
148
|
-
for (let i = 0; i < 50; i++) {
|
|
149
|
-
expect(tracker.trySpend('command')).toBe(true)
|
|
150
|
-
}
|
|
151
|
-
expect(tracker.getCount()).toBe(50)
|
|
152
|
-
} finally {
|
|
153
|
-
cleanup(testDir)
|
|
154
|
-
}
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
it('should allow polling when under soft cap', () => {
|
|
158
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
159
|
-
try {
|
|
160
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
161
|
-
dailyLimit: 100,
|
|
162
|
-
reserveForCommands: 20,
|
|
163
|
-
})
|
|
164
|
-
// Use 50 requests
|
|
165
|
-
for (let i = 0; i < 50; i++) {
|
|
166
|
-
expect(tracker.trySpend('poll')).toBe(true)
|
|
167
|
-
}
|
|
168
|
-
expect(tracker.getCount()).toBe(50)
|
|
169
|
-
} finally {
|
|
170
|
-
cleanup(testDir)
|
|
171
|
-
}
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
it('should block polling at soft cap when pausePollingAtReserve is true', () => {
|
|
175
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
176
|
-
try {
|
|
177
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
178
|
-
dailyLimit: 100,
|
|
179
|
-
reserveForCommands: 20,
|
|
180
|
-
pausePollingAtReserve: true, // Enable soft cap blocking
|
|
181
|
-
})
|
|
182
|
-
// Use up to soft cap (80 requests)
|
|
183
|
-
for (let i = 0; i < 80; i++) {
|
|
184
|
-
tracker.track()
|
|
185
|
-
}
|
|
186
|
-
expect(tracker.getCount()).toBe(80)
|
|
187
|
-
|
|
188
|
-
// Polling should be blocked at soft cap
|
|
189
|
-
expect(tracker.trySpend('poll')).toBe(false)
|
|
190
|
-
expect(tracker.trySpend('discovery')).toBe(false)
|
|
191
|
-
|
|
192
|
-
// Commands should still work
|
|
193
|
-
expect(tracker.trySpend('command')).toBe(true)
|
|
194
|
-
expect(tracker.getCount()).toBe(81)
|
|
195
|
-
} finally {
|
|
196
|
-
cleanup(testDir)
|
|
197
|
-
}
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
it('should block all requests at hard cap', () => {
|
|
201
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
202
|
-
try {
|
|
203
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
204
|
-
dailyLimit: 100,
|
|
205
|
-
reserveForCommands: 20,
|
|
206
|
-
})
|
|
207
|
-
// Use up to hard cap
|
|
208
|
-
for (let i = 0; i < 100; i++) {
|
|
209
|
-
tracker.track()
|
|
210
|
-
}
|
|
211
|
-
expect(tracker.getCount()).toBe(100)
|
|
212
|
-
|
|
213
|
-
// All request types should be blocked
|
|
214
|
-
expect(tracker.trySpend('poll')).toBe(false)
|
|
215
|
-
expect(tracker.trySpend('discovery')).toBe(false)
|
|
216
|
-
expect(tracker.trySpend('command')).toBe(false)
|
|
217
|
-
expect(tracker.getCount()).toBe(100)
|
|
218
|
-
} finally {
|
|
219
|
-
cleanup(testDir)
|
|
220
|
-
}
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
it('should support batch spending', () => {
|
|
224
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
225
|
-
try {
|
|
226
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
227
|
-
dailyLimit: 100,
|
|
228
|
-
reserveForCommands: 20,
|
|
229
|
-
})
|
|
230
|
-
expect(tracker.trySpend('poll', 10)).toBe(true)
|
|
231
|
-
expect(tracker.getCount()).toBe(10)
|
|
232
|
-
|
|
233
|
-
expect(tracker.trySpend('command', 5)).toBe(true)
|
|
234
|
-
expect(tracker.getCount()).toBe(15)
|
|
235
|
-
} finally {
|
|
236
|
-
cleanup(testDir)
|
|
237
|
-
}
|
|
238
|
-
})
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
describe('webhookOnlyOnReserve mode', () => {
|
|
242
|
-
it('should continue polling beyond soft cap when pausePollingAtReserve is false', () => {
|
|
243
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
244
|
-
try {
|
|
245
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
246
|
-
dailyLimit: 100,
|
|
247
|
-
reserveForCommands: 20,
|
|
248
|
-
pausePollingAtReserve: false,
|
|
249
|
-
})
|
|
250
|
-
// Use 85 requests (past soft cap)
|
|
251
|
-
for (let i = 0; i < 85; i++) {
|
|
252
|
-
tracker.track()
|
|
253
|
-
}
|
|
254
|
-
expect(tracker.getCount()).toBe(85)
|
|
255
|
-
|
|
256
|
-
// Polling should still work (not paused at reserve)
|
|
257
|
-
expect(tracker.trySpend('poll')).toBe(true)
|
|
258
|
-
expect(tracker.getCount()).toBe(86)
|
|
259
|
-
} finally {
|
|
260
|
-
cleanup(testDir)
|
|
261
|
-
}
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
it('should stop polling at soft cap when pausePollingAtReserve is true', () => {
|
|
265
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
266
|
-
try {
|
|
267
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
268
|
-
dailyLimit: 100,
|
|
269
|
-
reserveForCommands: 20,
|
|
270
|
-
pausePollingAtReserve: true,
|
|
271
|
-
})
|
|
272
|
-
// Use up to soft cap
|
|
273
|
-
for (let i = 0; i < 80; i++) {
|
|
274
|
-
tracker.track()
|
|
275
|
-
}
|
|
276
|
-
expect(tracker.getCount()).toBe(80)
|
|
277
|
-
|
|
278
|
-
// Polling should be blocked
|
|
279
|
-
expect(tracker.trySpend('poll')).toBe(false)
|
|
280
|
-
expect(tracker.getCount()).toBe(80)
|
|
281
|
-
|
|
282
|
-
// Commands should still work
|
|
283
|
-
expect(tracker.trySpend('command')).toBe(true)
|
|
284
|
-
expect(tracker.getCount()).toBe(81)
|
|
285
|
-
} finally {
|
|
286
|
-
cleanup(testDir)
|
|
287
|
-
}
|
|
288
|
-
})
|
|
289
|
-
})
|
|
290
|
-
|
|
291
|
-
describe('warning logs', () => {
|
|
292
|
-
it('should log warning when reaching soft cap with pausePollingAtReserve enabled', () => {
|
|
293
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
294
|
-
try {
|
|
295
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
296
|
-
dailyLimit: 100,
|
|
297
|
-
reserveForCommands: 20,
|
|
298
|
-
pausePollingAtReserve: true, // Enable soft cap warning
|
|
299
|
-
})
|
|
300
|
-
// Use up to soft cap
|
|
301
|
-
for (let i = 0; i < 80; i++) {
|
|
302
|
-
tracker.track()
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// Trigger soft cap warning by attempting poll (will be blocked)
|
|
306
|
-
tracker.trySpend('poll')
|
|
307
|
-
expect(mockLog.warn).toHaveBeenCalledWith(
|
|
308
|
-
expect.stringContaining('Near daily limit'),
|
|
309
|
-
)
|
|
310
|
-
} finally {
|
|
311
|
-
cleanup(testDir)
|
|
312
|
-
}
|
|
313
|
-
})
|
|
314
|
-
|
|
315
|
-
it('should log error when reaching hard cap', () => {
|
|
316
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
317
|
-
try {
|
|
318
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
319
|
-
dailyLimit: 100,
|
|
320
|
-
reserveForCommands: 20,
|
|
321
|
-
})
|
|
322
|
-
// Use up to hard cap
|
|
323
|
-
for (let i = 0; i < 100; i++) {
|
|
324
|
-
tracker.track()
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// Trigger hard cap error
|
|
328
|
-
tracker.trySpend('command')
|
|
329
|
-
expect(mockLog.error).toHaveBeenCalledWith(
|
|
330
|
-
expect.stringContaining('Daily limit'),
|
|
331
|
-
)
|
|
332
|
-
} finally {
|
|
333
|
-
cleanup(testDir)
|
|
334
|
-
}
|
|
335
|
-
})
|
|
336
|
-
})
|
|
337
|
-
|
|
338
|
-
describe('hourly logging', () => {
|
|
339
|
-
it('should log immediately on startup', () => {
|
|
340
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
341
|
-
try {
|
|
342
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
|
|
343
|
-
tracker.startHourlyLogging()
|
|
344
|
-
tracker.stopHourlyLogging()
|
|
345
|
-
expect(mockLog.info).toHaveBeenCalledWith(
|
|
346
|
-
expect.stringContaining('[API Stats] Today'),
|
|
347
|
-
)
|
|
348
|
-
} finally {
|
|
349
|
-
cleanup(testDir)
|
|
350
|
-
}
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
it('should stop logging when stopHourlyLogging is called', () => {
|
|
354
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
355
|
-
try {
|
|
356
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
|
|
357
|
-
tracker.startHourlyLogging()
|
|
358
|
-
tracker.stopHourlyLogging()
|
|
359
|
-
// Should not throw
|
|
360
|
-
expect(true).toBe(true)
|
|
361
|
-
} finally {
|
|
362
|
-
cleanup(testDir)
|
|
363
|
-
}
|
|
364
|
-
})
|
|
365
|
-
})
|
|
366
|
-
|
|
367
|
-
describe('edge cases', () => {
|
|
368
|
-
it('should handle zero daily limit', () => {
|
|
369
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
370
|
-
try {
|
|
371
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
372
|
-
dailyLimit: 0,
|
|
373
|
-
reserveForCommands: 0,
|
|
374
|
-
})
|
|
375
|
-
// All requests should be blocked immediately
|
|
376
|
-
expect(tracker.trySpend('poll')).toBe(false)
|
|
377
|
-
expect(tracker.trySpend('command')).toBe(false)
|
|
378
|
-
expect(tracker.getCount()).toBe(0)
|
|
379
|
-
} finally {
|
|
380
|
-
cleanup(testDir)
|
|
381
|
-
}
|
|
382
|
-
})
|
|
383
|
-
|
|
384
|
-
it('should handle reserve larger than limit', () => {
|
|
385
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
386
|
-
try {
|
|
387
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
388
|
-
dailyLimit: 100,
|
|
389
|
-
reserveForCommands: 150,
|
|
390
|
-
pausePollingAtReserve: true, // Enable soft cap blocking
|
|
391
|
-
})
|
|
392
|
-
// Soft cap would be negative (100 - 150 = -50), clamped to 0
|
|
393
|
-
// With pausePollingAtReserve=true, polling should be blocked immediately
|
|
394
|
-
expect(tracker.trySpend('poll')).toBe(false)
|
|
395
|
-
// Commands up to hard cap should work
|
|
396
|
-
expect(tracker.trySpend('command')).toBe(true)
|
|
397
|
-
} finally {
|
|
398
|
-
cleanup(testDir)
|
|
399
|
-
}
|
|
400
|
-
})
|
|
401
|
-
|
|
402
|
-
it('should handle negative values in config', () => {
|
|
403
|
-
const { mockApi, mockLog, testDir } = createTestEnvironment()
|
|
404
|
-
try {
|
|
405
|
-
const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
|
|
406
|
-
dailyLimit: -100,
|
|
407
|
-
reserveForCommands: -50,
|
|
408
|
-
})
|
|
409
|
-
// Should be treated as 0
|
|
410
|
-
expect(tracker.trySpend('poll')).toBe(false)
|
|
411
|
-
expect(tracker.trySpend('command')).toBe(false)
|
|
412
|
-
} finally {
|
|
413
|
-
cleanup(testDir)
|
|
414
|
-
}
|
|
415
|
-
})
|
|
416
|
-
})
|
|
417
|
-
})
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/first */
|
|
2
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
-
// Mock modules used by HAP device base occasionally via platform
|
|
4
|
-
vi.mock('fakegato-history', () => ({ default: () => ({}) }))
|
|
5
|
-
vi.mock('homebridge-lib/EveHomeKitTypes', () => ({ EveHomeKitTypes: class { constructor() {} } }))
|
|
6
|
-
|
|
7
|
-
import { deviceBase } from '../../devices-hap/device.js'
|
|
8
|
-
|
|
9
|
-
// Minimal HAP stub to satisfy deviceBase constructor operations
|
|
10
|
-
function makeHapStub() {
|
|
11
|
-
class Service {
|
|
12
|
-
private _chars: Record<string, any> = {}
|
|
13
|
-
setCharacteristic(k: any, v: any) {
|
|
14
|
-
this._chars[k] = v
|
|
15
|
-
return this
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
getCharacteristic(k: any) {
|
|
19
|
-
return {
|
|
20
|
-
updateValue: (v: any) => {
|
|
21
|
-
this._chars[k] = v
|
|
22
|
-
return this
|
|
23
|
-
},
|
|
24
|
-
} as any
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const Characteristic: any = {
|
|
28
|
-
Manufacturer: 'Manufacturer',
|
|
29
|
-
AppMatchingIdentifier: 'AppMatchingIdentifier',
|
|
30
|
-
Name: 'Name',
|
|
31
|
-
ConfiguredName: 'ConfiguredName',
|
|
32
|
-
Model: 'Model',
|
|
33
|
-
ProductData: 'ProductData',
|
|
34
|
-
SerialNumber: 'SerialNumber',
|
|
35
|
-
HardwareRevision: 'HardwareRevision',
|
|
36
|
-
SoftwareRevision: 'SoftwareRevision',
|
|
37
|
-
FirmwareRevision: 'FirmwareRevision',
|
|
38
|
-
On: 'On',
|
|
39
|
-
}
|
|
40
|
-
;(Service as any).AccessoryInformation = class extends Service {}
|
|
41
|
-
;(Service as any).Outlet = class extends Service {}
|
|
42
|
-
return { Service, Characteristic, Categories: { OUTLET: 7 } }
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Minimal PlatformAccessory stub
|
|
46
|
-
function makeAccessoryStub(hap: any, name = 'Test Accessory') {
|
|
47
|
-
const services: any[] = []
|
|
48
|
-
return {
|
|
49
|
-
displayName: name,
|
|
50
|
-
category: 0,
|
|
51
|
-
context: {},
|
|
52
|
-
getService(cls: any) {
|
|
53
|
-
// find existing or create
|
|
54
|
-
const svc = services.find(s => s instanceof cls)
|
|
55
|
-
if (svc) {
|
|
56
|
-
return svc
|
|
57
|
-
}
|
|
58
|
-
const s = new cls()
|
|
59
|
-
services.push(s)
|
|
60
|
-
return s
|
|
61
|
-
},
|
|
62
|
-
addService(cls: any) {
|
|
63
|
-
const s = new cls()
|
|
64
|
-
services.push(s)
|
|
65
|
-
return s
|
|
66
|
-
},
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Minimal SwitchBotHAPPlatform-like stub with required surface
|
|
71
|
-
function makePlatformStub(options: any, hap: any) {
|
|
72
|
-
const log = { info: vi.fn(), warn: vi.fn(), debug: vi.fn(), error: vi.fn(), success: vi.fn() }
|
|
73
|
-
return {
|
|
74
|
-
api: { hap },
|
|
75
|
-
log,
|
|
76
|
-
config: { options, credentials: {} },
|
|
77
|
-
debugMode: false,
|
|
78
|
-
// logging helpers used by deviceBase
|
|
79
|
-
infoLog: () => {},
|
|
80
|
-
successLog: () => {},
|
|
81
|
-
debugSuccessLog: () => {},
|
|
82
|
-
warnLog: () => {},
|
|
83
|
-
debugWarnLog: () => {},
|
|
84
|
-
errorLog: () => {},
|
|
85
|
-
debugErrorLog: () => {},
|
|
86
|
-
debugLog: () => {},
|
|
87
|
-
loggingIsDebug: async () => false,
|
|
88
|
-
enablingPlatformLogging: async () => true,
|
|
89
|
-
connectBLE: vi.fn(),
|
|
90
|
-
bleEventHandler: {},
|
|
91
|
-
webhookEventHandler: {},
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Create a tiny concrete subclass to instantiate deviceBase
|
|
96
|
-
class TestHAPDevice extends deviceBase {
|
|
97
|
-
// Override any methods that may be invoked by tests if needed
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
describe('hap device base webhook context', () => {
|
|
101
|
-
it('sets accessory.context.webhook=true when global webhook is enabled and device.webhook is undefined', async () => {
|
|
102
|
-
const hap = makeHapStub()
|
|
103
|
-
const accessory: any = makeAccessoryStub(hap, 'Plug Device')
|
|
104
|
-
const platform: any = makePlatformStub({ webhook: true, logging: 'debug' }, hap)
|
|
105
|
-
|
|
106
|
-
const dev: any = {
|
|
107
|
-
deviceId: 'DEV-HAP-1',
|
|
108
|
-
deviceType: 'Plug',
|
|
109
|
-
connectionType: 'OpenAPI',
|
|
110
|
-
// webhook intentionally undefined
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const d = new TestHAPDevice(platform, accessory, dev)
|
|
114
|
-
// Assert context
|
|
115
|
-
expect(accessory.context.webhook).toBe(true)
|
|
116
|
-
// ensure no unused var warning
|
|
117
|
-
expect(d).toBeDefined()
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('keeps accessory.context.webhook=false when device.webhook=false even if global is true', async () => {
|
|
121
|
-
const hap = makeHapStub()
|
|
122
|
-
const accessory: any = makeAccessoryStub(hap, 'Plug Device 2')
|
|
123
|
-
const platform: any = makePlatformStub({ webhook: true, logging: 'debug' }, hap)
|
|
124
|
-
|
|
125
|
-
const dev: any = {
|
|
126
|
-
deviceId: 'DEV-HAP-2',
|
|
127
|
-
deviceType: 'Plug',
|
|
128
|
-
connectionType: 'OpenAPI',
|
|
129
|
-
webhook: false,
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const d = new TestHAPDevice(platform, accessory, dev)
|
|
133
|
-
expect(accessory.context.webhook).toBe(false)
|
|
134
|
-
expect(d).toBeDefined()
|
|
135
|
-
})
|
|
136
|
-
})
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/first */
|
|
2
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
-
// Mock modules used by the HAP platform constructor to avoid requiring a real Homebridge API
|
|
4
|
-
vi.mock('fakegato-history', () => ({ default: () => ({}) }))
|
|
5
|
-
vi.mock('homebridge-lib/EveHomeKitTypes', () => ({ EveHomeKitTypes: class { constructor() {} } }))
|
|
6
|
-
|
|
7
|
-
import { SwitchBotHAPPlatform } from '../../platform-hap.js'
|
|
8
|
-
import { makeLogStub } from '../helpers/platform-fixtures.js'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Verifies that HAP platform debug logger includes the accessory displayName
|
|
12
|
-
* when loading an accessory from the cache.
|
|
13
|
-
*/
|
|
14
|
-
describe('platform-hap logging', () => {
|
|
15
|
-
it('prints accessory name when loading HAP cached accessory', async () => {
|
|
16
|
-
const api: any = { on: vi.fn() }
|
|
17
|
-
const log: any = makeLogStub()
|
|
18
|
-
|
|
19
|
-
const platform = new SwitchBotHAPPlatform(log as any, {
|
|
20
|
-
name: 'SwitchBot',
|
|
21
|
-
credentials: {},
|
|
22
|
-
options: { logging: 'debug' },
|
|
23
|
-
devices: [],
|
|
24
|
-
} as any, api)
|
|
25
|
-
|
|
26
|
-
const accessory: any = { displayName: 'Test HAP Device' }
|
|
27
|
-
await (platform as any).configureAccessory(accessory)
|
|
28
|
-
|
|
29
|
-
// Allow async logger to flush
|
|
30
|
-
await new Promise(resolve => setTimeout(resolve, 0))
|
|
31
|
-
|
|
32
|
-
const calls = (log.info as any).mock.calls as Array<string[]>
|
|
33
|
-
const hasLine = calls.some(args => String(args[0]).includes('Loading accessory from cache: Test HAP Device'))
|
|
34
|
-
expect(hasLine).toBe(true)
|
|
35
|
-
})
|
|
36
|
-
})
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/first */
|
|
2
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
-
// Mock modules used by the HAP platform constructor to avoid requiring a real Homebridge API
|
|
4
|
-
vi.mock('fakegato-history', () => ({ default: () => ({}) }))
|
|
5
|
-
vi.mock('homebridge-lib/EveHomeKitTypes', () => ({ EveHomeKitTypes: class { constructor() {} } }))
|
|
6
|
-
|
|
7
|
-
import { SwitchBotHAPPlatform } from '../../platform-hap.js'
|
|
8
|
-
import { makeLogStub } from '../helpers/platform-fixtures.js'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* High-level smoke tests for the HAP platform to ensure it initializes,
|
|
12
|
-
* subscribes to lifecycle events, and handles cached accessories.
|
|
13
|
-
*/
|
|
14
|
-
describe('platform-hap (smoke)', () => {
|
|
15
|
-
it('initializes and subscribes to didFinishLaunching', async () => {
|
|
16
|
-
const api: any = { on: vi.fn() }
|
|
17
|
-
const log: any = makeLogStub()
|
|
18
|
-
|
|
19
|
-
// Enable debug so debug* logs print via our shared logger
|
|
20
|
-
// Construct the platform (smoke)
|
|
21
|
-
new SwitchBotHAPPlatform(log as any, {
|
|
22
|
-
name: 'SwitchBot',
|
|
23
|
-
credentials: {},
|
|
24
|
-
options: { logging: 'debug' },
|
|
25
|
-
devices: [],
|
|
26
|
-
} as any, api)
|
|
27
|
-
|
|
28
|
-
// Should register didFinishLaunching handler
|
|
29
|
-
expect(api.on).toHaveBeenCalled()
|
|
30
|
-
const calledWithDL = (api.on as any).mock.calls.some((args: any[]) => args[0] === 'didFinishLaunching' && typeof args[1] === 'function')
|
|
31
|
-
expect(calledWithDL).toBe(true)
|
|
32
|
-
|
|
33
|
-
// Should log effective platform logging at startup
|
|
34
|
-
const debugCalls = (log.debug as any).mock.calls as Array<string[]>
|
|
35
|
-
const hasStartupLine = debugCalls.some(args => String(args[0]).includes('[SwitchBot HAP] effective platformLogging='))
|
|
36
|
-
expect(hasStartupLine).toBe(true)
|
|
37
|
-
|
|
38
|
-
// Missing credentials results in a debug error log
|
|
39
|
-
// Allow async platform logger to flush
|
|
40
|
-
await new Promise(resolve => setTimeout(resolve, 0))
|
|
41
|
-
const errorCalls = (log.error as any).mock.calls as Array<string[]>
|
|
42
|
-
const hasMissingCreds = errorCalls.some(args => String(args[0]).includes('Missing SwitchBot API credentials'))
|
|
43
|
-
expect(hasMissingCreds).toBe(true)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('adds cached accessories via configureAccessory', async () => {
|
|
47
|
-
const api: any = { on: vi.fn() }
|
|
48
|
-
const log: any = makeLogStub()
|
|
49
|
-
|
|
50
|
-
const platform = new SwitchBotHAPPlatform(log as any, {
|
|
51
|
-
name: 'SwitchBot',
|
|
52
|
-
credentials: {},
|
|
53
|
-
options: { logging: 'debug' },
|
|
54
|
-
devices: [],
|
|
55
|
-
} as any, api)
|
|
56
|
-
|
|
57
|
-
const accessory: any = { displayName: 'Cached Device' }
|
|
58
|
-
await (platform as any).configureAccessory(accessory)
|
|
59
|
-
|
|
60
|
-
// Should be stored in platform.accessories
|
|
61
|
-
expect(Array.isArray((platform as any).accessories)).toBe(true)
|
|
62
|
-
expect((platform as any).accessories.length).toBe(1)
|
|
63
|
-
|
|
64
|
-
// And should log the cache load message including device name
|
|
65
|
-
await new Promise(resolve => setTimeout(resolve, 0))
|
|
66
|
-
const infoCalls = (log.info as any).mock.calls as Array<string[]>
|
|
67
|
-
const hasLine = infoCalls.some(args => String(args[0]).includes('Loading accessory from cache: Cached Device'))
|
|
68
|
-
expect(hasLine).toBe(true)
|
|
69
|
-
})
|
|
70
|
-
})
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { vi } from 'vitest'
|
|
2
|
-
|
|
3
|
-
// Shared test helpers for platform-matter tests
|
|
4
|
-
export function makeApiStub(matterProps: Record<string, any> = {}) {
|
|
5
|
-
const handlers: Record<string, (...args: any[]) => any> = {}
|
|
6
|
-
|
|
7
|
-
const api: any = {
|
|
8
|
-
matter: {
|
|
9
|
-
uuid: { generate: (s: string) => `uuid-${s}` },
|
|
10
|
-
registerPlatformAccessories: matterProps.registerPlatformAccessories ?? vi.fn(),
|
|
11
|
-
unregisterPlatformAccessories: matterProps.unregisterPlatformAccessories ?? vi.fn(),
|
|
12
|
-
updateAccessoryState: matterProps.updateAccessoryState ?? vi.fn(),
|
|
13
|
-
clusterNames: matterProps.clusterNames ?? {},
|
|
14
|
-
deviceTypes: matterProps.deviceTypes ?? {},
|
|
15
|
-
},
|
|
16
|
-
isMatterAvailable: matterProps.isMatterAvailable ?? (() => true),
|
|
17
|
-
isMatterEnabled: matterProps.isMatterEnabled ?? (() => true),
|
|
18
|
-
on: (ev: string, fn: (...args: any[]) => any) => { handlers[ev] = fn },
|
|
19
|
-
_handlers: handlers,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return api
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function makeLogStub() {
|
|
26
|
-
return {
|
|
27
|
-
info: vi.fn(),
|
|
28
|
-
warn: vi.fn(),
|
|
29
|
-
debug: vi.fn(),
|
|
30
|
-
error: vi.fn(),
|
|
31
|
-
success: vi.fn(),
|
|
32
|
-
}
|
|
33
|
-
}
|