homebridge#PlatformConfig TypeScript Examples
The following examples show how to use
homebridge#PlatformConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: platform.ts From homebridge-plugin-eufy-security with Apache License 2.0 | 6 votes |
constructor(
public readonly log: Logger,
config: PlatformConfig,
public readonly api: API,
) {
this.config = config as EufyPlatformConfig;
// this.log.debug('Config', this.config);
this.log.debug('Finished initializing platform:', this.config.platform);
this.httpService = new HttpService(this.config.username, this.config.password);
// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
// to start discovery of new accessories.
this.api.on('didFinishLaunching', async () => {
if (this.config.enablePush) {
this.log.info('push client enabled');
await this.setupPushClient();
} else {
this.log.info('push client disabled');
}
log.debug('Executed didFinishLaunching callback');
// run the method to discover / register your devices as accessories
try {
this.discoverDevices();
} catch(error) {
this.log.error('error while discovering devices');
this.log.error(error);
}
});
}
Example #2
Source File: platform.ts From homebridge-lg-thinq-ac with Apache License 2.0 | 6 votes |
constructor(
public readonly log: Logger,
public readonly config: PlatformConfig & HomebridgeLgThinqPlatformConfig,
public readonly api: API,
) {
this.didFinishLaunching = new Promise((resolve) => {
// Store the resolver locally.
// Steps that depend on this can `await didFinishLaunching`.
// When Homebridge is finishes launching, this will be called to resolve.
this.handleFinishedLaunching = resolve
})
this.log.debug('Finished initializing platform:', this.config.name)
this.initialize()
// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
// to start discovery of new accessories.
this.api.on(APIEvent.DID_FINISH_LAUNCHING, () => {
this.log.debug('Executed didFinishLaunching callback')
if (this.handleFinishedLaunching) {
this.handleFinishedLaunching()
}
})
}
Example #3
Source File: platform.ts From homebridge-screenlogic with MIT License | 6 votes |
constructor(public readonly log: Logger, config: PlatformConfig, public readonly api: API) {
this.log.debug('Finished initializing platform', PLATFORM_NAME)
this.config = config as ScreenLogicPlatformConfig
// do this first to make sure we have proper defaults moving forward
this.applyConfigDefaults(config)
this.controller = new Controller({
log: this.log,
ip_address: this.config.ip_address,
port: this.config.port,
username: this.config.username,
password: this.config.password,
})
// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
// to start discovery of new accessories.
this.api.on('didFinishLaunching', () => {
log.debug('Executed didFinishLaunching callback')
// run the method to discover / register your devices as accessories
this.discoverDevices(0)
})
}
Example #4
Source File: platform.ts From homebridge-screenlogic with MIT License | 6 votes |
private applyConfigDefaults(config: PlatformConfig) {
// config.ip_address
config.port = config.port ?? 80
// config.username
// config.password
// config.hidden_circuits
config.hideAirTemperatureSensor = config.hideAirTemperatureSensor ?? false
config.hidePoolTemperatureSensor = config.hidePoolTemperatureSensor ?? false
config.hideSpaTemperatureSensor = config.hideSpaTemperatureSensor ?? false
config.hidePoolThermostat = config.hidePoolThermostat ?? false
config.hideSpaThermostat = config.hideSpaThermostat ?? false
config.statusPollingSeconds = config.statusPollingSeconds ?? 60
config.createLightColorSwitches = config.createLightColorSwitches ?? false
config.disabledLightColors = config.disabledLightColors ?? []
this.log.debug('config', this.config)
}
Example #5
Source File: platform.ts From homebridge-tuya-ir with Apache License 2.0 | 6 votes |
constructor(
public readonly log: Logger,
public readonly config: PlatformConfig,
public readonly api: API,
) {
this.log.debug('Finished initializing platform:', this.config.name);
// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
// to start discovery of new accessories.
this.api.on('didFinishLaunching', () => {
log.debug('Executed didFinishLaunching callback');
// run the method to discover / register your devices as accessories
this.discoverDevices();
});
}
Example #6
Source File: platform.ts From homebridge-konnected with MIT License | 6 votes |
constructor(public readonly log: Logger, public readonly config: PlatformConfig, public readonly api: API) {
this.log.debug('Finished initializing platform');
// Homebridge looks for and fires this event when it has retrieved all cached accessories from disk
// this event is also used to init other methods for this plugin
this.api.on('didFinishLaunching', () => {
log.debug('Executed didFinishLaunching callback. Accessories retreived from cache...');
// run the listening server & register the security system
this.listeningServer();
this.registerSecuritySystem();
this.discoverPanels();
});
}
Example #7
Source File: wled-platform.ts From homebridge-simple-wled with ISC License | 6 votes |
constructor(log: Logging, config: PlatformConfig, api: API) {
this.api = api;
this.config = config;
this.log = log;
if (!config) {
return;
}
if (!config.wleds) {
this.log("No WLEDs have been configured.");
return;
}
api.on(APIEvent.DID_FINISH_LAUNCHING, this.launchWLEDs.bind(this));
}
Example #8
Source File: platform.ts From homebridge-plugin-template with Apache License 2.0 | 6 votes |
constructor(
public readonly log: Logger,
public readonly config: PlatformConfig,
public readonly api: API,
) {
this.log.debug('Finished initializing platform:', this.config.name);
// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
// to start discovery of new accessories.
this.api.on('didFinishLaunching', () => {
log.debug('Executed didFinishLaunching callback');
// run the method to discover / register your devices as accessories
this.discoverDevices();
});
}
Example #9
Source File: platform.ts From homebridge-iRobot with Apache License 2.0 | 6 votes |
constructor(
public readonly log: Logger,
public readonly config: PlatformConfig,
public readonly api: API,
) {
this.log.debug('Finished initializing platform:', this.config.name);
// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
// to start discovery of new accessories.
this.api.on('didFinishLaunching', () => {
log.debug('Executed didFinishLaunching callback');
// run the method to discover / register your devices as accessories
this.discoverDevices();
});
}
Example #10
Source File: platform.ts From homebridge-iRobot with Apache License 2.0 | 6 votes |
constructor(
public readonly log: Logger,
public readonly config: PlatformConfig,
public readonly api: API,
) {
this.log.debug('Finished initializing platform:', this.config.name);
// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
// to start discovery of new accessories.
this.api.on('didFinishLaunching', () => {
log.debug('Executed didFinishLaunching callback');
// run the method to discover / register your devices as accessories
this.discoverDevices();
});
}
Example #11
Source File: platform.ts From homebridge-vieramatic with Apache License 2.0 | 6 votes |
constructor(
readonly log: Logger,
private readonly config: PlatformConfig,
private readonly api: API
) {
this.storage = new Storage(api)
this.Characteristic = this.api.hap.Characteristic
this.Service = this.api.hap.Service
this.log.debug('Finished initializing platform:', this.config.platform)
this.api.on('didFinishLaunching', async () => {
log.debug('Executed didFinishLaunching callback')
await this.discoverDevices()
})
}
Example #12
Source File: platform.ts From homebridge-plugin-govee with Apache License 2.0 | 6 votes |
constructor(
public readonly log: Logger,
public readonly config: PlatformConfig,
public readonly api: API
) {
this.log.info("Finished initializing platform:", this.config.name);
// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
// to start discovery of new accessories.
this.api.on("didFinishLaunching", () => {
log.debug("Executed didFinishLaunching callback");
// run the method to discover / register your devices as accessories
this.platformStatus = APIEvent.DID_FINISH_LAUNCHING;
this.discoverDevices();
});
this.api.on("shutdown", () => {
this.platformStatus = APIEvent.SHUTDOWN;
});
}
Example #13
Source File: index.ts From homebridge-fordpass with GNU General Public License v3.0 | 6 votes |
constructor(log: Logging, config: PlatformConfig, api: API) {
this.log = log;
this.api = api;
this.config = config as FordpassConfig;
// Need a config or plugin will not start
if (!config) {
return;
}
if (!config.username || !config.password) {
this.log.error('Please add a userame and password to your config.json');
return;
}
api.on(APIEvent.DID_FINISH_LAUNCHING, this.didFinishLaunching.bind(this));
}
Example #14
Source File: accessory.ts From homebridge-nest-cam with GNU General Public License v3.0 | 6 votes |
constructor(accessory: PlatformAccessory, camera: NestCam, config: PlatformConfig, log: Logging, hap: HAP) {
this.accessory = accessory;
this.camera = camera;
this.config = config;
this.log = log;
this.hap = hap;
// Setup events
camera.on(NestCamEvents.CAMERA_STATE_CHANGED, (value: boolean) => {
const service = this.accessory.getService(`${this.accessory.displayName} Streaming`);
service && service.updateCharacteristic(this.hap.Characteristic.On, value);
});
camera.on(NestCamEvents.CHIME_STATE_CHANGED, (value: boolean) => {
const service = this.accessory.getService(`${this.accessory.displayName} Chime`);
service && service.updateCharacteristic(this.hap.Characteristic.On, value);
});
camera.on(NestCamEvents.CHIME_ASSIST_STATE_CHANGED, (value: boolean) => {
const service = this.accessory.getService(`${this.accessory.displayName} Announcements`);
service && service.updateCharacteristic(this.hap.Characteristic.On, value);
});
camera.on(NestCamEvents.AUDIO_STATE_CHANGED, (value: boolean) => {
const service = this.accessory.getService(`${this.accessory.displayName} Audio`);
service && service.updateCharacteristic(this.hap.Characteristic.On, value);
});
camera.on(NestCamEvents.MOTION_DETECTED, (state: boolean, alertTypes: Array<string>) => {
this.setMotion(state, alertTypes);
});
camera.on(NestCamEvents.DOORBELL_RANG, () => {
this.setDoorbell();
});
}
Example #15
Source File: platform.ts From homebridge-tapo-p100 with Apache License 2.0 | 6 votes |
constructor(
public readonly log: Logger,
config: PlatformConfig,
public readonly api: API,
) {
this.log.debug('config.json: %j', config);
this.config = parseConfig(config);
this.log.debug('config: %j', this.config);
this.log.debug('Finished initializing platform:', this.config.name);
this.customCharacteristics = Characteristics(api.hap.Characteristic);
this.FakeGatoHistoryService = fakegato(this.api);
// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
// to start discovery of new accessories.
this.api.on('didFinishLaunching', () => {
log.debug('Executed didFinishLaunching callback');
// run the method to discover / register your devices as accessories
this.discoverDevices();
});
}
Example #16
Source File: index.ts From homebridge-nest-cam with GNU General Public License v3.0 | 6 votes |
constructor(log: Logging, config: PlatformConfig, api: API) {
this.log = log;
this.api = api;
this.config = config as NestConfig;
this.options = new Options();
// Need a config or plugin will not start
if (!config) {
return;
}
this.initDefaultOptions();
api.on(APIEvent.DID_FINISH_LAUNCHING, this.didFinishLaunching.bind(this));
api.on(APIEvent.SHUTDOWN, this.isShuttingDown.bind(this));
}
Example #17
Source File: platform.ts From HomebridgeMagicHome-DynamicPlatform with Apache License 2.0 | 6 votes |
constructor(
public readonly hbLogger: Logger,
public readonly config: PlatformConfig,
public readonly api: API,
) {
if (this.config.advancedOptions.logLevel) {
this.logs = new Logs(hbLogger, this.config.advancedOptions.logLevel);
} else {
this.logs = new Logs(hbLogger);
}
//this.logs = getLogger();
this.logs.warn('Finished initializing homebridge-magichome-dynamic-platform %o', loadJson<any>(join(__dirname, '../package.json'), {}).version);
this.logs.info('If this plugin brings you joy, consider visiting GitHub and giving it a ⭐.');
// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
// to start discovery of new accessories.
this.api.on(APIEvent.DID_FINISH_LAUNCHING, () => {
this.logs.debug('Executed didFinishLaunching callback');
this.count = 1;
// run the method to discover / register your devices as accessories
this.discoverDevices(true);
// Periodic scan for devices
const shouldRediscover = this.config.advancedOptions?.periodicDiscovery ?? false;
if (shouldRediscover) {
this.periodicDiscovery = setInterval(() => this.discoverDevices(false), 30000);
}
});
}
Example #18
Source File: Transport.ts From HomebridgeMagicHome-DynamicPlatform with Apache License 2.0 | 6 votes |
/**
* @param {string} host - hostname
* @param {number} timeout - connection timeout (in seconds)
*/
constructor(host: any, public readonly config: PlatformConfig) {
this.host = host;
this.socket = null;
this.queue = new Queue(1, Infinity); // 1 concurrent, infinite size
}
Example #19
Source File: index.ts From homebridge-philips-air with BSD 2-Clause "Simplified" License | 6 votes |
constructor(log: Logging, config: PlatformConfig, api: API) {
this.log = log;
this.config = config as unknown as PhilipsAirPlatformConfig;
this.api = api;
this.timeout = (this.config.timeout_seconds || 5) * 1000;
api.on(APIEvent.DID_FINISH_LAUNCHING, this.didFinishLaunching.bind(this));
}
Example #20
Source File: Discover.ts From HomebridgeMagicHome-DynamicPlatform with Apache License 2.0 | 5 votes |
constructor(
public readonly logs: Logs,
private readonly config: PlatformConfig,
) { }
Example #21
Source File: accessory.ts From homebridge-nest-cam with GNU General Public License v3.0 | 5 votes |
private config: PlatformConfig;
Example #22
Source File: platform.ts From homebridge-eufy-security with Apache License 2.0 | 5 votes |
constructor(
public readonly hblog: Logger,
config: PlatformConfig,
public readonly api: API,
) {
this.config = config as EufySecurityPlatformConfig;
this.eufyConfig = {
username: this.config.username,
password: this.config.password,
country: 'US',
language: 'en',
persistentDir: api.user.storagePath(),
p2pConnectionSetup: 0,
pollingIntervalMinutes: this.config.pollingIntervalMinutes ?? 10,
eventDurationSeconds: 10,
} as EufySecurityConfig;
this.config.ignoreStations = this.config.ignoreStations || [];
this.config.ignoreDevices = this.config.ignoreDevices || [];
if (this.config.enableDetailedLogging >= 1) {
const plugin = require('../package.json');
this.log = bunyan.createLogger({
name: '[EufySecurity-' + plugin.version + ']',
hostname: '',
streams: [{
level: (this.config.enableDetailedLogging === 2) ? 'trace' : 'debug',
type: 'raw',
stream: bunyanDebugStream({
forceColor: true,
showProcess: false,
showPid: false,
showDate: (time) => {
return '[' + time.toLocaleString('en-US') + ']';
},
}),
}],
serializers: bunyanDebugStream.serializers,
});
this.log.info('Eufy Security Plugin: enableDetailedLogging on');
} else {
this.log = hblog;
}
this.eufyClient = (this.config.enableDetailedLogging === 2)
? new EufySecurity(this.eufyConfig, this.log)
: new EufySecurity(this.eufyConfig);
// Removing the ability to set Off(6) waiting Bropat feedback bropat/eufy-security-client#27
this.config.hkOff = (this.config.hkOff === 6) ? 63 : this.config.hkOff;
// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
// to start discovery of new accessories.
this.api.on('didFinishLaunching', async () => {
// await this.createConnection();
// run the method to discover / register your devices as accessories
await this.discoverDevices();
});
this.log.info('Finished initializing Eufy Security Platform');
}
Example #23
Source File: platform.d.ts From homebridge-tuya-ir with Apache License 2.0 | 5 votes |
readonly config: PlatformConfig;
Example #24
Source File: platform.d.ts From homebridge-tuya-ir with Apache License 2.0 | 5 votes |
constructor(log: Logger, config: PlatformConfig, api: API);
Example #25
Source File: platform.ts From homebridge-samsungtv-control2 with MIT License | 5 votes |
constructor(
public readonly log: Logger,
public readonly config: PlatformConfig,
public readonly api: API,
) {
this.log = log
this.config = config
this.api = api
this.Service = api.hap.Service
this.Characteristic = api.hap.Characteristic
this.log.debug(`Got config`, this.config)
// Add devices
api.on(APIEvent.DID_FINISH_LAUNCHING, async () => {
const dir = path.join(api.user.storagePath(), `.${PLUGIN_NAME}`)
this.log.debug(`Using node-persist path:`, dir)
await storage.init({
dir,
logging: (...args) => this.log.debug(`${PLATFORM_NAME} db -`, ...args),
})
let devices = await this.discoverDevices()
devices = await this.applyConfig(devices)
this.devices = await this.checkDevicePairing(devices)
// Register all TV's
for (const device of this.devices) {
// Log all devices so that the user knows how to configure them
this.log.info(
chalk`Found device {blue ${device.name}} (${device.modelName}), usn: {green ${device.usn}}`,
)
this.log.debug(
`${device.name} - (ip: ${device.lastKnownIp}, mac: ${device.mac})`,
)
// Register it
this.registerTV(device.usn)
}
// Regularly discover upnp devices and update ip's, locations for registered devices
setInterval(async () => {
const devices = await this.discoverDevices()
this.devices = await this.applyConfig(devices)
/**
* @todo
* add previously not registered devices
*/
}, 1000 * 60 * 5 /* 5min */)
/**
* @TODO
* Add subscriptions to update getters
*/
})
}
Example #26
Source File: wled-platform.ts From homebridge-simple-wled with ISC License | 5 votes |
readonly config: PlatformConfig;
Example #27
Source File: platform.d.ts From homebridge-plugin-govee with Apache License 2.0 | 5 votes |
readonly config: PlatformConfig;
Example #28
Source File: getRoombas.ts From homebridge-iRobot with Apache License 2.0 | 5 votes |
export function getRoombas(config: PlatformConfig, log: Logger): Promise<ConfiguredRoomba[]> {
let index = 0;
const badRoombas: string[] = [];
return new Promise((resolve, reject) => {
const robots: ConfiguredRoomba[] = [];
if (config.password !== undefined && config.email !== undefined) {
getiRobotDevices(config.email, config.password).then(devices => {
log.info('Succefully logged into iRobot');
for (const robot of devices) {
log.debug('Configuring device:', JSON.stringify(robot));
getDeviceCredentials(robot.blid).then(credentials => {
log.debug('Configured Device:', JSON.stringify(credentials));
robots.push(Object.assign(robot, credentials));
}).catch((error) => {
log.warn('Failed To Configure Device:', JSON.stringify(robot), '\nWith error:', error);
badRoombas.push(error);
}).finally(() => {
index++;
if (badRoombas.length === devices.length) {
reject(badRoombas.toString());
}
if (index === devices.length) {
resolve(robots);
}
});
}
}).catch(error => {
reject(error);
});
} else {
for (const robot of config.roombas) {
if (robot.ip !== undefined) {
log.debug('Configuring device:', JSON.stringify(robot));
getDeviceCredentials(robot.blid, robot.ip).then(credentials => {
log.debug('Configured Device:', JSON.stringify(credentials));
robots.push(Object.assign(robot, credentials));
}).catch((error) => {
log.warn('Failed To Configure Device:', JSON.stringify(robot), '\nWith error:', error);
badRoombas.push(error);
}).finally(() => {
index++;
if (badRoombas.length === robots.length) {
reject(badRoombas.toString());
}
if (index === robots.length) {
resolve(robots);
}
});
} else {
log.debug('Configuring device:', JSON.stringify(robot));
getDeviceCredentials(robot.blid).then(credentials => {
log.debug('Configured Device:', JSON.stringify(credentials));
robots.push(Object.assign(robot, credentials));
}).catch((error) => {
log.warn('Failed To Configure Device:', JSON.stringify(robot), '\nWith error:', error);
badRoombas.push(error);
}).finally(() => {
index++;
if (badRoombas.length === robots.length) {
reject(badRoombas.toString());
}
if (index === robots.length) {
resolve(robots);
}
});
}
}
}
});
}
Example #29
Source File: getRoombas.ts From homebridge-iRobot with Apache License 2.0 | 5 votes |
export function getRoombas(email: string, password: string, log: Logger, config: PlatformConfig): Robot[] {
//child_process.execSync('chmod -R 755 "' + __dirname + '/scripts"');
let robots: Robot[] = [];
if(config.manualDiscovery){
log.info('Using manual discovery due to config');
robots = config.roombas || [];
}else{
log.info('Logging into iRobot...');
const Robots = child_process.execFileSync(__dirname + '/scripts/getRoombaCredentials.js', [email, password]).toString();
try{
robots = JSON.parse(Robots);
log.debug(Robots);
}catch(e){
log.error('Faild to login to iRobot, see below for details');
log.error(Robots);
}
}
const badRoombas: number[] = [];
robots.forEach(robot => {
if(robot.autoConfig || !config.autoDiscovery){
log.info('Configuring roomba:', robot.name);
const robotIP = child_process.execFileSync(__dirname + '/scripts/getRoombaIP.js', [robot.blid]).toString();
try{
const robotInfo = JSON.parse(robotIP);
log.debug(robotIP);
robot.ip = robotInfo.ip;
delete robotInfo.ip;
robot.model = getModel(robotInfo.sku);
robot.multiRoom = getMultiRoom(robot.model);
robot.info = robotInfo;
/*if(robotInfo.sku.startsWith('m6')){
badRoombas.push(robots.indexOf(robot));
}*/
}catch(e){
try{
log.error('Failed to configure roomba:', robot.name, 'see below for details');
log.error(robotIP);
} finally{
badRoombas.push(robots.indexOf(robot));
}
}
} else {
log.info('Skipping configuration for roomba:', robot.name, 'due to config');
}
});
for(const roomba of badRoombas){
log.warn('Disabling Unconfigured Roomba:', robots[roomba].name);
try{
robots.splice(roomba);
}catch(e){
log.error('Failed To Disable Unconfigured Roomba:', robots[roomba].name, 'see below for details');
log.error(e as string);
}
}
return robots;
}