@homebridge-plugins/homebridge-tuya 3.0.0-beta.3 → 3.0.0-beta.30
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 +364 -142
- package/config.schema.json +1299 -894
- package/dist/cloud/api/TuyaOpenAPI.js +108 -60
- package/dist/cloud/api/TuyaOpenAPI.js.map +1 -1
- package/dist/cloud/api/TuyaOpenMQ.js +45 -22
- package/dist/cloud/api/TuyaOpenMQ.js.map +1 -1
- package/dist/cloud/device/{TuyaDeviceManager.js → TuyaCloudDeviceManager.js} +146 -96
- package/dist/cloud/device/TuyaCloudDeviceManager.js.map +1 -0
- package/dist/cloud/device/TuyaCustomDeviceManager.js +75 -5
- package/dist/cloud/device/TuyaCustomDeviceManager.js.map +1 -1
- package/dist/cloud/device/TuyaDevice.js.map +1 -1
- package/dist/cloud/device/TuyaHomeDeviceManager.js +81 -13
- package/dist/cloud/device/TuyaHomeDeviceManager.js.map +1 -1
- package/dist/config.js +26 -5
- package/dist/config.js.map +1 -1
- package/dist/local/DynamicChildDiscovery.js +2 -1
- package/dist/local/DynamicChildDiscovery.js.map +1 -1
- package/dist/local/LocalDevice.js +108 -11
- package/dist/local/LocalDevice.js.map +1 -1
- package/dist/local/LocalDeviceManager.js +362 -177
- package/dist/local/LocalDeviceManager.js.map +1 -1
- package/dist/local/TuyaDiscovery.js +17 -8
- package/dist/local/TuyaDiscovery.js.map +1 -1
- package/dist/local/ZigbeeGatewayDetection.js +7 -4
- package/dist/local/ZigbeeGatewayDetection.js.map +1 -1
- package/dist/local/protocol/ProtocolUtilities.js +61 -27
- package/dist/local/protocol/ProtocolUtilities.js.map +1 -1
- package/dist/local/protocol/ProtocolV31V32.js +61 -11
- package/dist/local/protocol/ProtocolV31V32.js.map +1 -1
- package/dist/local/protocol/ProtocolV33.js +4 -2
- package/dist/local/protocol/ProtocolV33.js.map +1 -1
- package/dist/local/protocol/ProtocolV34.js +10 -5
- package/dist/local/protocol/ProtocolV34.js.map +1 -1
- package/dist/local/protocol/ProtocolV35.js +17 -6
- package/dist/local/protocol/ProtocolV35.js.map +1 -1
- package/dist/platform.js +263 -497
- package/dist/platform.js.map +1 -1
- package/dist/settings.js +0 -2
- package/dist/settings.js.map +1 -1
- package/dist/shared/TuyaDeviceManager.js +147 -0
- package/dist/shared/TuyaDeviceManager.js.map +1 -0
- package/dist/shared/TuyaHybridDeviceManager.js +219 -0
- package/dist/shared/TuyaHybridDeviceManager.js.map +1 -0
- package/dist/shared/accessory/AccessoryFactory.js +359 -0
- package/dist/shared/accessory/AccessoryFactory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/AirConditionerAccessory.js +129 -23
- package/dist/shared/accessory/AirConditionerAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/AirPurifierAccessory.js.map +1 -1
- package/dist/shared/accessory/AirQualitySensorAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/BaseAccessory.js +47 -97
- package/dist/shared/accessory/BaseAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/BlindsAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/CameraAccessory.js +9 -3
- package/dist/shared/accessory/CameraAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/CarbonDioxideSensorAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/CarbonMonoxideSensorAccessory.js.map +1 -1
- package/dist/shared/accessory/CatToiletAccessory.js +130 -0
- package/dist/shared/accessory/CatToiletAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/ContactSensorAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/DehumidifierAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/DiffuserAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/DimmerAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/DoorbellAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/ExtractionHoodAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/FanAccessory.js +16 -4
- package/dist/shared/accessory/FanAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/GarageDoorAccessory.js +19 -2
- package/dist/shared/accessory/GarageDoorAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/HeaterAccessory.js +3 -0
- package/dist/shared/accessory/HeaterAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/HeaterAccessory_old.js.map +1 -1
- package/dist/shared/accessory/HumanPresenceSensorAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/HumidifierAccessory.js.map +1 -1
- package/dist/shared/accessory/IRAdapter.js +169 -0
- package/dist/shared/accessory/IRAdapter.js.map +1 -0
- package/dist/shared/{accessories → accessory}/IRAirConditionerAccessory.js +2 -2
- package/dist/shared/accessory/IRAirConditionerAccessory.js.map +1 -0
- package/dist/shared/accessory/IRControlHubAccessory.js.map +1 -0
- package/dist/shared/accessory/IRControlHubSubAccessory.js.map +1 -0
- package/dist/shared/accessory/IRFanAccessory.js +109 -0
- package/dist/shared/accessory/IRFanAccessory.js.map +1 -0
- package/dist/shared/accessory/IRGenericAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/LeakSensorAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/LightAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/LightSensorAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/LocationWeatherAccessory.js +9 -36
- package/dist/shared/accessory/LocationWeatherAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/LockAccessory.js +3 -3
- package/dist/shared/{accessories → accessory}/LockAccessory.js.map +1 -1
- package/dist/shared/accessory/MotionSensorAccessory.js.map +1 -0
- package/dist/shared/accessory/OutletAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/PetFeederAccessory.js.map +1 -1
- package/dist/shared/accessory/SaunaAccessory.js +134 -0
- package/dist/shared/accessory/SaunaAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/SceneAccessory.js +1 -1
- package/dist/shared/accessory/SceneAccessory.js.map +1 -0
- package/dist/shared/accessory/SceneSwitchAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/SecuritySystemAccessory.js +4 -4
- package/dist/shared/accessory/SecuritySystemAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/SmokeSensorAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/SwitchAccessory.js +1 -45
- package/dist/shared/accessory/SwitchAccessory.js.map +1 -0
- package/dist/shared/accessory/TemperatureHumiditySensorAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/ThermostatAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/TowerRackAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/ValveAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/VibrationSensorAccessory.js.map +1 -1
- package/dist/shared/accessory/WeatherStationAccessory.js.map +1 -0
- package/dist/shared/accessory/WetBulbGlobeTemperatureAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/WhiteNoiseLightAccessory.js +1 -0
- package/dist/shared/accessory/WhiteNoiseLightAccessory.js.map +1 -0
- package/dist/shared/accessory/WindowAccessory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/WindowCoveringAccessory.js.map +1 -1
- package/dist/shared/{accessories → accessory}/WirelessSwitchAccessory.js.map +1 -1
- package/dist/shared/accessory/characteristic/Active.js.map +1 -0
- package/dist/shared/accessory/characteristic/AirQuality.js.map +1 -0
- package/dist/shared/{accessories → accessory}/characteristic/CurrentRelativeHumidity.js +3 -0
- package/dist/shared/accessory/characteristic/CurrentRelativeHumidity.js.map +1 -0
- package/dist/shared/accessory/characteristic/CurrentTemperature.js.map +1 -0
- package/dist/shared/accessory/characteristic/CurrentWeather.js.map +1 -0
- package/dist/shared/accessory/characteristic/CurrentWeatherByOpenMeteo.js.map +1 -0
- package/dist/shared/{accessories → accessory}/characteristic/CurrentWetBulbGlobeTemperature.js +3 -2
- package/dist/shared/accessory/characteristic/CurrentWetBulbGlobeTemperature.js.map +1 -0
- package/dist/shared/{accessories → accessory}/characteristic/EnergyUsage.js +0 -5
- package/dist/shared/accessory/characteristic/EnergyUsage.js.map +1 -0
- package/dist/shared/accessory/characteristic/EnumOn.js +48 -0
- package/dist/shared/accessory/characteristic/EnumOn.js.map +1 -0
- package/dist/shared/accessory/characteristic/ExtraCharacteristicAdapter.js +197 -0
- package/dist/shared/accessory/characteristic/ExtraCharacteristicAdapter.js.map +1 -0
- package/dist/shared/{accessories → accessory}/characteristic/Light.js +62 -12
- package/dist/shared/accessory/characteristic/Light.js.map +1 -0
- package/dist/shared/accessory/characteristic/LightSensor.js.map +1 -0
- package/dist/shared/{accessories → accessory}/characteristic/LockPhysicalControls.js +3 -0
- package/dist/shared/accessory/characteristic/LockPhysicalControls.js.map +1 -0
- package/dist/shared/accessory/characteristic/MotionDetected.js.map +1 -0
- package/dist/shared/accessory/characteristic/Name.js.map +1 -0
- package/dist/shared/accessory/characteristic/OccupancyDetected.js.map +1 -0
- package/dist/shared/{accessories → accessory}/characteristic/On.js +3 -2
- package/dist/shared/accessory/characteristic/On.js.map +1 -0
- package/dist/shared/accessory/characteristic/OutletInUse.js.map +1 -0
- package/dist/shared/accessory/characteristic/ProgrammableSwitchEvent.js.map +1 -0
- package/dist/shared/accessory/characteristic/RawOn.js +93 -0
- package/dist/shared/accessory/characteristic/RawOn.js.map +1 -0
- package/dist/shared/{accessories → accessory}/characteristic/RelativeHumidityDehumidifierThreshold.js +3 -0
- package/dist/shared/accessory/characteristic/RelativeHumidityDehumidifierThreshold.js.map +1 -0
- package/dist/shared/accessory/characteristic/RotationSpeed.js +157 -0
- package/dist/shared/accessory/characteristic/RotationSpeed.js.map +1 -0
- package/dist/shared/accessory/characteristic/SecuritySystemState.js.map +1 -0
- package/dist/shared/{accessories → accessory}/characteristic/SwingMode.js +3 -0
- package/dist/shared/accessory/characteristic/SwingMode.js.map +1 -0
- package/dist/shared/accessory/characteristic/TargetTemperature.js.map +1 -0
- package/dist/shared/{accessories → accessory}/characteristic/TemperatureDisplayUnits.js +9 -2
- package/dist/shared/accessory/characteristic/TemperatureDisplayUnits.js.map +1 -0
- package/dist/shared/util/ConfigHash.js +2 -2
- package/dist/shared/util/ConfigHash.js.map +1 -1
- package/dist/shared/util/ConfigMigrator.js +222 -0
- package/dist/shared/util/ConfigMigrator.js.map +1 -0
- package/dist/shared/util/FfmpegStreamingProcess.js +62 -0
- package/dist/shared/util/FfmpegStreamingProcess.js.map +1 -1
- package/dist/shared/util/InfraredTool.js +0 -2
- package/dist/shared/util/InfraredTool.js.map +1 -1
- package/dist/shared/util/Logger.js +85 -10
- package/dist/shared/util/Logger.js.map +1 -1
- package/dist/shared/util/TuyaStreamDelegate.js +201 -99
- package/dist/shared/util/TuyaStreamDelegate.js.map +1 -1
- package/dist/shared/util/color.js +15 -4
- package/dist/shared/util/color.js.map +1 -1
- package/dist/shared/util/util.js +91 -5
- package/dist/shared/util/util.js.map +1 -1
- package/docs/ADVANCED_OPTIONS.md +623 -0
- package/docs/CONFIG_GUIDE.md +616 -0
- package/docs/Get-Local-Keys-for-Your-Devices.md +246 -0
- package/{SUPPORTED_DEVICES.md → docs/SUPPORTED_DEVICES.md} +27 -5
- package/eslint.config.mjs +0 -1
- package/{jest.config.js → jest.config.ts} +5 -2
- package/package.json +14 -11
- package/test/ConfigMigrator.test.ts +1060 -0
- package/test/FanAccessory.test.ts +458 -0
- package/test/Light.test.ts +424 -0
- package/test/Logger.test.ts +482 -0
- package/test/ProtocolV31V32.test.ts +42 -0
- package/test/accessoryFactory.data.test.ts +176 -0
- package/test/accessoryFactory.test.ts +65 -35
- package/test/airConditioner.swing.test.ts +226 -0
- package/test/airConditioner.test.ts +770 -0
- package/test/color.test.ts +52 -0
- package/test/config.test.ts +17 -13
- package/test/custom.test.ts +2 -2
- package/test/errorHandling.test.ts +12 -12
- package/test/fanAccessory.test.ts +458 -0
- package/test/home.test.ts +1 -1
- package/test/hybridDeviceManager.test.ts +808 -0
- package/test/infraredTools.test.ts +67 -0
- package/test/light.test.ts +424 -0
- package/test/localDevice.test.ts +31 -53
- package/test/localDeviceManager.behavior.test.ts +211 -37
- package/test/localDeviceManager.test.ts +124 -41
- package/test/mqttMessages.test.ts +40 -16
- package/test/platform.test.ts +380 -814
- package/test/platform.validation.local.test.ts +90 -120
- package/test/protocol.test.ts +27 -12
- package/test/protocol35Frames.test.ts +204 -0
- package/test/rotationSpeed.test.ts +150 -0
- package/test/tuyaCustomDeviceManager.test.ts +111 -17
- package/test/tuyaDeviceManager.test.ts +655 -645
- package/test/tuyaDiscovery.test.ts +21 -33
- package/test/tuyaHomeDeviceManager.test.ts +114 -19
- package/test/tuyaOpenAPI.test.ts +25 -44
- package/test/tuyaOpenMQ.test.ts +15 -23
- package/test/util.test.ts +107 -7
- package/test/zigbee/LocalDevice.zigbee.test.ts +14 -18
- package/test/zigbee/LocalDeviceManager.cloud-discovery.test.ts +19 -20
- package/test/zigbee/LocalDeviceManager.zigbee.reconnect.test.ts +19 -20
- package/test/zigbee/LocalDeviceManager.zigbee.test.ts +73 -35
- package/test/zigbee/ZigbeeGatewayDetection.test.ts +2 -2
- package/ADVANCED_OPTIONS.md +0 -267
- package/dist/cloud/device/TuyaDeviceManager.js.map +0 -1
- package/dist/local/CloudLocalReconciliation.js +0 -180
- package/dist/local/CloudLocalReconciliation.js.map +0 -1
- package/dist/shared/accessories/AccessoryFactory.js +0 -309
- package/dist/shared/accessories/AccessoryFactory.js.map +0 -1
- package/dist/shared/accessories/AirConditionerAccessory.js.map +0 -1
- package/dist/shared/accessories/AirQualitySensorAccessory.js.map +0 -1
- package/dist/shared/accessories/BaseAccessory.js.map +0 -1
- package/dist/shared/accessories/CameraAccessory.js.map +0 -1
- package/dist/shared/accessories/FanAccessory.js.map +0 -1
- package/dist/shared/accessories/GarageDoorAccessory.js.map +0 -1
- package/dist/shared/accessories/HeaterAccessory.js.map +0 -1
- package/dist/shared/accessories/HumanPresenceSensorAccessory.js.map +0 -1
- package/dist/shared/accessories/IRAirConditionerAccessory.js.map +0 -1
- package/dist/shared/accessories/IRControlHubAccessory.js.map +0 -1
- package/dist/shared/accessories/IRControlHubSubAccessory.js.map +0 -1
- package/dist/shared/accessories/IRGenericAccessory.js.map +0 -1
- package/dist/shared/accessories/LocationWeatherAccessory.js.map +0 -1
- package/dist/shared/accessories/MotionSensorAccessory.js.map +0 -1
- package/dist/shared/accessories/OutletAccessory.js.map +0 -1
- package/dist/shared/accessories/SceneAccessory.js.map +0 -1
- package/dist/shared/accessories/SceneSwitchAccessory.js.map +0 -1
- package/dist/shared/accessories/SecuritySystemAccessory.js.map +0 -1
- package/dist/shared/accessories/SwitchAccessory.js.map +0 -1
- package/dist/shared/accessories/TemperatureHumiditySensorAccessory.js.map +0 -1
- package/dist/shared/accessories/WeatherStationAccessory.js.map +0 -1
- package/dist/shared/accessories/WetBulbGlobeTemperatureAccessory.js.map +0 -1
- package/dist/shared/accessories/WhiteNoiseLightAccessory.js.map +0 -1
- package/dist/shared/accessories/WindowAccessory.js.map +0 -1
- package/dist/shared/accessories/characteristic/Active.js.map +0 -1
- package/dist/shared/accessories/characteristic/AirQuality.js.map +0 -1
- package/dist/shared/accessories/characteristic/CurrentRelativeHumidity.js.map +0 -1
- package/dist/shared/accessories/characteristic/CurrentTemperature.js.map +0 -1
- package/dist/shared/accessories/characteristic/CurrentWeather.js.map +0 -1
- package/dist/shared/accessories/characteristic/CurrentWeatherByOpenMeteo.js.map +0 -1
- package/dist/shared/accessories/characteristic/CurrentWetBulbGlobeTemperature.js.map +0 -1
- package/dist/shared/accessories/characteristic/EnergyUsage.js.map +0 -1
- package/dist/shared/accessories/characteristic/Light.js.map +0 -1
- package/dist/shared/accessories/characteristic/LightSensor.js.map +0 -1
- package/dist/shared/accessories/characteristic/LockPhysicalControls.js.map +0 -1
- package/dist/shared/accessories/characteristic/MotionDetected.js.map +0 -1
- package/dist/shared/accessories/characteristic/Name.js.map +0 -1
- package/dist/shared/accessories/characteristic/OccupancyDetected.js.map +0 -1
- package/dist/shared/accessories/characteristic/On.js.map +0 -1
- package/dist/shared/accessories/characteristic/OutletInUse.js.map +0 -1
- package/dist/shared/accessories/characteristic/ProgrammableSwitchEvent.js.map +0 -1
- package/dist/shared/accessories/characteristic/RelativeHumidityDehumidifierThreshold.js.map +0 -1
- package/dist/shared/accessories/characteristic/RotationSpeed.js +0 -78
- package/dist/shared/accessories/characteristic/RotationSpeed.js.map +0 -1
- package/dist/shared/accessories/characteristic/SecuritySystemState.js.map +0 -1
- package/dist/shared/accessories/characteristic/SwingMode.js.map +0 -1
- package/dist/shared/accessories/characteristic/TargetTemperature.js.map +0 -1
- package/dist/shared/accessories/characteristic/TemperatureDisplayUnits.js.map +0 -1
- package/test/zigbee/CloudLocalReconciliation.test.ts +0 -284
- package/tuya-local-configs/dev-1.hash +0 -1
- package/tuya-local-configs/device1.hash +0 -1
- package/wiki/Get-Local-Keys-for-Your-Devices.md +0 -85
- /package/dist/shared/{accessories → accessory}/AirPurifierAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/AirQualitySensorAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/BlindsAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/CarbonDioxideSensorAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/CarbonMonoxideSensorAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/ContactSensorAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/DehumidifierAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/DiffuserAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/DimmerAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/DoorbellAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/ExtractionHoodAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/HeaterAccessory_old.js +0 -0
- /package/dist/shared/{accessories → accessory}/HumanPresenceSensorAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/HumidifierAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/IRControlHubAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/IRControlHubSubAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/IRGenericAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/LeakSensorAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/LightAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/LightSensorAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/MotionSensorAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/OutletAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/PetFeederAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/SceneSwitchAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/SmokeSensorAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/TemperatureHumiditySensorAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/ThermostatAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/TowerRackAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/ValveAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/VibrationSensorAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/WeatherStationAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/WetBulbGlobeTemperatureAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/WindowAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/WindowCoveringAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/WirelessSwitchAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/Active.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/AirQuality.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/CurrentTemperature.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/CurrentWeather.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/CurrentWeatherByOpenMeteo.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/LightSensor.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/MotionDetected.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/Name.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/OccupancyDetected.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/OutletInUse.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/ProgrammableSwitchEvent.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/SecuritySystemState.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/TargetTemperature.js +0 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, jest, test } from '@jest/globals';
|
|
2
|
+
import Logger, { initLogger } from '../src/shared/util/Logger';
|
|
3
|
+
import { configureLight } from '../src/shared/accessory/characteristic/Light';
|
|
4
|
+
import { TuyaDeviceSchemaType } from '../src/cloud/device/TuyaDevice';
|
|
5
|
+
|
|
6
|
+
// Mock Logger
|
|
7
|
+
const mockLogger: Logger = {
|
|
8
|
+
debug: jest.fn(),
|
|
9
|
+
info: jest.fn(),
|
|
10
|
+
warn: jest.fn(),
|
|
11
|
+
error: jest.fn(),
|
|
12
|
+
log: jest.fn(),
|
|
13
|
+
} as unknown as Logger;
|
|
14
|
+
|
|
15
|
+
describe('Light Characteristic', () => {
|
|
16
|
+
let accessoryMock = {
|
|
17
|
+
getService: jest.fn(),
|
|
18
|
+
addService: jest.fn(),
|
|
19
|
+
removeService: jest.fn(),
|
|
20
|
+
getStatus: jest.fn(),
|
|
21
|
+
log: mockLogger,
|
|
22
|
+
deviceManager: {
|
|
23
|
+
getDevice: jest.fn(),
|
|
24
|
+
enableAdaptiveLighting: jest.fn(),
|
|
25
|
+
},
|
|
26
|
+
Characteristic: {
|
|
27
|
+
On: jest.fn(),
|
|
28
|
+
Brightness: jest.fn(),
|
|
29
|
+
ColorTemperature: jest.fn(),
|
|
30
|
+
Hue: jest.fn(),
|
|
31
|
+
Saturation: jest.fn(),
|
|
32
|
+
},
|
|
33
|
+
Service: {
|
|
34
|
+
Lightbulb: jest.fn(),
|
|
35
|
+
Switch: jest.fn(),
|
|
36
|
+
},
|
|
37
|
+
} as unknown as any;
|
|
38
|
+
let serviceMock = {
|
|
39
|
+
getCharacteristic: jest.fn().mockReturnValue({
|
|
40
|
+
onGet: jest.fn().mockReturnThis(),
|
|
41
|
+
onSet: jest.fn().mockReturnThis(),
|
|
42
|
+
setProps: jest.fn(),
|
|
43
|
+
updateValue: jest.fn(),
|
|
44
|
+
}),
|
|
45
|
+
} as unknown as any;
|
|
46
|
+
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
jest.resetModules();
|
|
49
|
+
initLogger(mockLogger);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('ensureHSVProperty', () => {
|
|
53
|
+
let spyLogDebug = jest.spyOn(mockLogger, 'debug').mockImplementation(() => {});
|
|
54
|
+
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
jest.resetModules();
|
|
57
|
+
spyLogDebug.mockClear();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('color schema with defined property', () => {
|
|
61
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
62
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
63
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
64
|
+
const colorSchema = {
|
|
65
|
+
code: 'color',
|
|
66
|
+
type: TuyaDeviceSchemaType.Json,
|
|
67
|
+
property: {
|
|
68
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
69
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
70
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
71
|
+
},
|
|
72
|
+
} as any;
|
|
73
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
74
|
+
|
|
75
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
76
|
+
expect(spyLogDebug).toHaveBeenCalledWith('hsvProperty: %O', colorSchema.property);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('color schema without defined property but mode includes colour', () => {
|
|
80
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
81
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
82
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
83
|
+
const colorSchema = { code: 'color', type: TuyaDeviceSchemaType.Json } as any; // No property
|
|
84
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
85
|
+
|
|
86
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
87
|
+
expect(spyLogDebug).toHaveBeenCalledWith('hsvProperty: %O', {
|
|
88
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
89
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
90
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
91
|
+
});
|
|
92
|
+
expect(colorSchema.property).toEqual({
|
|
93
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
94
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
95
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('color schema without defined property and mode does not include colour', () => {
|
|
100
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
101
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
102
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
103
|
+
const colorSchema = { code: 'color', type: TuyaDeviceSchemaType.Json } as any; // No property
|
|
104
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['white'] } } as any;
|
|
105
|
+
|
|
106
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
107
|
+
expect(spyLogDebug).toHaveBeenCalledWith('hsvProperty: %O', {});
|
|
108
|
+
expect(colorSchema.property).toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('color schema with non JSON type but with defined property includes colour', () => {
|
|
112
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
113
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
114
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
115
|
+
const colorSchema = {
|
|
116
|
+
code: 'color',
|
|
117
|
+
type: 'unsupported',
|
|
118
|
+
property: {
|
|
119
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
120
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
121
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
122
|
+
},
|
|
123
|
+
} as any;
|
|
124
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
125
|
+
|
|
126
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
127
|
+
expect(spyLogDebug).toHaveBeenCalledWith('hsvProperty: %O', colorSchema.property);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('getLightType', () => {
|
|
132
|
+
let spyLogInfo = jest.spyOn(mockLogger, 'info').mockImplementation(() => {});
|
|
133
|
+
|
|
134
|
+
beforeEach(() => {
|
|
135
|
+
jest.resetModules();
|
|
136
|
+
spyLogInfo.mockClear();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('Unknown light type when no schemas are provided', () => {
|
|
140
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
141
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
142
|
+
configureLight(accessoryMock, serviceMock, onSchema, undefined, tempSchema);
|
|
143
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'Unknown');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('Normal light type when only on schema is provided', () => {
|
|
147
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
148
|
+
|
|
149
|
+
configureLight(accessoryMock, serviceMock, onSchema);
|
|
150
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'Normal');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('CW light type when on and temp schemas are provided', () => {
|
|
154
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
155
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
156
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
157
|
+
|
|
158
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema);
|
|
159
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'CW');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('RGB light type when on and color schemas are provided', () => {
|
|
163
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
164
|
+
const colorSchema = {
|
|
165
|
+
code: 'color',
|
|
166
|
+
type: TuyaDeviceSchemaType.Json,
|
|
167
|
+
property: {
|
|
168
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
169
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
170
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
171
|
+
},
|
|
172
|
+
} as any;
|
|
173
|
+
|
|
174
|
+
configureLight(accessoryMock, serviceMock, onSchema, undefined, undefined, colorSchema);
|
|
175
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'RGB');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('RGBC light type when on, color, and mode schemas are provided with mode including colour', () => {
|
|
179
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
180
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
181
|
+
const colorSchema = {
|
|
182
|
+
code: 'color',
|
|
183
|
+
type: TuyaDeviceSchemaType.Json,
|
|
184
|
+
property: {
|
|
185
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
186
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
187
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
188
|
+
},
|
|
189
|
+
} as any;
|
|
190
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
191
|
+
|
|
192
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, undefined, colorSchema, modeSchema);
|
|
193
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'RGBC');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('RGBCW light type', () => {
|
|
197
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
198
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
199
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
200
|
+
const colorSchema = { code: 'color', type: TuyaDeviceSchemaType.Json, property: { h: {}, s: {}, v: {} } } as any;
|
|
201
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
202
|
+
|
|
203
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
204
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'RGBCW');
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('RGBCW light type with JSON color schema without property but mode includes colour', () => {
|
|
208
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
209
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
210
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
211
|
+
const colorSchema = { code: 'color', type: TuyaDeviceSchemaType.Json } as any; // No property
|
|
212
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
213
|
+
|
|
214
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
215
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'RGBCW');
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('RGBCW light type with JSON color schema without property and mode does not include colour', () => {
|
|
219
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
220
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
221
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
222
|
+
const colorSchema = { code: 'color', type: TuyaDeviceSchemaType.Json } as any; // No property
|
|
223
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['white'] } } as any;
|
|
224
|
+
|
|
225
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
226
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'CW');
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('RGBCW light type with non JSON color schema', () => {
|
|
230
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
231
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
232
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
233
|
+
const colorSchema = { code: 'color', type: 'unsupported' } as any; // Unsupported type
|
|
234
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
235
|
+
|
|
236
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
237
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'CW');
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test('RGBCW light type with non JSON with property color schema', () => {
|
|
241
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
242
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
243
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
244
|
+
const colorSchema = { code: 'color', type: 'unsupported', property: { h: {}, s: {}, v: {} } } as any; // Unsupported type but has property
|
|
245
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
246
|
+
|
|
247
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
248
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'RGBCW');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
describe('configureLight - ON handler bundles brightness', () => {
|
|
254
|
+
let mockAccessory: any;
|
|
255
|
+
let mockService: any;
|
|
256
|
+
let handlers: Record<string, { onGet?: Function; onSet?: Function }>;
|
|
257
|
+
|
|
258
|
+
beforeEach(() => {
|
|
259
|
+
handlers = {};
|
|
260
|
+
|
|
261
|
+
const makeCharChain = (name: string) => ({
|
|
262
|
+
onGet: jest.fn(function (this: any, handler: Function) {
|
|
263
|
+
handlers[name] = handlers[name] || {};
|
|
264
|
+
handlers[name].onGet = handler;
|
|
265
|
+
return this;
|
|
266
|
+
}),
|
|
267
|
+
onSet: jest.fn(function (this: any, handler: Function) {
|
|
268
|
+
handlers[name] = handlers[name] || {};
|
|
269
|
+
handlers[name].onSet = handler;
|
|
270
|
+
return this;
|
|
271
|
+
}),
|
|
272
|
+
setProps: jest.fn().mockReturnThis(),
|
|
273
|
+
updateValue: jest.fn().mockReturnThis(),
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const onChar = makeCharChain('On');
|
|
277
|
+
const brightChar = makeCharChain('Brightness');
|
|
278
|
+
|
|
279
|
+
mockService = {
|
|
280
|
+
getCharacteristic: jest.fn((charType: any) => {
|
|
281
|
+
if (charType === 'MockOn') return onChar;
|
|
282
|
+
if (charType === 'MockBrightness') return brightChar;
|
|
283
|
+
return makeCharChain('other');
|
|
284
|
+
}),
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
mockAccessory = {
|
|
288
|
+
Characteristic: { On: 'MockOn', Brightness: 'MockBrightness' },
|
|
289
|
+
Service: { Lightbulb: 'MockLightbulb' },
|
|
290
|
+
accessory: {
|
|
291
|
+
displayName: 'Test Light',
|
|
292
|
+
getService: jest.fn(() => null),
|
|
293
|
+
addService: jest.fn(() => mockService),
|
|
294
|
+
},
|
|
295
|
+
log: { info: jest.fn(), debug: jest.fn(), warn: jest.fn() },
|
|
296
|
+
platform: { getDeviceConfig: jest.fn(() => undefined) },
|
|
297
|
+
deviceManager: { enableAdaptiveLighting: jest.fn(() => false)},
|
|
298
|
+
checkOnlineStatus: jest.fn(),
|
|
299
|
+
getStatus: jest.fn((code: string) => {
|
|
300
|
+
if (code === 'light') return { code: 'light', value: true };
|
|
301
|
+
if (code === 'bright_value') return { code: 'bright_value', value: 420 };
|
|
302
|
+
if (code === 'switch_led') return { code: 'switch_led', value: false };
|
|
303
|
+
if (code === 'bright_value_1') return { code: 'bright_value_1', value: 100 };
|
|
304
|
+
return undefined;
|
|
305
|
+
}),
|
|
306
|
+
sendCommands: jest.fn(),
|
|
307
|
+
};
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
function makeSchema(code: string, type = 'Boolean', property: any = {}) {
|
|
311
|
+
return { code, mode: 'rw', type, property };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function brightSchema(code = 'bright_value') {
|
|
315
|
+
return makeSchema(code, 'Integer', { min: 10, max: 1000, scale: 0, step: 1 });
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
test('LightType.C: ON sends both on + cached brightness', async () => {
|
|
319
|
+
configureLight(
|
|
320
|
+
mockAccessory,
|
|
321
|
+
mockService,
|
|
322
|
+
makeSchema('light') as any,
|
|
323
|
+
brightSchema() as any,
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
expect(handlers['On']?.onSet).toBeDefined();
|
|
327
|
+
await handlers['On'].onSet!(true);
|
|
328
|
+
|
|
329
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
330
|
+
[
|
|
331
|
+
{ code: 'light', value: true },
|
|
332
|
+
{ code: 'bright_value', value: 420 },
|
|
333
|
+
],
|
|
334
|
+
true,
|
|
335
|
+
);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test('LightType.C: OFF sends only the on command (no brightness)', async () => {
|
|
339
|
+
configureLight(
|
|
340
|
+
mockAccessory,
|
|
341
|
+
mockService,
|
|
342
|
+
makeSchema('light') as any,
|
|
343
|
+
brightSchema() as any,
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
await handlers['On'].onSet!(false);
|
|
347
|
+
|
|
348
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
349
|
+
[{ code: 'light', value: false }],
|
|
350
|
+
true,
|
|
351
|
+
);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test('dual-light warm channel: ON bundles warm brightness', async () => {
|
|
355
|
+
configureLight(
|
|
356
|
+
mockAccessory,
|
|
357
|
+
mockService,
|
|
358
|
+
makeSchema('light') as any,
|
|
359
|
+
brightSchema('bright_value') as any,
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
await handlers['On'].onSet!(true);
|
|
363
|
+
|
|
364
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
365
|
+
[
|
|
366
|
+
{ code: 'light', value: true },
|
|
367
|
+
{ code: 'bright_value', value: 420 },
|
|
368
|
+
],
|
|
369
|
+
true,
|
|
370
|
+
);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
test('dual-light white channel: ON bundles white brightness', async () => {
|
|
374
|
+
configureLight(
|
|
375
|
+
mockAccessory,
|
|
376
|
+
mockService,
|
|
377
|
+
makeSchema('switch_led') as any,
|
|
378
|
+
brightSchema('bright_value_1') as any,
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
await handlers['On'].onSet!(true);
|
|
382
|
+
|
|
383
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
384
|
+
[
|
|
385
|
+
{ code: 'switch_led', value: true },
|
|
386
|
+
{ code: 'bright_value_1', value: 100 },
|
|
387
|
+
],
|
|
388
|
+
true,
|
|
389
|
+
);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test('brightness-only set does not include on command', async () => {
|
|
393
|
+
configureLight(
|
|
394
|
+
mockAccessory,
|
|
395
|
+
mockService,
|
|
396
|
+
makeSchema('light') as any,
|
|
397
|
+
brightSchema() as any,
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
await handlers['Brightness'].onSet!(42);
|
|
401
|
+
|
|
402
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
403
|
+
[{ code: 'bright_value', value: 420 }],
|
|
404
|
+
true,
|
|
405
|
+
);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test('ON without brightness schema does not crash', async () => {
|
|
409
|
+
configureLight(
|
|
410
|
+
mockAccessory,
|
|
411
|
+
mockService,
|
|
412
|
+
makeSchema('light') as any,
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
expect(handlers['On']?.onSet).toBeDefined();
|
|
416
|
+
await handlers['On'].onSet!(true);
|
|
417
|
+
|
|
418
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
419
|
+
[{ code: 'light', value: true }],
|
|
420
|
+
true,
|
|
421
|
+
);
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
});
|