Added check for empty accessories list
This commit is contained in:
parent
c8d117a894
commit
d07d621e45
181
src/platform.ts
181
src/platform.ts
@ -75,97 +75,100 @@ export class SmartHomeNGPlatform implements StaticPlatformPlugin {
|
|||||||
|
|
||||||
// convert all configured accessory keys to lowercase to tolerate user case errors
|
// convert all configured accessory keys to lowercase to tolerate user case errors
|
||||||
const accessories = JSON.parse(JSON.stringify(uncapitalizeKeys(this.config.accessories)));
|
const accessories = JSON.parse(JSON.stringify(uncapitalizeKeys(this.config.accessories)));
|
||||||
|
this.log.debug(accessories);
|
||||||
for (const accessory of accessories) {
|
if (Object.keys(accessories).length > 0) {
|
||||||
if (!accessory.manufacturer) {
|
for (const accessory of accessories) {
|
||||||
accessory.manufacturer = 'SmartHomeNG';
|
if (!accessory.manufacturer) {
|
||||||
}
|
accessory.manufacturer = 'SmartHomeNG';
|
||||||
if (!accessory.model) {
|
}
|
||||||
accessory.model = 'SHNG Item';
|
if (!accessory.model) {
|
||||||
}
|
accessory.model = 'SHNG Item';
|
||||||
|
}
|
||||||
if (accessory.type !== '') {
|
|
||||||
this.log.info('Parsing accessory:', accessory.name, 'of type', accessory.type);
|
if (accessory.type !== '') {
|
||||||
// set lo lowercase to ignore user case errors
|
this.log.info('Parsing accessory:', accessory.name, 'of type', accessory.type);
|
||||||
switch (accessory.type.toLowerCase()) {
|
// set lo lowercase to ignore user case errors
|
||||||
|
switch (accessory.type.toLowerCase()) {
|
||||||
// Presence sensor
|
|
||||||
case 'occupancysensor':
|
// Presence sensor
|
||||||
devices.push(new OccupancySensor(this, accessory));
|
case 'occupancysensor':
|
||||||
break;
|
devices.push(new OccupancySensor(this, accessory));
|
||||||
// Motion sensor
|
break;
|
||||||
case 'motionsensor':
|
// Motion sensor
|
||||||
devices.push(new MotionSensor(this, accessory));
|
case 'motionsensor':
|
||||||
break;
|
devices.push(new MotionSensor(this, accessory));
|
||||||
|
break;
|
||||||
// Contact sensor
|
|
||||||
case 'contactsensor':
|
// Contact sensor
|
||||||
devices.push(new ContactSensor(this, accessory));
|
case 'contactsensor':
|
||||||
break;
|
devices.push(new ContactSensor(this, accessory));
|
||||||
|
break;
|
||||||
// Doorbell
|
|
||||||
case 'doorbell':
|
// Doorbell
|
||||||
devices.push(new Doorbell(this, accessory));
|
case 'doorbell':
|
||||||
break;
|
devices.push(new Doorbell(this, accessory));
|
||||||
|
break;
|
||||||
// Security system
|
|
||||||
case 'securitysystem':
|
// Security system
|
||||||
devices.push(new SecuritySystem(this, accessory));
|
case 'securitysystem':
|
||||||
break;
|
devices.push(new SecuritySystem(this, accessory));
|
||||||
|
break;
|
||||||
// Switch
|
|
||||||
case 'switch':
|
// Switch
|
||||||
devices.push(new Switch(this, accessory));
|
case 'switch':
|
||||||
break;
|
devices.push(new Switch(this, accessory));
|
||||||
|
break;
|
||||||
// Lightbulb
|
|
||||||
case 'lightbulb':
|
// Lightbulb
|
||||||
devices.push(new Lightbulb(this, accessory));
|
case 'lightbulb':
|
||||||
break;
|
devices.push(new Lightbulb(this, accessory));
|
||||||
|
break;
|
||||||
// Outlet
|
|
||||||
case 'outlet':
|
// Outlet
|
||||||
devices.push(new Outlet(this, accessory));
|
case 'outlet':
|
||||||
break;
|
devices.push(new Outlet(this, accessory));
|
||||||
|
break;
|
||||||
// Fan (uses Fanv2)
|
|
||||||
case 'fan':
|
// Fan (uses Fanv2)
|
||||||
devices.push(new Fan(this, accessory));
|
case 'fan':
|
||||||
break;
|
devices.push(new Fan(this, accessory));
|
||||||
|
break;
|
||||||
// Temperature sensor
|
|
||||||
case 'temperaturesensor':
|
// Temperature sensor
|
||||||
devices.push(new TemperatureSensor(this, accessory));
|
case 'temperaturesensor':
|
||||||
break;
|
devices.push(new TemperatureSensor(this, accessory));
|
||||||
|
break;
|
||||||
// Thermostat
|
|
||||||
case 'thermostat':
|
// Thermostat
|
||||||
devices.push(new Thermostat(this, accessory));
|
case 'thermostat':
|
||||||
break;
|
devices.push(new Thermostat(this, accessory));
|
||||||
|
break;
|
||||||
// WindowCovering
|
|
||||||
case 'windowcovering':
|
// WindowCovering
|
||||||
devices.push(new WindowCovering(this, accessory));
|
case 'windowcovering':
|
||||||
break;
|
devices.push(new WindowCovering(this, accessory));
|
||||||
|
break;
|
||||||
// Garage door
|
|
||||||
case 'garagedoor':
|
// Garage door
|
||||||
devices.push(new GarageDoor(this, accessory));
|
case 'garagedoor':
|
||||||
break;
|
devices.push(new GarageDoor(this, accessory));
|
||||||
|
break;
|
||||||
// Humidity sensor
|
|
||||||
case 'humiditysensor':
|
// Humidity sensor
|
||||||
devices.push(new HumiditySensor(this, accessory));
|
case 'humiditysensor':
|
||||||
break;
|
devices.push(new HumiditySensor(this, accessory));
|
||||||
|
break;
|
||||||
// Show error for (yet ?) unsupported device
|
|
||||||
default:
|
// Show error for (yet ?) unsupported device
|
||||||
this.log.warn('Accessory type', accessory.type, 'for', accessory.name, 'not recognized !');
|
default:
|
||||||
break;
|
this.log.warn('Accessory type', accessory.type, 'for', accessory.name, 'not recognized !');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.log.warn('Ignoring accessory (no type given): ' + accessory);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
this.log.warn('Ignoring accessory (no type given): ' + accessory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
callback(devices);
|
callback(devices);
|
||||||
this.log.debug('Finished building accessories list');
|
this.log.debug('Finished building accessories list');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user