Compare commits

..

No commits in common. "master" and "v2.0.4" have entirely different histories.

7 changed files with 2733 additions and 1647 deletions

View File

@ -1,12 +1,14 @@
# homebridge-smarthomeng # homebridge-smarthomeng
[![npm](https://badgen.net/npm/v/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng) [![npm](https://badgen.net/npm/v/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng)
[![verified-by-homebridge](https://badgen.net/badge/homebridge/verified/purple)](https://github.com/homebridge/homebridge/wiki/Verified-Plugins)
[![npm](https://badgen.net/badge/homebridge/>=1.3.5/green)](https://www.npmjs.com/package/homebridge-smarthomeng) [![npm](https://badgen.net/badge/homebridge/>=1.3.5/green)](https://www.npmjs.com/package/homebridge-smarthomeng)
[![npm](https://badgen.net/npm/node/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng) [![npm](https://badgen.net/npm/node/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng)
[![npm](https://badgen.net/npm/dt/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng) [![npm](https://badgen.net/npm/dt/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng)
[![npm](https://badgen.net/npm/dm/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng) [![npm](https://badgen.net/npm/dm/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng)
**Version v2 is a complete rewrite from scratch and a breaking update.**
You need to adapt your [`config.json`](#example-configuration-file) !
## Currently supported accessories ## Currently supported accessories
This plugin currently supports the following services (and characteristics): This plugin currently supports the following services (and characteristics):
@ -27,15 +29,32 @@ This plugin currently supports the following services (and characteristics):
| [Thermostat](#thermostat) | Thermostat with temperature sensor and heating state | | [Thermostat](#thermostat) | Thermostat with temperature sensor and heating state |
| [WindowCovering](#window-covering) | Window covering (shutters, blinds, ...) | | [WindowCovering](#window-covering) | Window covering (shutters, blinds, ...) |
Other accessories are being worked on and will be added as soon as ready.
## Requirements ## Requirements
* [SmartHomeNG](https://github.com/smarthomeNG/smarthome) * [SmartHomeNG](https://github.com/smarthomeNG/smarthome)
* [Node.js >=14.18.1](https://nodejs.org/en/) * [homebridge](https://www.npmjs.com/package/homebridge)
* [Homebridge](https://homebridge.io)
## Installation of plugin ## Installation
### Install nodejs >=14.18.1
See [NodeJS](https://nodejs.org/en/) website for details depending on your OS.
Use [Homebridge Config UI X](https://github.com/oznu/homebridge-config-ui-x#readme) or install manually using ```npm install -g homebridge-smarthomeng``` ### Install libavahi-compat-libdnssd-dev lib
For me i needed these libraries to be installed for my homebridge to work. See their [Homepage](https://homebridge.io) for installation instructions.
Below is what i did on my Debian Bullseye installation:
sudo apt install libavahi-compat-libdnssd-dev
### Install homebridge >=1.3.5 from NPM repository
npm install -g homebridge --unsafe-perm
### Install this plugin from NPM repository
npm install -g homebridge-smarthomeng --unsafe-perm
## Configuration ## Configuration
@ -44,13 +63,13 @@ If you already have a working homebridge installation just add the platform sect
### Platform configuration ### Platform configuration
The following parameters are available to configure the plugin as platform in homebridge. The following parameters are available to configure the plugin as platform in homebridge.
| Parameter | Possible values | Mandatory | Default | Description | | Parameter | Possible values | Mandatory | Description |
|:----------|:---------------------------------------|:----------|:--------|:------------------------------------| |:----------|:---------------------------------------|:----------|:----------------------------------------------------|
| platform | Any \<string> | Yes | | Internal name of your platform | | platform | Any \<string> | Yes | Internal name of your platform |
| name | Any \<string> | Yes | | Visible name in HomeKit | | name | Any \<string> | Yes | Visible name in HomeKit |
| host | IP address or FQDN of your SHNG server | Yes | | Your SHNG host | | host | IP address or FQDN of your SHNG server | Yes | Your SHNG host |
| port | Port \<number> | No | 2424 | Listening port of websocket module. | | port | Port \<number> | No | Listening port of websocket module. Default is 2424 |
| tls | \<boolean> | No | False | Should TLS encryption be used. | | tls | \<boolean> | No | Should TLS encryption be used. Defaults is 'false' |
#### Example configuration: #### Example configuration:
```json ```json
@ -122,10 +141,9 @@ Further investigation is needed, but for now it still works.
For now this accessory only supports turning the fan on and off. Further improvements are possible, but i don't have the needed hardware for testing. For now this accessory only supports turning the fan on and off. Further improvements are possible, but i don't have the needed hardware for testing.
#### Characteristics in addition to [common characteristics](#common-accessories-characteristics) #### Characteristics in addition to [common characteristics](#common-accessories-characteristics)
| Parameter | Possible values | Mandatory | Description | | Parameter | Possible values | Mandatory | Description |
|:--------------|:----------------|:----------|:------------------------------------------------| |:----------|:----------------|:----------|:---------------------------------------|
| Active | \<item> | Yes | SHNG item to set and get the fan state. | | Active | \<item> | Yes | SHNG item to set and get the fan state |
| RotationSpeed | \<item> | No | SHNG item to set and get the fan rotation speed |
#### Example: #### Example:
@ -141,11 +159,11 @@ For now this accessory only supports turning the fan on and off. Further improve
This accessory is used for opening/closing garage doors or any other automatic gate. This accessory is used for opening/closing garage doors or any other automatic gate.
#### Characteristics in addition to [common characteristics](#common-accessories-characteristics) #### Characteristics in addition to [common characteristics](#common-accessories-characteristics)
| Parameter | Possible values | Mandatory | Description | | Parameter | Possible values | Mandatory | Default | Description |
|:--------------------|:----------------|:----------|:------------------------------------------------------------------| |:---------------------------|:----------------|:----------|:--------|:------------------------------------------------------------------|
| CurrentDoorState | \<item> | Yes | SHNG item to monitor the current door state | | CurrentDoorState | \<item> | Yes | | SHNG item to monitor the current door state |
| TargetDoorState | \<item> | Yes | SHNG item to monitor and set the target position | | TargetDoorState | \<item> | Yes | | SHNG item to monitor and set the target position |
| ObstructionDetected | \<item> | No | SHNG item to monitor if the door is blocked | | ObstructionDetected | \<item> | No | | SHNG item to monitor if the door is blocked |
#### Additional comments #### Additional comments
@ -404,11 +422,9 @@ This accessory type can be used for shutters or blinds. Because the differnce be
| TargetPosition | \<item> | Yes | | SHNG item to monitor and set the target position | | TargetPosition | \<item> | Yes | | SHNG item to monitor and set the target position |
| CurrentPositionMin | \<number> | No | 0 | Your device's minimum value for current position | | CurrentPositionMin | \<number> | No | 0 | Your device's minimum value for current position |
| CurrentPositionMax | \<number> | No | 100 | Your device's maximum value for current position | | CurrentPositionMax | \<number> | No | 100 | Your device's maximum value for current position |
| CurrentPositionDecimals | \<number> | No | 0 | Number of decimals to round to |
| CurrentPositionInverted | \<boolean> | No | false | Should the values be inverted, ex: 0 for Homekit = 100 for device | | CurrentPositionInverted | \<boolean> | No | false | Should the values be inverted, ex: 0 for Homekit = 100 for device |
| TargetPositionMin | \<number> | No | 0 | Your device's minimum value for target position | | TargetPositionMin | \<number> | No | 0 | Your device's minimum value for target position |
| TargetPositionMax | \<number> | No | 100 | Your device's maximum value for target position | | TargetPositionMax | \<number> | No | 100 | Your device's maximum value for target position |
| TargetPositionDecimals | \<number> | No | 0 | Number of decimals to round to |
| TargetPositionInverted | \<boolean> | No | false | Should the values be inverted, ex: 0 for Homekit = 100 for device | | TargetPositionInverted | \<boolean> | No | false | Should the values be inverted, ex: 0 for Homekit = 100 for device |
| CurrentHorizontalTiltAngle | \<item> | No | | SHNG item to monitor current horizontal tilt angle | | CurrentHorizontalTiltAngle | \<item> | No | | SHNG item to monitor current horizontal tilt angle |
| TargetHorizontalTiltAngle | \<item> | No | | SHNG item to monitor and set the target horizontal tilt angle | | TargetHorizontalTiltAngle | \<item> | No | | SHNG item to monitor and set the target horizontal tilt angle |

4046
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
"private": false, "private": false,
"displayName": "SmartHomeNG", "displayName": "SmartHomeNG",
"name": "homebridge-smarthomeng", "name": "homebridge-smarthomeng",
"version": "2.0.8", "version": "2.0.4",
"description": "SmartHomeNG plugin for Homebridge", "description": "SmartHomeNG plugin for Homebridge",
"license": "Apache-2.0", "license": "Apache-2.0",
"repository": { "repository": {
@ -27,17 +27,17 @@
"homebridge-plugin" "homebridge-plugin"
], ],
"dependencies": { "dependencies": {
"ws": "^8.12.1" "ws": "^8.4.2"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^18.13.0", "@types/node": "^16.10.9",
"@typescript-eslint/eslint-plugin": "^5.52.0", "@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.52.0", "@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.34.0", "eslint": "^8.0.1",
"homebridge": "^1.6.0", "homebridge": "^1.3.5",
"nodemon": "^2.0.20", "nodemon": "^2.0.13",
"rimraf": "^4.1.2", "rimraf": "^3.0.2",
"ts-node": "^10.9.1", "ts-node": "^10.3.0",
"typescript": "^4.9.5" "typescript": "^4.4.4"
} }
} }

View File

@ -13,7 +13,6 @@ export class Fan implements AccessoryPlugin {
public name: string; public name: string;
private active = false; private active = false;
private rotationSpeed = 100;
constructor(private readonly platform: SmartHomeNGPlatform, private readonly accessory) { constructor(private readonly platform: SmartHomeNGPlatform, private readonly accessory) {
this.name = accessory.name; this.name = accessory.name;
@ -23,20 +22,14 @@ export class Fan implements AccessoryPlugin {
this.deviceService.getCharacteristic(this.platform.Characteristic.Active) this.deviceService.getCharacteristic(this.platform.Characteristic.Active)
.onGet(this.getActive.bind(this)) .onGet(this.getActive.bind(this))
.onSet(this.setActive.bind(this)); .onSet(this.setActive.bind(this));
this.platform.shng.addMonitor(accessory.active, this.shngActiveCallback.bind(this));
if (accessory.rotationspeed) {
this.deviceService.getCharacteristic(this.platform.Characteristic.RotationSpeed)
.onGet(this.getRotationSpeed.bind(this))
.onSet(this.setRotationSpeed.bind(this));
this.platform.shng.addMonitor(accessory.rotationspeed, this.shngRotationSpeedCallback.bind(this));
}
this.informationService = this.informationService =
new this.platform.Service.AccessoryInformation() new this.platform.Service.AccessoryInformation()
.setCharacteristic(this.platform.Characteristic.Manufacturer, accessory.manufacturer) .setCharacteristic(this.platform.Characteristic.Manufacturer, accessory.manufacturer)
.setCharacteristic(this.platform.Characteristic.Model, accessory.model) .setCharacteristic(this.platform.Characteristic.Model, accessory.model)
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.active); .setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.active);
this.platform.shng.addMonitor(accessory.active, this.shngCallback.bind(this));
this.platform.log.info("Fan '%s' created!", accessory.name); this.platform.log.info("Fan '%s' created!", accessory.name);
} }
@ -59,19 +52,8 @@ export class Fan implements AccessoryPlugin {
this.platform.shng.setItem(this.accessory.active, this.active); this.platform.shng.setItem(this.accessory.active, this.active);
} }
getRotationSpeed(): Nullable<CharacteristicValue> { shngCallback(value: unknown): void {
this.platform.log.info('getRotationSpeed:', this.accessory.name, 'is currently', this.rotationSpeed); this.platform.log.debug('shngCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
return this.rotationSpeed;
}
setRotationSpeed(value: CharacteristicValue) {
this.rotationSpeed = value as number;
this.platform.log.info('setRotationSpeed:', this.accessory.name, 'was set to', this.rotationSpeed);
this.platform.shng.setItem(this.accessory.rotationspeed, this.rotationSpeed);
}
shngActiveCallback(value: unknown): void {
this.platform.log.debug('shngActiveCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
if (typeof value === 'boolean') { if (typeof value === 'boolean') {
this.active = value; this.active = value;
this.deviceService.updateCharacteristic(this.platform.Characteristic.Active, this.active); this.deviceService.updateCharacteristic(this.platform.Characteristic.Active, this.active);
@ -79,14 +61,4 @@ export class Fan implements AccessoryPlugin {
this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value); this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value);
} }
} }
shngRotationSpeedCallback(value: unknown): void {
this.platform.log.debug('shngRotationSpeedCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
if (typeof value === 'number') {
this.rotationSpeed = value;
this.deviceService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.rotationSpeed);
} else {
this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value);
}
}
} }

View File

@ -21,11 +21,12 @@ export class GarageDoor implements AccessoryPlugin {
this.deviceService = new this.platform.Service.GarageDoorOpener(accessory.name); this.deviceService = new this.platform.Service.GarageDoorOpener(accessory.name);
// create handlers for required characteristics // create handlers for required characteristics
this.informationService = this.informationService =
new this.platform.Service.AccessoryInformation() new this.platform.Service.AccessoryInformation()
.setCharacteristic(this.platform.Characteristic.Manufacturer, accessory.manufacturer) .setCharacteristic(this.platform.Characteristic.Manufacturer, accessory.manufacturer)
.setCharacteristic(this.platform.Characteristic.Model, accessory.model) .setCharacteristic(this.platform.Characteristic.Model, accessory.model)
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.currentdoorstate); .setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.currentdoorstate); // FIXME
if (accessory.currentdoorstate) { if (accessory.currentdoorstate) {
this.platform.shng.addMonitor(accessory.currentdoorstate, this.shngCurrentDoorStateCallback.bind(this)); this.platform.shng.addMonitor(accessory.currentdoorstate, this.shngCurrentDoorStateCallback.bind(this));
@ -33,7 +34,7 @@ export class GarageDoor implements AccessoryPlugin {
.onGet(this.getCurrentDoorState.bind(this)) .onGet(this.getCurrentDoorState.bind(this))
.onSet(this.setCurrentDoorState.bind(this)); .onSet(this.setCurrentDoorState.bind(this));
} else { } else {
this.platform.log.error('GarageDoor: missing \"currentdoorstate\" in config.json!'); this.platform.log.error('GarageDoor: missing \"currentdoorstate\" in config.json!');
} }
if (accessory.targetdoorstate) { if (accessory.targetdoorstate) {
@ -42,7 +43,7 @@ export class GarageDoor implements AccessoryPlugin {
.onGet(this.getTargetDoorState.bind(this)) .onGet(this.getTargetDoorState.bind(this))
.onSet(this.setTargetDoorState.bind(this)); .onSet(this.setTargetDoorState.bind(this));
} else { } else {
this.platform.log.error('GarageDoor: missing \"targetdoorstate\" in config.json!'); this.platform.log.error('GarageDoor: missing \"targetdoorstate\" in config.json!');
} }
if (accessory.obstructiondetected) { if (accessory.obstructiondetected) {
@ -65,6 +66,8 @@ export class GarageDoor implements AccessoryPlugin {
} }
getCurrentDoorState(): Nullable<CharacteristicValue> { getCurrentDoorState(): Nullable<CharacteristicValue> {
//getCurrentDoorState(value: CharacteristicValue) {
// this.currentDoorState = value as number;
this.platform.log.info('getCurrentDoorState:', this.accessory.name, 'is currently', this.currentDoorState); this.platform.log.info('getCurrentDoorState:', this.accessory.name, 'is currently', this.currentDoorState);
return this.currentDoorState; return this.currentDoorState;
} }
@ -76,6 +79,8 @@ export class GarageDoor implements AccessoryPlugin {
} }
getTargetDoorState(): Nullable<CharacteristicValue> { getTargetDoorState(): Nullable<CharacteristicValue> {
//getTargetDoorState(value: CharacteristicValue) {
// this.targetDoorState = value as number;
this.platform.log.info('getTargetDoorState:', this.accessory.name, 'is currently', this.targetDoorState); this.platform.log.info('getTargetDoorState:', this.accessory.name, 'is currently', this.targetDoorState);
return this.targetDoorState; return this.targetDoorState;
} }

View File

@ -12,10 +12,8 @@ export class WindowCovering implements AccessoryPlugin {
private readonly informationService: Service; private readonly informationService: Service;
public name: string; public name: string;
private currentPosition = 0; private currentPositionMin = 0; private currentPositionMax = 100; private currentPosition = 0; private currentPositionMin = 0; private currentPositionMax = 100; private currentPositionInverted = false;
private currentPositionDecimals = 0; private currentPositionInverted = false; private targetPosition = 0; private targetPositionMin = 0; private targetPositionMax = 100; private targetPositionInverted = false;
private targetPosition = 0; private targetPositionMin = 0; private targetPositionMax = 100;
private targetPositionDecimals = 0; private targetPositionInverted = false;
private positionState = this.platform.Characteristic.PositionState.STOPPED; private positionState = this.platform.Characteristic.PositionState.STOPPED;
private currentHorizontalTiltAngle = 0; private targetHorizontalTiltAngle = 0; private currentHorizontalTiltAngle = 0; private targetHorizontalTiltAngle = 0;
private currentVerticalTiltAngle = 0; private targetVerticalTiltAngle = 0; private currentVerticalTiltAngle = 0; private targetVerticalTiltAngle = 0;
@ -72,11 +70,9 @@ export class WindowCovering implements AccessoryPlugin {
this.currentPositionMax = accessory.currentpositionmax ? accessory.currentpositionmax : this.currentPositionMax; this.currentPositionMax = accessory.currentpositionmax ? accessory.currentpositionmax : this.currentPositionMax;
this.currentPositionMin = accessory.currentpositionmin ? accessory.currentpositionmin : this.currentPositionMin; this.currentPositionMin = accessory.currentpositionmin ? accessory.currentpositionmin : this.currentPositionMin;
this.currentPositionDecimals = accessory.currentpositiondecimals ? accessory.currentpositiondecimals : this.currentPositionDecimals;
this.currentPositionInverted = accessory.currentpositioninverted ? accessory.currentpositioninverted : this.currentPositionInverted; this.currentPositionInverted = accessory.currentpositioninverted ? accessory.currentpositioninverted : this.currentPositionInverted;
this.targetPositionMax = accessory.targetpositionmax ? accessory.targetpositionmax : this.targetPositionMax; this.targetPositionMax = accessory.targetpositionmax ? accessory.targetpositionmax : this.targetPositionMax;
this.targetPositionMin = accessory.targetpositionmin ? accessory.targetpositionmin : this.targetPositionMin; this.targetPositionMin = accessory.targetpositionmin ? accessory.targetpositionmin : this.targetPositionMin;
this.targetPositionDecimals = accessory.targetpositiondecimals ? accessory.targetpositiondecimals : this.targetPositionDecimals;
this.targetPositionInverted = accessory.targetpositioninverted ? accessory.targetpositioninverted : this.targetPositionInverted; this.targetPositionInverted = accessory.targetpositioninverted ? accessory.targetpositioninverted : this.targetPositionInverted;
this.platform.log.info("WindowCovering '%s' created!", accessory.name); this.platform.log.info("WindowCovering '%s' created!", accessory.name);
} }
@ -111,7 +107,7 @@ export class WindowCovering implements AccessoryPlugin {
value as number, value as number,
0, 100, 0, 100,
this.targetPositionMin, this.targetPositionMax, this.targetPositionMin, this.targetPositionMax,
this.targetPositionDecimals, this.targetPositionInverted, this.targetPositionInverted,
); );
this.platform.shng.setItem(this.accessory.targetposition, transposedTarget); this.platform.shng.setItem(this.accessory.targetposition, transposedTarget);
} }
@ -156,7 +152,7 @@ export class WindowCovering implements AccessoryPlugin {
value as number, value as number,
this.currentPositionMin, this.currentPositionMax, this.currentPositionMin, this.currentPositionMax,
0, 100, 0, 100,
0, this.currentPositionInverted, this.currentPositionInverted,
); );
this.deviceService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.currentPosition); this.deviceService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.currentPosition);
} else { } else {
@ -173,7 +169,7 @@ export class WindowCovering implements AccessoryPlugin {
value as number, value as number,
this.targetPositionMin, this.targetPositionMax, this.targetPositionMin, this.targetPositionMax,
0, 100, 0, 100,
0, this.targetPositionInverted, this.targetPositionInverted,
); );
this.deviceService.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.targetPosition); this.deviceService.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.targetPosition);
} else { } else {
@ -239,14 +235,9 @@ export class WindowCovering implements AccessoryPlugin {
); );
} }
// eslint-disable-next-line max-len convertRange(value: number, oldmin: number, oldmax: number, newmin: number, newmax: number, inverted: boolean): number {
convertRange(value: number, oldmin: number, oldmax: number, newmin: number, newmax: number, decimals: number, inverted: boolean): number {
let result = (((value - oldmin) * (newmax - newmin)) / (oldmax - oldmin)) + newmin; let result = (((value - oldmin) * (newmax - newmin)) / (oldmax - oldmin)) + newmin;
if(decimals > 0) { result = Math.round(result);
result = parseFloat(result.toFixed(decimals));
} else {
result = Math.round(result);
}
if (inverted) { if (inverted) {
result = newmax - result; result = newmax - result;
} }
@ -255,7 +246,6 @@ export class WindowCovering implements AccessoryPlugin {
'from range', oldmin, '-', oldmax, 'from range', oldmin, '-', oldmax,
'to', newmin, '-', newmax, 'to', newmin, '-', newmax,
'with inverted', inverted, 'with inverted', inverted,
'and', decimals, 'decimals',
'=', result, '=', result,
); );
return result; return result;

View File

@ -75,100 +75,97 @@ 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);
if (Object.keys(accessories).length > 0) {
for (const accessory of accessories) {
if (!accessory.manufacturer) {
accessory.manufacturer = 'SmartHomeNG';
}
if (!accessory.model) {
accessory.model = 'SHNG Item';
}
if (accessory.type !== '') { for (const accessory of accessories) {
this.log.info('Parsing accessory:', accessory.name, 'of type', accessory.type); if (!accessory.manufacturer) {
// set lo lowercase to ignore user case errors accessory.manufacturer = 'SmartHomeNG';
switch (accessory.type.toLowerCase()) { }
if (!accessory.model) {
// Presence sensor accessory.model = 'SHNG Item';
case 'occupancysensor':
devices.push(new OccupancySensor(this, accessory));
break;
// Motion sensor
case 'motionsensor':
devices.push(new MotionSensor(this, accessory));
break;
// Contact sensor
case 'contactsensor':
devices.push(new ContactSensor(this, accessory));
break;
// Doorbell
case 'doorbell':
devices.push(new Doorbell(this, accessory));
break;
// Security system
case 'securitysystem':
devices.push(new SecuritySystem(this, accessory));
break;
// Switch
case 'switch':
devices.push(new Switch(this, accessory));
break;
// Lightbulb
case 'lightbulb':
devices.push(new Lightbulb(this, accessory));
break;
// Outlet
case 'outlet':
devices.push(new Outlet(this, accessory));
break;
// Fan (uses Fanv2)
case 'fan':
devices.push(new Fan(this, accessory));
break;
// Temperature sensor
case 'temperaturesensor':
devices.push(new TemperatureSensor(this, accessory));
break;
// Thermostat
case 'thermostat':
devices.push(new Thermostat(this, accessory));
break;
// WindowCovering
case 'windowcovering':
devices.push(new WindowCovering(this, accessory));
break;
// Garage door
case 'garagedoor':
devices.push(new GarageDoor(this, accessory));
break;
// Humidity sensor
case 'humiditysensor':
devices.push(new HumiditySensor(this, accessory));
break;
// Show error for (yet ?) unsupported device
default:
this.log.warn('Accessory type', accessory.type, 'for', accessory.name, 'not recognized !');
break;
}
} else {
this.log.warn('Ignoring accessory (no type given): ' + accessory);
}
} }
if (accessory.type !== '') {
this.log.info('Parsing accessory:', accessory.name, 'of type', accessory.type);
// set lo lowercase to ignore user case errors
switch (accessory.type.toLowerCase()) {
// Presence sensor
case 'occupancysensor':
devices.push(new OccupancySensor(this, accessory));
break;
// Motion sensor
case 'motionsensor':
devices.push(new MotionSensor(this, accessory));
break;
// Contact sensor
case 'contactsensor':
devices.push(new ContactSensor(this, accessory));
break;
// Doorbell
case 'doorbell':
devices.push(new Doorbell(this, accessory));
break;
// Security system
case 'securitysystem':
devices.push(new SecuritySystem(this, accessory));
break;
// Switch
case 'switch':
devices.push(new Switch(this, accessory));
break;
// Lightbulb
case 'lightbulb':
devices.push(new Lightbulb(this, accessory));
break;
// Outlet
case 'outlet':
devices.push(new Outlet(this, accessory));
break;
// Fan (uses Fanv2)
case 'fan':
devices.push(new Fan(this, accessory));
break;
// Temperature sensor
case 'temperaturesensor':
devices.push(new TemperatureSensor(this, accessory));
break;
// Thermostat
case 'thermostat':
devices.push(new Thermostat(this, accessory));
break;
// WindowCovering
case 'windowcovering':
devices.push(new WindowCovering(this, accessory));
break;
// Garage door
case 'garagedoor':
devices.push(new GarageDoor(this, accessory));
break;
// Humidity sensor
case 'humiditysensor':
devices.push(new HumiditySensor(this, accessory));
break;
// Show error for (yet ?) unsupported device
default:
this.log.warn('Accessory type', accessory.type, 'for', accessory.name, 'not recognized !');
break;
}
} 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');