homebridge-fujitsu-airstage
Version:
A Homebridge plugin to control devices that use the Fujitsu Airstage API.
123 lines (108 loc) • 3.3 kB
JavaScript
;
const { mock } = require('node:test');
const hap = require('hap-nodejs');
const PlatformAccessoryManager = require('../platform-accessory-manager');
const airstage = require('../airstage');
const airstageCloudClient = new airstage.cloud.Client(
'us',
'United States',
'en'
);
const airstageLanClient = new airstage.lan.Client(
[],
'C'
);
class MockPlatformAccessory {
context = {
'deviceId': 'testDeviceId',
'model': 'Test Model',
'airstageCloudClient': airstageCloudClient,
'airstageLanClient': airstageLanClient
};
constructor(name, uuid) {
this.name = name;
this.uuid = uuid;
this.UUID = uuid;
}
getService(name) {
return mockService;
}
addService(name) {
return mockService;
}
}
const mockCharacteristic = {
'on': mock.fn((event, listener) => {
return mockCharacteristic;
}),
'emit': mock.fn((event, listener) => {
return mockCharacteristic;
})
};
const mockService = {
'setCharacteristic': mock.fn((name, value) => {
return mockService;
}),
'getCharacteristic': mock.fn((name, value) => {
return mockCharacteristic;
})
};
const mockPlatform = {
'Characteristic': hap.Characteristic,
'Service': hap.Service,
'airstageCloudClient': airstageCloudClient,
'airstageLanClient': airstageLanClient,
'accessories': [],
'lanDeviceIds': [],
'api': {
'hap': hap,
'platformAccessory': MockPlatformAccessory,
'user': {
'configPath': mock.fn(() => {
return '/test/path';
}),
'persistPath': mock.fn(() => {
return '/test/path';
})
},
'updatePlatformAccessories': mock.fn(
(accessories) => {}
),
'registerPlatformAccessories': mock.fn(
(pluginName, platformName, accessories) => {}
),
'unregisterPlatformAccessories': mock.fn(
(pluginName, platformName, accessories) => {}
),
'on': mock.fn((event, listener) => {
return mockPlatform.api;
})
},
'log': {
'debug': mock.fn(() => {}),
'error': mock.fn(() => {}),
'info': mock.fn(() => {})
}
};
mockPlatform['accessoryManager'] = new PlatformAccessoryManager(mockPlatform);
class MockHomebridge {
characteristic = mockCharacteristic;
service = mockService;
platform = mockPlatform;
resetMocks() {
mockCharacteristic.on.mock.resetCalls();
mockCharacteristic.emit.mock.resetCalls();
mockService.setCharacteristic.mock.resetCalls();
mockService.getCharacteristic.mock.resetCalls();
mockPlatform.api.updatePlatformAccessories.mock.resetCalls();
mockPlatform.api.registerPlatformAccessories.mock.resetCalls();
mockPlatform.api.unregisterPlatformAccessories.mock.resetCalls();
mockPlatform.api.on.mock.resetCalls();
mockPlatform.log.debug.mock.resetCalls();
mockPlatform.log.error.mock.resetCalls();
mockPlatform.log.info.mock.resetCalls();
mockPlatform.accessories = [];
mockPlatform.lanDeviceIds = [];
}
}
module.exports = MockHomebridge;