@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,482 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, jest, test } from '@jest/globals';
|
|
2
|
+
import { EOL } from 'os';
|
|
3
|
+
import Logger, { initLogger, logger, PrefixLogger } from '../src/shared/util/Logger';
|
|
4
|
+
|
|
5
|
+
describe('Logger', () => {
|
|
6
|
+
const output:string[] = [];
|
|
7
|
+
let spyStdout;
|
|
8
|
+
let spyStderr;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
output.splice(0, output.length);
|
|
11
|
+
spyStdout = jest
|
|
12
|
+
.spyOn(process.stdout, 'write')
|
|
13
|
+
.mockImplementation((value) => {
|
|
14
|
+
const str = String(value);
|
|
15
|
+
if (str.startsWith(' ')) {
|
|
16
|
+
output.push(str.split(/\r\n|\r|\n/)[1].replace(/^ /, ''));
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
});
|
|
20
|
+
spyStderr = jest
|
|
21
|
+
.spyOn(process.stderr, 'write')
|
|
22
|
+
.mockImplementation((value) => {
|
|
23
|
+
const str = String(value);
|
|
24
|
+
if (str.startsWith(' ')) {
|
|
25
|
+
output.push(str.split(/\r\n|\r|\n/)[1].replace(/^ /, ''));
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
});
|
|
29
|
+
jest.clearAllMocks();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('info log', () => {
|
|
33
|
+
test('string message', () => {
|
|
34
|
+
const mockLog = {
|
|
35
|
+
info: jest.fn(),
|
|
36
|
+
warn: jest.fn(),
|
|
37
|
+
debug: jest.fn(),
|
|
38
|
+
error: jest.fn(),
|
|
39
|
+
} as Logger;
|
|
40
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
41
|
+
const spyInfo = jest.spyOn(mockLog, 'info');
|
|
42
|
+
instance.info('info');
|
|
43
|
+
expect(spyInfo).toHaveBeenCalledWith('[test] info');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('number message', () => {
|
|
47
|
+
const mockLog = {
|
|
48
|
+
info: jest.fn(),
|
|
49
|
+
warn: jest.fn(),
|
|
50
|
+
debug: jest.fn(),
|
|
51
|
+
error: jest.fn(),
|
|
52
|
+
} as Logger;
|
|
53
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
54
|
+
const spyInfo = jest.spyOn(mockLog, 'info');
|
|
55
|
+
instance.info(1);
|
|
56
|
+
expect(spyInfo).toHaveBeenCalledWith('[test] 1');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('object message', () => {
|
|
60
|
+
const mockLog = {
|
|
61
|
+
info: jest.fn(),
|
|
62
|
+
warn: jest.fn(),
|
|
63
|
+
debug: jest.fn(),
|
|
64
|
+
error: jest.fn(),
|
|
65
|
+
success: jest.fn(),
|
|
66
|
+
} as Logger;
|
|
67
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
68
|
+
const spyInfo = jest.spyOn(mockLog, 'info');
|
|
69
|
+
instance.info({ info: 'message'});
|
|
70
|
+
expect(spyInfo).toHaveBeenCalledWith('[test] { info: \'message\' }');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('array message', () => {
|
|
74
|
+
const mockLog = {
|
|
75
|
+
info: jest.fn(),
|
|
76
|
+
warn: jest.fn(),
|
|
77
|
+
debug: jest.fn(),
|
|
78
|
+
error: jest.fn(),
|
|
79
|
+
success: jest.fn(),
|
|
80
|
+
} as Logger;
|
|
81
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
82
|
+
const spyInfo = jest.spyOn(mockLog, 'info');
|
|
83
|
+
instance.info(['a', 'b', 'c']);
|
|
84
|
+
expect(spyInfo).toHaveBeenCalledWith('[test] [ \'a\', \'b\', \'c\' ]');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('message with arguments', () => {
|
|
88
|
+
const mockLog = {
|
|
89
|
+
info: jest.fn(),
|
|
90
|
+
warn: jest.fn(),
|
|
91
|
+
debug: jest.fn(),
|
|
92
|
+
error: jest.fn(),
|
|
93
|
+
success: jest.fn(),
|
|
94
|
+
} as Logger;
|
|
95
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
96
|
+
const spyInfo = jest.spyOn(mockLog, 'info');
|
|
97
|
+
instance.info('with arguments %s, %o', 'args', { arg: 'object' });
|
|
98
|
+
expect(spyInfo).toHaveBeenCalledWith("[test] with arguments %s, %o", "args", {"arg": "object"});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('success log', () => {
|
|
103
|
+
test('success method unavailable', () => {
|
|
104
|
+
const mockLog = {
|
|
105
|
+
info: jest.fn(),
|
|
106
|
+
warn: jest.fn(),
|
|
107
|
+
debug: jest.fn(),
|
|
108
|
+
error: jest.fn(),
|
|
109
|
+
} as Logger;
|
|
110
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
111
|
+
const spyInfo = jest.spyOn(mockLog, 'info');
|
|
112
|
+
instance.success('successed');
|
|
113
|
+
expect(spyInfo).toHaveBeenCalledWith('[test] successed');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('success method available', () => {
|
|
117
|
+
const mockLog = {
|
|
118
|
+
info: jest.fn(),
|
|
119
|
+
warn: jest.fn(),
|
|
120
|
+
debug: jest.fn(),
|
|
121
|
+
error: jest.fn(),
|
|
122
|
+
success: jest.fn(),
|
|
123
|
+
} as Logger;
|
|
124
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
125
|
+
const spySuccess = jest.spyOn(mockLog as any, 'success');
|
|
126
|
+
instance.success('successed');
|
|
127
|
+
expect(spySuccess).toHaveBeenCalledWith('[test] successed');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('number message, success method unavailable', () => {
|
|
131
|
+
const mockLog = {
|
|
132
|
+
info: jest.fn(),
|
|
133
|
+
warn: jest.fn(),
|
|
134
|
+
debug: jest.fn(),
|
|
135
|
+
error: jest.fn(),
|
|
136
|
+
} as Logger;
|
|
137
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
138
|
+
const spyInfo = jest.spyOn(mockLog, 'info');
|
|
139
|
+
instance.success(1);
|
|
140
|
+
expect(spyInfo).toHaveBeenCalledWith('[test] 1');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('number message. success method available', () => {
|
|
144
|
+
const mockLog = {
|
|
145
|
+
info: jest.fn(),
|
|
146
|
+
warn: jest.fn(),
|
|
147
|
+
debug: jest.fn(),
|
|
148
|
+
error: jest.fn(),
|
|
149
|
+
success: jest.fn(),
|
|
150
|
+
} as Logger;
|
|
151
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
152
|
+
const spySuccess = jest.spyOn(mockLog as any, 'success');
|
|
153
|
+
instance.success(1);
|
|
154
|
+
expect(spySuccess).toHaveBeenCalledWith('[test] 1');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('message with arguments(success method unavailable)', () => {
|
|
158
|
+
const mockLog = {
|
|
159
|
+
info: jest.fn(),
|
|
160
|
+
warn: jest.fn(),
|
|
161
|
+
debug: jest.fn(),
|
|
162
|
+
error: jest.fn(),
|
|
163
|
+
} as Logger;
|
|
164
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
165
|
+
const spyInfo = jest.spyOn(mockLog, 'info');
|
|
166
|
+
instance.success('with arguments %s, %o', 'args', { arg: 'object' });
|
|
167
|
+
expect(spyInfo).toHaveBeenCalledWith("[test] with arguments %s, %o", "args", {"arg": "object"});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('message with arguments(success method available)', () => {
|
|
171
|
+
const mockLog = {
|
|
172
|
+
info: jest.fn(),
|
|
173
|
+
warn: jest.fn(),
|
|
174
|
+
debug: jest.fn(),
|
|
175
|
+
error: jest.fn(),
|
|
176
|
+
success: jest.fn(),
|
|
177
|
+
} as Logger;
|
|
178
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
179
|
+
const spySuccess = jest.spyOn(mockLog as any, 'success');
|
|
180
|
+
instance.success('with arguments %s, %o', 'args', { arg: 'object' });
|
|
181
|
+
expect(spySuccess).toHaveBeenCalledWith("[test] with arguments %s, %o", "args", {"arg": "object"});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('debug log', () => {
|
|
186
|
+
test('debugMode disabled', () => {
|
|
187
|
+
const instance = new PrefixLogger(console, 'test', false);
|
|
188
|
+
const spyInfo = jest.spyOn(console, 'info');
|
|
189
|
+
const spyDebug = jest.spyOn(console, 'debug');
|
|
190
|
+
instance.debug('debug');
|
|
191
|
+
expect(spyInfo).toHaveBeenCalledTimes(0);
|
|
192
|
+
expect(spyDebug).toHaveBeenCalledWith('[test] debug');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('debugMode enabled. (string)', () => {
|
|
196
|
+
const instance = new PrefixLogger(console, 'test', true);
|
|
197
|
+
const spyInfo = jest.spyOn(console, 'info');
|
|
198
|
+
const spyDebug = jest.spyOn(console, 'debug');
|
|
199
|
+
instance.debug('debug');
|
|
200
|
+
expect(spyInfo).toHaveBeenCalledTimes(1);
|
|
201
|
+
expect(spyDebug).toHaveBeenCalledTimes(0);
|
|
202
|
+
expect(spyInfo).toHaveBeenCalledWith('[test] debug');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('debugMode enabled. (non-string)', () => {
|
|
206
|
+
const instance = new PrefixLogger(console, 'test', true);
|
|
207
|
+
const spyInfo = jest.spyOn(console, 'info');
|
|
208
|
+
const spyDebug = jest.spyOn(console, 'debug');
|
|
209
|
+
instance.debug({ debug: 'enabled' });
|
|
210
|
+
expect(spyInfo).toHaveBeenCalledTimes(1);
|
|
211
|
+
expect(spyDebug).toHaveBeenCalledTimes(0);
|
|
212
|
+
expect(spyInfo).toHaveBeenCalledWith('[test] { debug: \'enabled\' }');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('number message', () => {
|
|
216
|
+
const mockLog = {
|
|
217
|
+
info: jest.fn(),
|
|
218
|
+
warn: jest.fn(),
|
|
219
|
+
debug: jest.fn(),
|
|
220
|
+
error: jest.fn(),
|
|
221
|
+
} as Logger;
|
|
222
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
223
|
+
const spyDebug = jest.spyOn(mockLog, 'debug');
|
|
224
|
+
instance.debug(1);
|
|
225
|
+
expect(spyDebug).toHaveBeenCalledWith('[test] 1');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('message with arguments', () => {
|
|
229
|
+
const mockLog = {
|
|
230
|
+
info: jest.fn(),
|
|
231
|
+
warn: jest.fn(),
|
|
232
|
+
debug: jest.fn(),
|
|
233
|
+
error: jest.fn(),
|
|
234
|
+
} as Logger;
|
|
235
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
236
|
+
const spyDebug = jest.spyOn(mockLog as any, 'debug');
|
|
237
|
+
instance.debug('with arguments %s, %o', 'args', { arg: 'object' });
|
|
238
|
+
expect(spyDebug).toHaveBeenCalledWith("[test] with arguments %s, %o", "args", {"arg": "object"});
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe('warn log', () => {
|
|
243
|
+
test('string message', () => {
|
|
244
|
+
const mockLog = {
|
|
245
|
+
info: jest.fn(),
|
|
246
|
+
warn: jest.fn(),
|
|
247
|
+
debug: jest.fn(),
|
|
248
|
+
error: jest.fn(),
|
|
249
|
+
} as Logger;
|
|
250
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
251
|
+
const spyWarn = jest.spyOn(mockLog, 'warn');
|
|
252
|
+
instance.warn('warn');
|
|
253
|
+
expect(spyWarn).toHaveBeenCalledWith('[test] warn');
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test('number message', () => {
|
|
257
|
+
const mockLog = {
|
|
258
|
+
info: jest.fn(),
|
|
259
|
+
warn: jest.fn(),
|
|
260
|
+
debug: jest.fn(),
|
|
261
|
+
error: jest.fn(),
|
|
262
|
+
} as Logger;
|
|
263
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
264
|
+
const spyWarn = jest.spyOn(mockLog, 'warn');
|
|
265
|
+
instance.warn(1);
|
|
266
|
+
expect(spyWarn).toHaveBeenCalledWith('[test] 1');
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test('message with arguments', () => {
|
|
270
|
+
const mockLog = {
|
|
271
|
+
info: jest.fn(),
|
|
272
|
+
warn: jest.fn(),
|
|
273
|
+
debug: jest.fn(),
|
|
274
|
+
error: jest.fn(),
|
|
275
|
+
} as Logger;
|
|
276
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
277
|
+
const spyWarn = jest.spyOn(mockLog as any, 'warn');
|
|
278
|
+
instance.warn('with arguments %s, %o', 'args', { arg: 'object' });
|
|
279
|
+
expect(spyWarn).toHaveBeenCalledWith("[test] with arguments %s, %o", "args", {"arg": "object"});
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
describe('error log', () => {
|
|
284
|
+
test('string message', () => {
|
|
285
|
+
const mockLog = {
|
|
286
|
+
info: jest.fn(),
|
|
287
|
+
warn: jest.fn(),
|
|
288
|
+
debug: jest.fn(),
|
|
289
|
+
error: jest.fn(),
|
|
290
|
+
} as Logger;
|
|
291
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
292
|
+
const spyError = jest.spyOn(mockLog, 'error');
|
|
293
|
+
instance.error('error');
|
|
294
|
+
expect(spyError).toHaveBeenCalledWith('[test] error');
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test('number message', () => {
|
|
298
|
+
const mockLog = {
|
|
299
|
+
info: jest.fn(),
|
|
300
|
+
warn: jest.fn(),
|
|
301
|
+
debug: jest.fn(),
|
|
302
|
+
error: jest.fn(),
|
|
303
|
+
} as Logger;
|
|
304
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
305
|
+
const spyError = jest.spyOn(mockLog, 'error');
|
|
306
|
+
instance.error(1);
|
|
307
|
+
expect(spyError).toHaveBeenCalledWith('[test] 1');
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test('message with arguments', () => {
|
|
311
|
+
const mockLog = {
|
|
312
|
+
info: jest.fn(),
|
|
313
|
+
warn: jest.fn(),
|
|
314
|
+
debug: jest.fn(),
|
|
315
|
+
error: jest.fn(),
|
|
316
|
+
} as Logger;
|
|
317
|
+
const instance = new PrefixLogger(mockLog, 'test', false);
|
|
318
|
+
const spyError = jest.spyOn(mockLog as any, 'error');
|
|
319
|
+
instance.error('with arguments %s, %o', 'args', { arg: 'object' });
|
|
320
|
+
expect(spyError).toHaveBeenCalledWith("[test] with arguments %s, %o", "args", {"arg": "object"});
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
describe('init logger', () => {
|
|
325
|
+
test('before initLogger', () => {
|
|
326
|
+
expect(logger()).toBe(console);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test('after initLogger', () => {
|
|
330
|
+
const mockLog = {
|
|
331
|
+
info: jest.fn(),
|
|
332
|
+
warn: jest.fn(),
|
|
333
|
+
debug: jest.fn(),
|
|
334
|
+
error: jest.fn(),
|
|
335
|
+
} as Logger;
|
|
336
|
+
initLogger(mockLog);
|
|
337
|
+
expect(logger()).toBe(mockLog);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test('undefined prefix', () => {
|
|
341
|
+
const mockLog = {
|
|
342
|
+
info: jest.fn(),
|
|
343
|
+
warn: jest.fn(),
|
|
344
|
+
debug: jest.fn(),
|
|
345
|
+
error: jest.fn(),
|
|
346
|
+
} as Logger;
|
|
347
|
+
const instance = new PrefixLogger(mockLog, undefined, false);
|
|
348
|
+
const spyInfo = jest.spyOn(mockLog, 'info');
|
|
349
|
+
instance.info('noprefix');
|
|
350
|
+
expect(spyInfo).toHaveBeenCalledWith('[] noprefix');
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test('undefined debugMode', () => {
|
|
354
|
+
const mockLog = {
|
|
355
|
+
info: jest.fn(),
|
|
356
|
+
warn: jest.fn(),
|
|
357
|
+
debug: jest.fn(),
|
|
358
|
+
error: jest.fn(),
|
|
359
|
+
} as Logger;
|
|
360
|
+
const instance = new PrefixLogger(mockLog, 'test');
|
|
361
|
+
expect(instance.debugMode).toBe(false);
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
describe('masking()', () => {
|
|
366
|
+
test('Return as-is when masking is OFF (string)', () => {
|
|
367
|
+
const instance = new PrefixLogger(console as unknown as Logger, 'test', true);
|
|
368
|
+
const input = `'password': 'abc'`;
|
|
369
|
+
expect((instance as any).masking(input)).toBe(input);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test('Return as-is when masking is OFF (object)', () => {
|
|
373
|
+
const instance = new PrefixLogger(console as unknown as Logger, 'test', true);
|
|
374
|
+
const input = { password: 'abc' };
|
|
375
|
+
expect((instance as any).masking(input)).toBe(input);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test('Mask the password', () => {
|
|
379
|
+
const instance = new PrefixLogger(console as unknown as Logger, 'test', false);
|
|
380
|
+
const input = `'password': 'abc'`;
|
|
381
|
+
const output = `'password': '********'`;
|
|
382
|
+
expect((instance as any).masking(input)).toBe(output);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
test('Mask the token', () => {
|
|
386
|
+
const instance = new PrefixLogger(console as unknown as Logger, 'test', false);
|
|
387
|
+
const input = `'token' : 'abcdef'`;
|
|
388
|
+
const output = `'token': '********'`;
|
|
389
|
+
expect((instance as any).masking(input)).toBe(output);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test('Mask the password in line', () => {
|
|
393
|
+
const instance = new PrefixLogger(console as unknown as Logger, 'test', false);
|
|
394
|
+
const input = `abc 'password': 'abc' def`;
|
|
395
|
+
const output = `abc 'password': '********' def`;
|
|
396
|
+
expect((instance as any).masking(input)).toBe(output);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
test('Two maskable targets within the string.', () => {
|
|
400
|
+
const instance = new PrefixLogger(console as unknown as Logger, 'test', false);
|
|
401
|
+
const input = `'password': 'abc', 'password': 'def'`;
|
|
402
|
+
const output = `'password': '********', 'password': '********'`;
|
|
403
|
+
expect((instance as any).masking(input)).toBe(output);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test('Mask only the target lines in multi-line text', () => {
|
|
407
|
+
const instance = new PrefixLogger(console as unknown as Logger, 'test', false);
|
|
408
|
+
const input = [
|
|
409
|
+
`normal line`,
|
|
410
|
+
`'password' : '123456'`,
|
|
411
|
+
`another line`,
|
|
412
|
+
`'apiKey': 'xyz'`
|
|
413
|
+
].join('\n');
|
|
414
|
+
|
|
415
|
+
const expected = [
|
|
416
|
+
`normal line`,
|
|
417
|
+
`'password': '********'`,
|
|
418
|
+
`another line`,
|
|
419
|
+
`'apiKey': '********'`
|
|
420
|
+
].join(EOL);
|
|
421
|
+
expect((instance as any).masking(input)).toBe(expected);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
test('Leave unmatched strings unchanged', () => {
|
|
425
|
+
const instance = new PrefixLogger(console as unknown as Logger, 'test', false);
|
|
426
|
+
const input = `no sensitive data here`;
|
|
427
|
+
expect((instance as any).masking(input)).toBe(input);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test('Leave unmatched objects unchanged', () => {
|
|
431
|
+
const instance = new PrefixLogger(console as unknown as Logger, 'test', false);
|
|
432
|
+
const input = { test: 'unchanged' };
|
|
433
|
+
expect((instance as any).masking(input)).toBe(input);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
describe('maskingValue()', () => {
|
|
438
|
+
test('Mask object value', () => {
|
|
439
|
+
const instance = new PrefixLogger(console as unknown as Logger, 'test', false);
|
|
440
|
+
const input = {
|
|
441
|
+
id: 'testID',
|
|
442
|
+
password: 'testPassword',
|
|
443
|
+
token: 'testToken',
|
|
444
|
+
accessToken: 'testAccessToken',
|
|
445
|
+
Access_Token: 'testAccess_Token',
|
|
446
|
+
aCcEsSkEy: 'testAccessKey',
|
|
447
|
+
tuyakey: 'testTuyaKey',
|
|
448
|
+
api_key: 'testApiKey',
|
|
449
|
+
secret: 'testSecret',
|
|
450
|
+
name: 'testName',
|
|
451
|
+
obj: {
|
|
452
|
+
password: 'test-objpassword'
|
|
453
|
+
},
|
|
454
|
+
func: () => 'test'
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
const expected = {
|
|
458
|
+
id: 'testID',
|
|
459
|
+
password: '************',
|
|
460
|
+
token: '*********',
|
|
461
|
+
accessToken: '***************',
|
|
462
|
+
Access_Token: '****************',
|
|
463
|
+
aCcEsSkEy: '*************',
|
|
464
|
+
tuyakey: '***********',
|
|
465
|
+
api_key: '**********',
|
|
466
|
+
secret: '**********',
|
|
467
|
+
name: 'testName',
|
|
468
|
+
obj: {
|
|
469
|
+
password: '****************'
|
|
470
|
+
},
|
|
471
|
+
func: input.func
|
|
472
|
+
};
|
|
473
|
+
expect((instance as any).maskingValue(input)).toEqual(expected);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
test('Leave matched objects unchanged', () => {
|
|
477
|
+
const instance = new PrefixLogger(console as unknown as Logger, 'test', true);
|
|
478
|
+
const input = { password: 'test' };
|
|
479
|
+
expect((instance as any).maskingValue(input)).toBe(input);
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { describe, expect, test, beforeEach, jest } from '@jest/globals';
|
|
3
|
+
import { PlatformAccessory, Service } from 'homebridge';
|
|
4
|
+
import AccessoryFactory from '../src/shared/accessory/AccessoryFactory';
|
|
5
|
+
import TuyaDevice from '../src/cloud/device/TuyaDevice';
|
|
6
|
+
import { TuyaPlatform, TuyaPluginAccessoryContext } from '../src/platform';
|
|
7
|
+
import { ExLogger, initLogger } from '../src/shared/util/Logger';
|
|
8
|
+
import cz from './data/cz/wja8imamn8sj2sjf.json';
|
|
9
|
+
import qn from './data/qn/eabctkdf7akikibf.json';
|
|
10
|
+
import SwitchAccessory from '../src/shared/accessory/SwitchAccessory';
|
|
11
|
+
import HeaterAccessory from '../src/shared/accessory/HeaterAccessory';
|
|
12
|
+
|
|
13
|
+
describe('AccessoryFactory data sample', () => {
|
|
14
|
+
let mockPlatform: Partial<TuyaPlatform>;
|
|
15
|
+
let mockAccessory: Partial<PlatformAccessory>;
|
|
16
|
+
let mockAccessoryService: Partial<Service>;
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
// Mock Logger
|
|
20
|
+
const mockLog: ExLogger = {
|
|
21
|
+
debug: jest.fn(),
|
|
22
|
+
info: jest.fn(),
|
|
23
|
+
warn: jest.fn(),
|
|
24
|
+
error: jest.fn(),
|
|
25
|
+
log: jest.fn(),
|
|
26
|
+
success: jest.fn(),
|
|
27
|
+
} as unknown as ExLogger;
|
|
28
|
+
initLogger(console);
|
|
29
|
+
|
|
30
|
+
// Create proper HAP mock structure
|
|
31
|
+
class MockService {
|
|
32
|
+
static AccessoryInformation = class {};
|
|
33
|
+
static Lightbulb = class {};
|
|
34
|
+
static Switch = class {};
|
|
35
|
+
static Outlet = class {};
|
|
36
|
+
static Fan = class {};
|
|
37
|
+
static Thermostat = class {};
|
|
38
|
+
static WindowCovering = class {};
|
|
39
|
+
static GarageDoorOpener = class {};
|
|
40
|
+
static LockMechanism = class {};
|
|
41
|
+
static Valve = class {};
|
|
42
|
+
static HeaterCooler = class {};
|
|
43
|
+
static Microphone = class {};
|
|
44
|
+
static Speaker = class {};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
class MockCharacteristic {
|
|
48
|
+
static On = { UUID: 'uuid-on' };
|
|
49
|
+
static Brightness = { UUID: 'uuid-brightness' };
|
|
50
|
+
static Name = { UUID: 'uuid-name' };
|
|
51
|
+
static Manufacturer = { UUID: 'uuid-manufacturer' };
|
|
52
|
+
static Model = { UUID: 'uuid-model' };
|
|
53
|
+
static SerialNumber = { UUID: 'uuid-sn' };
|
|
54
|
+
static AccessoryFlags = { UUID: 'uuid-flags' };
|
|
55
|
+
static Identify = { UUID: 'uuid-identify' };
|
|
56
|
+
static CurrentTemperature = { UUID: 'uuid-temp' };
|
|
57
|
+
static TargetTemperature = { UUID: 'uuid-target-temp' };
|
|
58
|
+
static CurrentRelativeHumidity = { UUID: 'uuid-humidity' };
|
|
59
|
+
static Saturation = { UUID: 'uuid-saturation' };
|
|
60
|
+
static Hue = { UUID: 'uuid-hue' };
|
|
61
|
+
static ColorTemperature = { UUID: 'uuid-color-temp' };
|
|
62
|
+
static RotationSpeed = { UUID: 'uuid-rotation' };
|
|
63
|
+
static CurrentPosition = { UUID: 'uuid-position' };
|
|
64
|
+
static TargetPosition = { UUID: 'uuid-target-pos' };
|
|
65
|
+
static LockCurrentState = { UUID: 'uuid-lock-state' };
|
|
66
|
+
static LockTargetState = { UUID: 'uuid-lock-target' };
|
|
67
|
+
static LockPhysicalControls = { UUID: 'uuid-lock-physical-controls' };
|
|
68
|
+
static Active = { UUID: 'uuid-active', INACTIVE: 0, ACTIVE: 1 };
|
|
69
|
+
static CurrentHeatingCoolingState = { UUID: 'uuid-heating-cooling', OFF: 0, HEAT: 1, COOL: 2, AUTO: 3 };
|
|
70
|
+
static TargetHeatingCoolingState = { UUID: 'uuid-target-heating-cooling', OFF: 0, HEAT: 1, COOL: 2, AUTO: 3 };
|
|
71
|
+
static TemperatureDisplayUnits = { UUID: 'uuid-temp-units', CELSIUS: 0, FAHRENHEIT: 1 };
|
|
72
|
+
static CurrentHeaterCoolerState = { UUID: 'uuid-current-heater-cooler', IDLE: 0, HEATING: 1, COOLING: 2 };
|
|
73
|
+
static TargetHeaterCoolerState = { UUID: 'uuid-target-heater-cooler', OFF: 0, HEAT: 1, COOL: 2, AUTO: 3 };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
mockPlatform = {
|
|
77
|
+
log: mockLog,
|
|
78
|
+
config: {} as any,
|
|
79
|
+
api: {
|
|
80
|
+
hap: {
|
|
81
|
+
Service: MockService as any,
|
|
82
|
+
Characteristic: MockCharacteristic as any,
|
|
83
|
+
CameraController: jest.fn(),
|
|
84
|
+
},
|
|
85
|
+
} as any,
|
|
86
|
+
accessories: [],
|
|
87
|
+
Service: MockService as any,
|
|
88
|
+
Characteristic: MockCharacteristic as any,
|
|
89
|
+
platformConfig: {
|
|
90
|
+
options: {
|
|
91
|
+
debug: false,
|
|
92
|
+
debugLevel: '',
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
deviceManager: {
|
|
96
|
+
getDevice: jest.fn(),
|
|
97
|
+
getDeviceSchemaConfig: jest.fn().mockReturnValue({})
|
|
98
|
+
},
|
|
99
|
+
} as any;
|
|
100
|
+
|
|
101
|
+
mockAccessoryService = {
|
|
102
|
+
testCharacteristic: jest.fn().mockReturnValue(true),
|
|
103
|
+
setCharacteristic: jest.fn().mockReturnThis(),
|
|
104
|
+
getCharacteristic: jest.fn().mockReturnValue({
|
|
105
|
+
onGet: jest.fn().mockReturnThis(),
|
|
106
|
+
onSet: jest.fn().mockReturnThis(),
|
|
107
|
+
setProps: jest.fn().mockReturnThis(),
|
|
108
|
+
}),
|
|
109
|
+
} as any;
|
|
110
|
+
|
|
111
|
+
mockAccessory = {
|
|
112
|
+
UUID: 'test-uuid',
|
|
113
|
+
displayName: 'Test Device',
|
|
114
|
+
context: {
|
|
115
|
+
deviceID: 'test_device',
|
|
116
|
+
},
|
|
117
|
+
services: [],
|
|
118
|
+
getService: jest.fn().mockReturnValue(mockAccessoryService),
|
|
119
|
+
addService: jest.fn().mockReturnValue(mockAccessoryService),
|
|
120
|
+
removeService: jest.fn().mockReturnThis(),
|
|
121
|
+
removeAllListeners: jest.fn(),
|
|
122
|
+
on: jest.fn(),
|
|
123
|
+
once: jest.fn(),
|
|
124
|
+
configureController: jest.fn(),
|
|
125
|
+
} as any;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('SwitchAccessory', () => {
|
|
129
|
+
const device = new TuyaDevice(cz as any);
|
|
130
|
+
|
|
131
|
+
mockPlatform.deviceManager = {
|
|
132
|
+
...mockPlatform.deviceManager,
|
|
133
|
+
getDevice: jest.fn().mockReturnValue(device),
|
|
134
|
+
getDeviceSchemaConfig: jest.fn().mockReturnValue(undefined)
|
|
135
|
+
} as any;
|
|
136
|
+
|
|
137
|
+
const spyGetCharacteristic = jest.spyOn(mockAccessoryService, 'getCharacteristic');
|
|
138
|
+
|
|
139
|
+
const accessory = AccessoryFactory.createAccessory(
|
|
140
|
+
mockPlatform as TuyaPlatform,
|
|
141
|
+
mockAccessory as PlatformAccessory<TuyaPluginAccessoryContext>,
|
|
142
|
+
device,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
expect(accessory).toBeDefined();
|
|
146
|
+
expect(accessory).toBeInstanceOf(SwitchAccessory);
|
|
147
|
+
expect(spyGetCharacteristic).toHaveBeenCalledWith(mockPlatform.Characteristic!.On);
|
|
148
|
+
expect(spyGetCharacteristic).toHaveBeenCalledWith(mockPlatform.Characteristic!.InUse);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('HeaterAccessory', () => {
|
|
152
|
+
const device = new TuyaDevice(qn as any);
|
|
153
|
+
|
|
154
|
+
mockPlatform.deviceManager = {
|
|
155
|
+
...mockPlatform.deviceManager,
|
|
156
|
+
getDevice: jest.fn().mockReturnValue(device),
|
|
157
|
+
getDeviceSchemaConfig: jest.fn().mockReturnValue(undefined)
|
|
158
|
+
} as any;
|
|
159
|
+
|
|
160
|
+
const spyGetCharacteristic = jest.spyOn(mockAccessoryService, 'getCharacteristic');
|
|
161
|
+
|
|
162
|
+
const accessory = AccessoryFactory.createAccessory(
|
|
163
|
+
mockPlatform as TuyaPlatform,
|
|
164
|
+
mockAccessory as PlatformAccessory<TuyaPluginAccessoryContext>,
|
|
165
|
+
device,
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
expect(accessory).toBeDefined();
|
|
169
|
+
expect(accessory).toBeInstanceOf(HeaterAccessory);
|
|
170
|
+
expect(spyGetCharacteristic).toHaveBeenCalledWith(mockPlatform.Characteristic!.Active);
|
|
171
|
+
});
|
|
172
|
+
});
|