homebridge-shortcuts-buttons
Version:
Run any Apple Shortcut with just the tap of a button, and execute a custom unix command (or another shortcut!) after completion to handle its success/failure, using x-callback-url.
56 lines • 2.41 kB
JavaScript
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
import { HSBAccessory, HSBDevice } from './accessory.js';
import { HSBXCallbackUrlServer } from './server/index.js';
import { HSBUtils } from './utils.js';
export class HSBPlatform {
log;
api;
config;
utils;
device;
accessory = null;
server = null;
constructor(log, _config, api) {
this.log = log;
this.api = api;
if (!log.success) {
log.success = log.info;
}
this.config = _config;
this.device = new HSBDevice(this.config);
this.utils = new HSBUtils(log);
this.log.info('Platform initialized:', this.config.name);
api.on('didFinishLaunching', () => {
log.debug('Platform::api.on(didFinishLaunching) callback');
if (this.config.callbackServerEnabled === true) {
this.server = new HSBXCallbackUrlServer(this.config, log, this.utils, api);
}
this.discoverDevices();
});
}
configureAccessory(accessory) {
this.log.debug('Platform::configureAccessory', `DisplayName=${accessory.displayName}`);
this.accessory = accessory;
}
discoverDevices() {
const uuid = this.api.hap.uuid.generate(this.device.serialNumber);
if (this.accessory?.UUID === uuid) {
if (this.accessory.displayName !== this.device.displayName) {
this.log.debug('Platform::discoverDevices', 'Update existing accessory display name to:', this.device.displayName);
this.accessory.displayName = this.device.displayName;
this.accessory.context.device = this.device;
this.api.updatePlatformAccessories([this.accessory]);
}
this.log.info('Platform::discoverDevices', 'Restored existing accessory from cache:', this.accessory.displayName);
}
else {
const accessory = new this.api.platformAccessory(this.device.displayName, uuid);
accessory.context.device = this.device;
this.accessory = accessory;
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [this.accessory]);
this.log.info('Platform::discoverDevices', 'Registered new accessory:', this.accessory.displayName);
}
new HSBAccessory(this, this.accessory);
}
}
//# sourceMappingURL=platform.js.map