@homebridge-plugins/homebridge-tuya 3.0.0-beta.2 → 3.0.0-beta.21
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 +354 -142
- package/config.schema.json +1221 -893
- 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 +16 -3
- package/dist/local/LocalDevice.js.map +1 -1
- package/dist/local/LocalDeviceManager.js +361 -164
- package/dist/local/LocalDeviceManager.js.map +1 -1
- package/dist/local/TuyaDiscovery.js +16 -7
- 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 +34 -17
- package/dist/local/protocol/ProtocolUtilities.js.map +1 -1
- package/dist/local/protocol/ProtocolV31V32.js +4 -2
- 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 +8 -4
- package/dist/local/protocol/ProtocolV35.js.map +1 -1
- package/dist/platform.js +253 -493
- 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 +215 -0
- package/dist/shared/TuyaHybridDeviceManager.js.map +1 -0
- package/dist/shared/accessory/AccessoryFactory.js +350 -0
- package/dist/shared/accessory/AccessoryFactory.js.map +1 -0
- package/dist/shared/{accessories → accessory}/AirConditionerAccessory.js +21 -15
- 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 +16 -95
- 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 +2 -2
- 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/{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.map +1 -1
- 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.map +1 -1
- 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 +167 -0
- package/dist/shared/accessory/IRAdapter.js.map +1 -0
- 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 +90 -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 +1 -1
- 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/{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/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/{accessories → accessory}/characteristic/Light.js +28 -5
- 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 +1 -0
- 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/{accessories → accessory}/characteristic/RelativeHumidityDehumidifierThreshold.js +3 -0
- package/dist/shared/accessory/characteristic/RelativeHumidityDehumidifierThreshold.js.map +1 -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/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 +194 -97
- package/dist/shared/util/TuyaStreamDelegate.js.map +1 -1
- package/dist/shared/util/util.js +59 -4
- package/dist/shared/util/util.js.map +1 -1
- package/docs/ADVANCED_OPTIONS.md +603 -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} +24 -3
- package/eslint.config.mjs +0 -1
- package/{jest.config.js → jest.config.ts} +5 -2
- package/package.json +12 -9
- package/test/ConfigMigrator.test.ts +1060 -0
- package/test/Logger.test.ts +482 -0
- package/test/accessoryFactory.data.test.ts +172 -0
- package/test/accessoryFactory.test.ts +64 -35
- package/test/airConditioner.test.ts +742 -0
- package/test/config.test.ts +17 -13
- package/test/custom.test.ts +2 -2
- package/test/errorHandling.test.ts +12 -12
- package/test/home.test.ts +1 -1
- package/test/hybridDeviceManager.test.ts +808 -0
- package/test/light.test.ts +250 -0
- package/test/localDevice.test.ts +21 -50
- package/test/localDeviceManager.behavior.test.ts +196 -31
- package/test/localDeviceManager.test.ts +124 -41
- package/test/mqttMessages.test.ts +33 -14
- package/test/platform.test.ts +337 -814
- package/test/platform.validation.local.test.ts +58 -119
- package/test/tuyaCustomDeviceManager.test.ts +106 -16
- package/test/tuyaDeviceManager.test.ts +636 -639
- package/test/tuyaDiscovery.test.ts +21 -33
- package/test/tuyaHomeDeviceManager.test.ts +109 -18
- 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/AccessoryFactory.js +0 -276
- package/dist/shared/AccessoryFactory.js.map +0 -1
- package/dist/shared/accessories/AccessoryFactory.js +0 -305
- 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/GarageDoorAccessory.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.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}/FanAccessory.js +0 -0
- /package/dist/shared/{accessories → accessory}/HeaterAccessory.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}/IRAirConditionerAccessory.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}/SecuritySystemAccessory.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/RotationSpeed.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/SecuritySystemState.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/TargetTemperature.js +0 -0
- /package/dist/shared/{accessories → accessory}/characteristic/TemperatureDisplayUnits.js +0 -0
|
@@ -0,0 +1,250 @@
|
|
|
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
|
+
log: mockLogger,
|
|
21
|
+
deviceManager: {
|
|
22
|
+
getDevice: jest.fn(),
|
|
23
|
+
enableAdaptiveLighting: jest.fn(),
|
|
24
|
+
},
|
|
25
|
+
Characteristic: {
|
|
26
|
+
On: jest.fn(),
|
|
27
|
+
Brightness: jest.fn(),
|
|
28
|
+
ColorTemperature: jest.fn(),
|
|
29
|
+
Hue: jest.fn(),
|
|
30
|
+
Saturation: jest.fn(),
|
|
31
|
+
},
|
|
32
|
+
Service: {
|
|
33
|
+
Lightbulb: jest.fn(),
|
|
34
|
+
Switch: jest.fn(),
|
|
35
|
+
},
|
|
36
|
+
} as unknown as any;
|
|
37
|
+
let serviceMock = {
|
|
38
|
+
getCharacteristic: jest.fn().mockReturnValue({
|
|
39
|
+
onGet: jest.fn().mockReturnThis(),
|
|
40
|
+
onSet: jest.fn().mockReturnThis(),
|
|
41
|
+
setProps: jest.fn(),
|
|
42
|
+
}),
|
|
43
|
+
} as unknown as any;
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
jest.resetModules();
|
|
47
|
+
initLogger(mockLogger);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('ensureHSVProperty', () => {
|
|
51
|
+
let spyLogDebug = jest.spyOn(mockLogger, 'debug').mockImplementation(() => {});
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
jest.resetModules();
|
|
55
|
+
spyLogDebug.mockClear();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('color schema with defined property', () => {
|
|
59
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
60
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
61
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
62
|
+
const colorSchema = {
|
|
63
|
+
code: 'color',
|
|
64
|
+
type: TuyaDeviceSchemaType.Json,
|
|
65
|
+
property: {
|
|
66
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
67
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
68
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
69
|
+
},
|
|
70
|
+
} as any;
|
|
71
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
72
|
+
|
|
73
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
74
|
+
expect(spyLogDebug).toHaveBeenCalledWith('hsvProperty: %O', colorSchema.property);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('color schema without defined property but mode includes colour', () => {
|
|
78
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
79
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
80
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
81
|
+
const colorSchema = { code: 'color', type: TuyaDeviceSchemaType.Json } as any; // No property
|
|
82
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
83
|
+
|
|
84
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
85
|
+
expect(spyLogDebug).toHaveBeenCalledWith('hsvProperty: %O', {
|
|
86
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
87
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
88
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
89
|
+
});
|
|
90
|
+
expect(colorSchema.property).toEqual({
|
|
91
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
92
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
93
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('color schema without defined property and mode does not include colour', () => {
|
|
98
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
99
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
100
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
101
|
+
const colorSchema = { code: 'color', type: TuyaDeviceSchemaType.Json } as any; // No property
|
|
102
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['white'] } } as any;
|
|
103
|
+
|
|
104
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
105
|
+
expect(spyLogDebug).toHaveBeenCalledWith('hsvProperty: %O', {});
|
|
106
|
+
expect(colorSchema.property).toBeUndefined();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('color schema with non JSON type but with defined property includes colour', () => {
|
|
110
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
111
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
112
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
113
|
+
const colorSchema = {
|
|
114
|
+
code: 'color',
|
|
115
|
+
type: 'unsupported',
|
|
116
|
+
property: {
|
|
117
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
118
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
119
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
120
|
+
},
|
|
121
|
+
} as any;
|
|
122
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
123
|
+
|
|
124
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
125
|
+
expect(spyLogDebug).toHaveBeenCalledWith('hsvProperty: %O', colorSchema.property);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('getLightType', () => {
|
|
130
|
+
let spyLogInfo = jest.spyOn(mockLogger, 'info').mockImplementation(() => {});
|
|
131
|
+
|
|
132
|
+
beforeEach(() => {
|
|
133
|
+
jest.resetModules();
|
|
134
|
+
spyLogInfo.mockClear();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('Unknown light type when no schemas are provided', () => {
|
|
138
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
139
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
140
|
+
configureLight(accessoryMock, serviceMock, onSchema, undefined, tempSchema);
|
|
141
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'Unknown');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('Normal light type when only on schema is provided', () => {
|
|
145
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
146
|
+
|
|
147
|
+
configureLight(accessoryMock, serviceMock, onSchema);
|
|
148
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'Normal');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('CW light type when on and temp schemas are provided', () => {
|
|
152
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
153
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
154
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
155
|
+
|
|
156
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema);
|
|
157
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'CW');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('RGB light type when on and color schemas are provided', () => {
|
|
161
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
162
|
+
const colorSchema = {
|
|
163
|
+
code: 'color',
|
|
164
|
+
type: TuyaDeviceSchemaType.Json,
|
|
165
|
+
property: {
|
|
166
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
167
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
168
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
169
|
+
},
|
|
170
|
+
} as any;
|
|
171
|
+
|
|
172
|
+
configureLight(accessoryMock, serviceMock, onSchema, undefined, undefined, colorSchema);
|
|
173
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'RGB');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('RGBC light type when on, color, and mode schemas are provided with mode including colour', () => {
|
|
177
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
178
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
179
|
+
const colorSchema = {
|
|
180
|
+
code: 'color',
|
|
181
|
+
type: TuyaDeviceSchemaType.Json,
|
|
182
|
+
property: {
|
|
183
|
+
h: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 360, scale: 0 },
|
|
184
|
+
s: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
185
|
+
v: { type: TuyaDeviceSchemaType.Integer, min: 0, max: 1000, scale: 0 },
|
|
186
|
+
},
|
|
187
|
+
} as any;
|
|
188
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
189
|
+
|
|
190
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, undefined, colorSchema, modeSchema);
|
|
191
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'RGBC');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('RGBCW light type', () => {
|
|
195
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
196
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
197
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
198
|
+
const colorSchema = { code: 'color', type: TuyaDeviceSchemaType.Json, property: { h: {}, s: {}, v: {} } } as any;
|
|
199
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
200
|
+
|
|
201
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
202
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'RGBCW');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('RGBCW light type with JSON color schema without property but mode includes colour', () => {
|
|
206
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
207
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
208
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
209
|
+
const colorSchema = { code: 'color', type: TuyaDeviceSchemaType.Json } as any; // No property
|
|
210
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
211
|
+
|
|
212
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
213
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'RGBCW');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('RGBCW light type with JSON color schema without property and mode does not include colour', () => {
|
|
217
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
218
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
219
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
220
|
+
const colorSchema = { code: 'color', type: TuyaDeviceSchemaType.Json } as any; // No property
|
|
221
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['white'] } } as any;
|
|
222
|
+
|
|
223
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
224
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'CW');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('RGBCW light type with non JSON color schema', () => {
|
|
228
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
229
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
230
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
231
|
+
const colorSchema = { code: 'color', type: 'unsupported' } as any; // Unsupported type
|
|
232
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
233
|
+
|
|
234
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
235
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'CW');
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('RGBCW light type with non JSON with property color schema', () => {
|
|
239
|
+
const onSchema = { code: 'on', type: TuyaDeviceSchemaType.Boolean } as any;
|
|
240
|
+
const brightSchema = { code: 'bright', type: TuyaDeviceSchemaType.Integer } as any;
|
|
241
|
+
const tempSchema = { code: 'temp', type: TuyaDeviceSchemaType.Integer } as any;
|
|
242
|
+
const colorSchema = { code: 'color', type: 'unsupported', property: { h: {}, s: {}, v: {} } } as any; // Unsupported type but has property
|
|
243
|
+
const modeSchema = { code: 'mode', type: TuyaDeviceSchemaType.Enum, property: { range: ['colour', 'white'] } } as any;
|
|
244
|
+
|
|
245
|
+
configureLight(accessoryMock, serviceMock, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
|
|
246
|
+
expect(spyLogInfo).toHaveBeenCalledWith('Light type: %s', 'RGBCW');
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
});
|
|
250
|
+
});
|
package/test/localDevice.test.ts
CHANGED
|
@@ -3,37 +3,7 @@
|
|
|
3
3
|
import { describe, expect, test, beforeEach, afterEach, jest } from '@jest/globals';
|
|
4
4
|
import EventEmitter from 'events';
|
|
5
5
|
import LocalDevice, { LocalDeviceContext } from '../src/local/LocalDevice';
|
|
6
|
-
|
|
7
|
-
// Mock Logger
|
|
8
|
-
jest.mock('../src/shared/util/Logger', () => ({
|
|
9
|
-
__esModule: true,
|
|
10
|
-
default: class Logger {
|
|
11
|
-
log() {}
|
|
12
|
-
info() {}
|
|
13
|
-
warn() {}
|
|
14
|
-
error() {}
|
|
15
|
-
debug() {}
|
|
16
|
-
},
|
|
17
|
-
PrefixLogger: class PrefixLogger {
|
|
18
|
-
constructor(public log: any, public prefix: string, public debugMode: boolean) {}
|
|
19
|
-
debug(message?: any, ...args: any[]) {
|
|
20
|
-
if (this.debugMode) {
|
|
21
|
-
this.log.info((this.prefix ? `[${this.prefix}] ` : '') + message, ...args);
|
|
22
|
-
} else {
|
|
23
|
-
this.log.debug((this.prefix ? `[${this.prefix}] ` : '') + message, ...args);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
info(message?: any, ...args: any[]) {
|
|
27
|
-
this.log.info((this.prefix ? `[${this.prefix}] ` : '') + message, ...args);
|
|
28
|
-
}
|
|
29
|
-
warn(message?: any, ...args: any[]) {
|
|
30
|
-
this.log.warn((this.prefix ? `[${this.prefix}] ` : '') + message, ...args);
|
|
31
|
-
}
|
|
32
|
-
error(message?: any, ...args: any[]) {
|
|
33
|
-
this.log.error((this.prefix ? `[${this.prefix}] ` : '') + message, ...args);
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
}));
|
|
6
|
+
import { initLogger } from '../src/shared/util/Logger';
|
|
37
7
|
|
|
38
8
|
// Mock Protocol
|
|
39
9
|
const mockProtocol = {
|
|
@@ -71,6 +41,7 @@ describe('LocalDevice', () => {
|
|
|
71
41
|
error: jest.fn(),
|
|
72
42
|
debug: jest.fn(),
|
|
73
43
|
};
|
|
44
|
+
initLogger(mockLogger);
|
|
74
45
|
|
|
75
46
|
context = {
|
|
76
47
|
id: 'device_001',
|
|
@@ -89,7 +60,7 @@ describe('LocalDevice', () => {
|
|
|
89
60
|
mockSocket.destroy = jest.fn();
|
|
90
61
|
mockSocket.removeAllListeners = jest.fn();
|
|
91
62
|
|
|
92
|
-
device = new LocalDevice(context
|
|
63
|
+
device = new LocalDevice(context);
|
|
93
64
|
});
|
|
94
65
|
|
|
95
66
|
afterEach(() => {
|
|
@@ -107,7 +78,7 @@ describe('LocalDevice', () => {
|
|
|
107
78
|
|
|
108
79
|
test('sets default port if not provided', () => {
|
|
109
80
|
const contextNoPort = { ...context, port: undefined };
|
|
110
|
-
const dev = new LocalDevice(contextNoPort
|
|
81
|
+
const dev = new LocalDevice(contextNoPort);
|
|
111
82
|
|
|
112
83
|
expect(dev).toBeDefined();
|
|
113
84
|
expect(dev.connected).toBe(false);
|
|
@@ -115,14 +86,14 @@ describe('LocalDevice', () => {
|
|
|
115
86
|
|
|
116
87
|
test('sets default pingGap if not provided', () => {
|
|
117
88
|
const contextNoPingGap = { ...context, pingGap: undefined };
|
|
118
|
-
const dev = new LocalDevice(contextNoPingGap
|
|
89
|
+
const dev = new LocalDevice(contextNoPingGap);
|
|
119
90
|
|
|
120
91
|
expect(dev).toBeDefined();
|
|
121
92
|
});
|
|
122
93
|
|
|
123
94
|
test('sets default connectTimeout if not provided', () => {
|
|
124
95
|
const contextNoTimeout = { ...context, connectTimeout: undefined };
|
|
125
|
-
const dev = new LocalDevice(contextNoTimeout
|
|
96
|
+
const dev = new LocalDevice(contextNoTimeout);
|
|
126
97
|
|
|
127
98
|
expect(dev).toBeDefined();
|
|
128
99
|
});
|
|
@@ -299,21 +270,21 @@ describe('LocalDevice', () => {
|
|
|
299
270
|
describe('protocol handling', () => {
|
|
300
271
|
test('creates protocol for version 3.5', () => {
|
|
301
272
|
const ctxV35 = { ...context, version: '3.5' };
|
|
302
|
-
const devV35 = new LocalDevice(ctxV35
|
|
273
|
+
const devV35 = new LocalDevice(ctxV35);
|
|
303
274
|
|
|
304
275
|
expect(devV35['protocol']).toBeDefined();
|
|
305
276
|
});
|
|
306
277
|
|
|
307
278
|
test('creates protocol for version 3.1', () => {
|
|
308
279
|
const ctxV31 = { ...context, version: '3.1' };
|
|
309
|
-
const devV31 = new LocalDevice(ctxV31
|
|
280
|
+
const devV31 = new LocalDevice(ctxV31);
|
|
310
281
|
|
|
311
282
|
expect(devV31['protocol']).toBeDefined();
|
|
312
283
|
});
|
|
313
284
|
|
|
314
285
|
test('creates protocol for version 3.4', () => {
|
|
315
286
|
const ctxV34 = { ...context, version: '3.4' };
|
|
316
|
-
const devV34 = new LocalDevice(ctxV34
|
|
287
|
+
const devV34 = new LocalDevice(ctxV34);
|
|
317
288
|
|
|
318
289
|
expect(devV34['protocol']).toBeDefined();
|
|
319
290
|
});
|
|
@@ -349,7 +320,7 @@ describe('LocalDevice', () => {
|
|
|
349
320
|
|
|
350
321
|
test('creates device logger with context', () => {
|
|
351
322
|
const ctxNoName = { ...context, name: undefined };
|
|
352
|
-
const devNoName = new LocalDevice(ctxNoName
|
|
323
|
+
const devNoName = new LocalDevice(ctxNoName);
|
|
353
324
|
|
|
354
325
|
expect(devNoName.log).toBeDefined();
|
|
355
326
|
});
|
|
@@ -358,21 +329,21 @@ describe('LocalDevice', () => {
|
|
|
358
329
|
describe('connection configuration', () => {
|
|
359
330
|
test('uses custom port if provided', () => {
|
|
360
331
|
const ctxCustomPort = { ...context, port: 8888 };
|
|
361
|
-
const devCustomPort = new LocalDevice(ctxCustomPort
|
|
332
|
+
const devCustomPort = new LocalDevice(ctxCustomPort);
|
|
362
333
|
|
|
363
334
|
expect(devCustomPort['context'].port).toBe(8888);
|
|
364
335
|
});
|
|
365
336
|
|
|
366
337
|
test('uses custom pingGap if provided', () => {
|
|
367
338
|
const ctxCustomPing = { ...context, pingGap: 15 };
|
|
368
|
-
const devCustomPing = new LocalDevice(ctxCustomPing
|
|
339
|
+
const devCustomPing = new LocalDevice(ctxCustomPing);
|
|
369
340
|
|
|
370
341
|
expect(devCustomPing['context'].pingGap).toBe(15);
|
|
371
342
|
});
|
|
372
343
|
|
|
373
344
|
test('uses custom connectTimeout if provided', () => {
|
|
374
345
|
const ctxCustomTimeout = { ...context, connectTimeout: 60 };
|
|
375
|
-
const devCustomTimeout = new LocalDevice(ctxCustomTimeout
|
|
346
|
+
const devCustomTimeout = new LocalDevice(ctxCustomTimeout);
|
|
376
347
|
|
|
377
348
|
expect(devCustomTimeout['context'].connectTimeout).toBe(60);
|
|
378
349
|
});
|
|
@@ -381,7 +352,7 @@ describe('LocalDevice', () => {
|
|
|
381
352
|
describe('device types', () => {
|
|
382
353
|
test('handles light device', () => {
|
|
383
354
|
const lightContext = { ...context, id: 'light_001', name: 'Smart Light' };
|
|
384
|
-
const light = new LocalDevice(lightContext
|
|
355
|
+
const light = new LocalDevice(lightContext);
|
|
385
356
|
|
|
386
357
|
expect(light['context'].id).toBe('light_001');
|
|
387
358
|
expect(light['context'].name).toBe('Smart Light');
|
|
@@ -389,14 +360,14 @@ describe('LocalDevice', () => {
|
|
|
389
360
|
|
|
390
361
|
test('handles switch device', () => {
|
|
391
362
|
const switchContext = { ...context, id: 'switch_001', name: 'Smart Switch' };
|
|
392
|
-
const switchDev = new LocalDevice(switchContext
|
|
363
|
+
const switchDev = new LocalDevice(switchContext);
|
|
393
364
|
|
|
394
365
|
expect(switchDev['context'].id).toBe('switch_001');
|
|
395
366
|
});
|
|
396
367
|
|
|
397
368
|
test('handles outlet device', () => {
|
|
398
369
|
const outletContext = { ...context, id: 'outlet_001', name: 'Smart Outlet' };
|
|
399
|
-
const outlet = new LocalDevice(outletContext
|
|
370
|
+
const outlet = new LocalDevice(outletContext);
|
|
400
371
|
|
|
401
372
|
expect(outlet['context'].id).toBe('outlet_001');
|
|
402
373
|
});
|
|
@@ -429,8 +400,8 @@ describe('LocalDevice', () => {
|
|
|
429
400
|
connectTimeout: 30,
|
|
430
401
|
};
|
|
431
402
|
|
|
432
|
-
deviceV34 = new LocalDevice(contextV34
|
|
433
|
-
deviceV35 = new LocalDevice(contextV35
|
|
403
|
+
deviceV34 = new LocalDevice(contextV34);
|
|
404
|
+
deviceV35 = new LocalDevice(contextV35);
|
|
434
405
|
});
|
|
435
406
|
|
|
436
407
|
afterEach(() => {
|
|
@@ -463,7 +434,7 @@ describe('LocalDevice', () => {
|
|
|
463
434
|
const localNonce = Buffer.from('0123456789abcdef');
|
|
464
435
|
const remoteNonce = Buffer.from('fedcba9876543210');
|
|
465
436
|
const invalidHmac = Buffer.alloc(32); // all zeros - definitely wrong
|
|
466
|
-
const step2Payload = Buffer.concat([remoteNonce, invalidHmac]);
|
|
437
|
+
const step2Payload = Buffer.concat([remoteNonce as Uint8Array, invalidHmac as Uint8Array]);
|
|
467
438
|
|
|
468
439
|
deviceV34['tmpLocalKey'] = localNonce;
|
|
469
440
|
deviceV34['socket'] = mockSocket;
|
|
@@ -543,8 +514,8 @@ describe('LocalDevice', () => {
|
|
|
543
514
|
port: 6668,
|
|
544
515
|
};
|
|
545
516
|
|
|
546
|
-
deviceV34 = new LocalDevice(contextV34
|
|
547
|
-
deviceV35 = new LocalDevice(contextV35
|
|
517
|
+
deviceV34 = new LocalDevice(contextV34);
|
|
518
|
+
deviceV35 = new LocalDevice(contextV35);
|
|
548
519
|
});
|
|
549
520
|
|
|
550
521
|
afterEach(() => {
|