Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae63f6cdee | ||
|
|
bbc42dfb7e | ||
|
|
c6f596e9e5 | ||
|
|
3561e0c3d6 | ||
|
|
447e0a68ef | ||
|
|
6f373379ae | ||
|
|
6b46c9cdb8 | ||
|
|
77df0609ca | ||
|
|
abe95f516f | ||
|
|
a3e7b85f17 | ||
|
|
ba2505853c | ||
|
|
e0611aed2c | ||
|
|
9a1709591f | ||
|
|
a03b5f787b | ||
|
|
de26802e1d |
No files matched your search
@@ -1,24 +1,33 @@
|
|||||||
# homebridge-smarthomeng
|
# homebridge-smarthomeng
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/homebridge-smarthomeng)
|
||||||
|
[](https://www.npmjs.com/package/homebridge-smarthomeng)
|
||||||
|
[](https://www.npmjs.com/package/homebridge-smarthomeng)
|
||||||
|
[](https://www.npmjs.com/package/homebridge-smarthomeng)
|
||||||
|
[](https://www.npmjs.com/package/homebridge-smarthomeng)
|
||||||
|
|
||||||
**Version v2 is a complete rewrite from scratch and a breaking update.**
|
**Version v2 is a complete rewrite from scratch and a breaking update.**
|
||||||
You need to adapt your `config.json` !
|
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):
|
||||||
|
|
||||||
| Type | Description |
|
| Type | Description |
|
||||||
|:----------------------------------------|:--------------------------------------------------------|
|
|:-----------------------------------------|:--------------------------------------------------------|
|
||||||
| ContactSensor | Simple contact sensor, for example for windows |
|
| [ContactSensor](#contact-sensor) | Simple contact sensor, for example for windows |
|
||||||
| [Doorbell](#doorbell) | Doorbell, sends message to devices on ring |
|
| [Doorbell](#doorbell) | Doorbell, sends message to devices on ring |
|
||||||
| [Fan](#fan) | Simple on/off fan, may be extended in future |
|
| [Fan](#fan) | Simple on/off fan, may be extended in future |
|
||||||
|
| [GarageDoor](#garage-door) | Garage door opener |
|
||||||
|
| [HumiditySensor](#humidity-sensor) | Humidity sensor |
|
||||||
| [Lightbulb](#lightbulb) | Everything, from simple light to dimmable, RGB and RGBW |
|
| [Lightbulb](#lightbulb) | Everything, from simple light to dimmable, RGB and RGBW |
|
||||||
| [MotionSensor](#motionsensor) | Detects and reports motion |
|
| [MotionSensor](#motion-sensor) | Detects and reports motion |
|
||||||
| [OccupancySensor](#occupancysensor) | Detects presence in a room |
|
| [OccupancySensor](#occupancy-sensor) | Detects presence in a room |
|
||||||
| [Outlet](#outlet) | Simple on/off wall outlet |
|
| [Outlet](#outlet) | Simple on/off wall outlet |
|
||||||
| [TemperatureSensor](#temperaturesensor) | Temperature sensor |
|
| [SecuritySystem](#security-system) | Intrusion alarm system |
|
||||||
| [Thermostat](#thermostat) | Thermostat with temperature sensor and heating state |
|
|
||||||
| [Switch](#switch) | Simple on/off switch |
|
| [Switch](#switch) | Simple on/off switch |
|
||||||
| [WindowCovering](#windowcovering) | Window covering (shutters, blinds, ...) |
|
| [TemperatureSensor](#temperature-sensor) | Temperature sensor |
|
||||||
|
| [Thermostat](#thermostat) | Thermostat with temperature sensor and heating state |
|
||||||
|
| [WindowCovering](#window-covering) | Window covering (shutters, blinds, ...) |
|
||||||
|
|
||||||
Other accessories are being worked on and will be added as soon as ready.
|
Other accessories are being worked on and will be added as soon as ready.
|
||||||
|
|
||||||
@@ -91,6 +100,25 @@ The following characteristics are valid for all accessories:
|
|||||||
"model": "Motion 360 KNX",
|
"model": "Motion 360 KNX",
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Contact sensor
|
||||||
|
This sensor shows the open / closed state of a contact (door, window, generic ...).
|
||||||
|
|
||||||
|
#### Characteristics in addition to [common characteristics](#common-accessories-characteristics)
|
||||||
|
| Parameter | Possible values | Mandatory | Description |
|
||||||
|
|:-------------|:----------------|:----------|:---------------------------------|
|
||||||
|
| ContactState | \<item> | Yes | SHNG item to monitor for contact |
|
||||||
|
|
||||||
|
|
||||||
|
#### Example:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "ContactSensor",
|
||||||
|
"name": "Window kitchen",
|
||||||
|
"ContactState": "EG.Kueche.Fenster"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Doorbell
|
### Doorbell
|
||||||
A doorbell is an accessory that simply sends a message to all devices enrolled in the home that someone rang the doorbell.
|
A doorbell is an accessory that simply sends a message to all devices enrolled in the home that someone rang the doorbell.
|
||||||
HomeKit displays a message that "This accessory is not currently supported by the Home app.".
|
HomeKit displays a message that "This accessory is not currently supported by the Home app.".
|
||||||
@@ -127,6 +155,60 @@ For now this accessory only supports turning the fan on and off. Further improve
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Garage Door
|
||||||
|
This accessory is used for opening/closing garage doors or any other automatic gate.
|
||||||
|
|
||||||
|
#### Characteristics in addition to [common characteristics](#common-accessories-characteristics)
|
||||||
|
| Parameter | Possible values | Mandatory | Default | Description |
|
||||||
|
|:---------------------------|:----------------|:----------|:--------|:------------------------------------------------------------------|
|
||||||
|
| CurrentDoorState | \<item> | Yes | | SHNG item to monitor the current door state |
|
||||||
|
| TargetDoorState | \<item> | Yes | | SHNG item to monitor and set the target position |
|
||||||
|
| ObstructionDetected | \<item> | No | | SHNG item to monitor if the door is blocked |
|
||||||
|
|
||||||
|
#### Additional comments
|
||||||
|
|
||||||
|
Valid values for 'CurrentDoorState':
|
||||||
|
* OPEN = 0
|
||||||
|
* CLOSED = 1
|
||||||
|
* OPENING = 2
|
||||||
|
* CLOSING = 3
|
||||||
|
* STOPPED = 4
|
||||||
|
|
||||||
|
Valid values for 'TargetDoorState':
|
||||||
|
* OPEN = 0
|
||||||
|
* CLOSED = 1
|
||||||
|
|
||||||
|
'ObstructionDetected' may be set 'true' if there is any physical problem opening/closing the door.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "GarageDoor",
|
||||||
|
"name": "GarageRechts",
|
||||||
|
"currentdoorstate": "garage.rechts.cds",
|
||||||
|
"targetdoorstate": "garage.rechts.tds",
|
||||||
|
"obstructiondetected": "garage.rechts.od"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Humidity sensor
|
||||||
|
This accessory shows the current relative humidity in %.
|
||||||
|
|
||||||
|
#### Characteristics in addition to [common characteristics](#common-accessories-characteristics)
|
||||||
|
| Parameter | Possible values | Mandatory | Description |
|
||||||
|
|:-------------------|:----------------|:----------|:-----------------------------------------------|
|
||||||
|
| CurrentHumidity | \<item> | Yes | SHNG item to monitor relative humidity in % |
|
||||||
|
|
||||||
|
|
||||||
|
#### Example:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "HumiditySensor",
|
||||||
|
"name": "Luftfeuchtigkeit Glashaus",
|
||||||
|
"CurrentHumidity": "Glashaus.Luftfeuchtigkeit"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### LightBulb
|
### LightBulb
|
||||||
Lightbulb can be as simple as a generic on/off light, but can also be as complex as a full RGBW led strip.
|
Lightbulb can be as simple as a generic on/off light, but can also be as complex as a full RGBW led strip.
|
||||||
|
|
||||||
@@ -179,6 +261,25 @@ The above optional min and max parameters allow you to specify the neede range f
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Motion sensor
|
||||||
|
This sensor is tripped if it detects motion in a room.
|
||||||
|
|
||||||
|
#### Characteristics in addition to [common characteristics](#common-accessories-characteristics)
|
||||||
|
| Parameter | Possible values | Mandatory | Description |
|
||||||
|
|:---------------|:----------------|:----------|:--------------------------------|
|
||||||
|
| MotionDetected | \<item> | Yes | SHNG item to monitor for motion |
|
||||||
|
|
||||||
|
|
||||||
|
#### Example:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "MotionSensor",
|
||||||
|
"name": "Movement hallway",
|
||||||
|
"MotionDetected": "EG.Flur.Bewegung"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Occupancy sensor
|
### Occupancy sensor
|
||||||
This sensor is tripped if it detects presence in a room.
|
This sensor is tripped if it detects presence in a room.
|
||||||
|
|
||||||
@@ -199,39 +300,55 @@ This sensor is tripped if it detects presence in a room.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Motion sensor
|
|
||||||
This sensor is tripped if it detects motion in a room.
|
### Outlet
|
||||||
|
This accessory can monitor and change the on/off state of a wall outlet. The outlet can be generic, a light, a fan, ...
|
||||||
|
|
||||||
#### 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 |
|
||||||
|:---------------|:----------------|:----------|:--------------------------------|
|
|:----------|:----------------|:----------|:-------------------------------------|
|
||||||
| MotionDetected | \<item> | Yes | SHNG item to monitor for motion |
|
| On | \<item> | Yes | SHNG item to switch outlet on or off |
|
||||||
|
|
||||||
|
|
||||||
#### Example:
|
#### Example:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "OccupancySensor",
|
"type": "Outlet",
|
||||||
"name": "Presence bathroom",
|
"name": "Christmas tree",
|
||||||
"OccupancyDetected": "EG.Flur.Bewegung"
|
"On": "EG.Esszimmer.Steckdose"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Contact sensor
|
### Security system
|
||||||
This sensor shows the open / closed state of a contact (door, window, generic ...).
|
This accessory can pilote your intrusion security system. That system can be a physical one operated via SHNG, or a SHNG native logic.
|
||||||
|
|
||||||
#### 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 |
|
||||||
|:-------------|:----------------|:----------|:---------------------------------|
|
|:-------------|:----------------|:----------|:-------------------------------------------------|
|
||||||
| ContactState | \<item> | Yes | SHNG item to monitor for contact |
|
| CurrentState | \<item> | Yes | SHNG item to monitor for the current alarm state |
|
||||||
|
| TargetState | \<item> | Yes | SHNG item to set or get the target state |
|
||||||
|
|
||||||
|
#### Additional comments
|
||||||
|
Valid values for 'CurrentState':
|
||||||
|
* STAY_ARM = 0
|
||||||
|
* AWAY_ARM = 1
|
||||||
|
* NIGHT_ARM = 2
|
||||||
|
* DISARMED = 3
|
||||||
|
* ALARM_TRIGGERED = 4
|
||||||
|
|
||||||
|
Valid values for 'TargetState':
|
||||||
|
* STAY_ARM = 0
|
||||||
|
* AWAY_ARM = 1
|
||||||
|
* NIGHT_ARM = 2
|
||||||
|
* DISARMED = 3
|
||||||
|
|
||||||
#### Example:
|
#### Example:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "ContactSensor",
|
"type": "SecuritySystem",
|
||||||
"name": "Window kitchen",
|
"name": "Intrusion alarm",
|
||||||
"ContactState": "EG.Kueche.Fenster"
|
"currentState": "Technik.Alarmanlage.Status.Ist",
|
||||||
|
"targetState": "Technik.Alarmanlage.Status.Soll"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -253,26 +370,8 @@ This accessory can monitor and change the on/off state of something. It is very
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Outlet
|
|
||||||
This accessory can monitor and change the on/off state of a wall outlet. The outlet can be generic, a light, a fan, ...
|
|
||||||
|
|
||||||
#### Characteristics in addition to [common characteristics](#common-accessories-characteristics)
|
|
||||||
| Parameter | Possible values | Mandatory | Description |
|
|
||||||
|:----------|:----------------|:----------|:-------------------------------------|
|
|
||||||
| On | \<item> | Yes | SHNG item to switch outlet on or off |
|
|
||||||
|
|
||||||
|
|
||||||
#### Example:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"type": "Outlet",
|
|
||||||
"name": "Christmas tree",
|
|
||||||
"On": "EG.Esszimmer.Steckdose"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Temperature sensor
|
### Temperature sensor
|
||||||
This sensor show the actual temperature.
|
This sensor shows the actual temperature.
|
||||||
|
|
||||||
#### 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 |
|
||||||
@@ -313,7 +412,7 @@ CurrentHeatingCoolingState = 0 for OFF, 1 for HEAT and 2 for COOL
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### WindowCovering
|
### Window covering
|
||||||
This accessory type can be used for shutters or blinds. Because the differnce between HomeKit and the controlling technology, for example KNX, can be significant this accessory has a lot of parameters. Luckily most are optional.
|
This accessory type can be used for shutters or blinds. Because the differnce between HomeKit and the controlling technology, for example KNX, can be significant this accessory has a lot of parameters. Luckily most are optional.
|
||||||
|
|
||||||
#### Characteristics in addition to [common characteristics](#common-accessories-characteristics)
|
#### Characteristics in addition to [common characteristics](#common-accessories-characteristics)
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "homebridge-smarthomeng",
|
"name": "homebridge-smarthomeng",
|
||||||
"version": "2.0.0",
|
"version": "2.0.4",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "homebridge-smarthomeng",
|
"name": "homebridge-smarthomeng",
|
||||||
"version": "2.0.0",
|
"version": "2.0.4",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ws": "^8.4.2"
|
"ws": "^8.4.2"
|
||||||
|
|||||||
+4
-4
@@ -2,15 +2,15 @@
|
|||||||
"private": false,
|
"private": false,
|
||||||
"displayName": "SmartHomeNG",
|
"displayName": "SmartHomeNG",
|
||||||
"name": "homebridge-smarthomeng",
|
"name": "homebridge-smarthomeng",
|
||||||
"version": "2.0.1",
|
"version": "2.0.4",
|
||||||
"description": "A short description about what your plugin does.",
|
"description": "SmartHomeNG plugin for Homebridge",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/Foxi352/homebridge-smarthomeng2.git"
|
"url": "git://github.com/Foxi352/homebridge-smarthomeng.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/Foxi352/homebridge-smarthomeng2/issues"
|
"url": "https://github.com/Foxi352/homebridge-smarthomeng/issues"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.18.1",
|
"node": ">=14.18.1",
|
||||||
|
|||||||
@@ -0,0 +1,135 @@
|
|||||||
|
import {
|
||||||
|
AccessoryPlugin,
|
||||||
|
CharacteristicValue,
|
||||||
|
Service,
|
||||||
|
Nullable,
|
||||||
|
} from 'homebridge';
|
||||||
|
|
||||||
|
import { SmartHomeNGPlatform } from '../platform';
|
||||||
|
|
||||||
|
export class GarageDoor implements AccessoryPlugin {
|
||||||
|
private readonly deviceService: Service;
|
||||||
|
private readonly informationService: Service;
|
||||||
|
|
||||||
|
public name: string;
|
||||||
|
private targetDoorState = this.platform.Characteristic.CurrentDoorState.CLOSED;
|
||||||
|
private currentDoorState = this.platform.Characteristic.CurrentDoorState.STOPPED;
|
||||||
|
private obstructionDetected = false;
|
||||||
|
|
||||||
|
constructor(private readonly platform: SmartHomeNGPlatform, private readonly accessory) {
|
||||||
|
this.name = accessory.name;
|
||||||
|
this.deviceService = new this.platform.Service.GarageDoorOpener(accessory.name);
|
||||||
|
|
||||||
|
// create handlers for required characteristics
|
||||||
|
|
||||||
|
this.informationService =
|
||||||
|
new this.platform.Service.AccessoryInformation()
|
||||||
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, accessory.manufacturer)
|
||||||
|
.setCharacteristic(this.platform.Characteristic.Model, accessory.model)
|
||||||
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.currentdoorstate); // FIXME
|
||||||
|
|
||||||
|
if (accessory.currentdoorstate) {
|
||||||
|
this.platform.shng.addMonitor(accessory.currentdoorstate, this.shngCurrentDoorStateCallback.bind(this));
|
||||||
|
this.deviceService.getCharacteristic(this.platform.Characteristic.CurrentDoorState)
|
||||||
|
.onGet(this.getCurrentDoorState.bind(this))
|
||||||
|
.onSet(this.setCurrentDoorState.bind(this));
|
||||||
|
} else {
|
||||||
|
this.platform.log.error('GarageDoor: missing \"currentdoorstate\" in config.json!');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accessory.targetdoorstate) {
|
||||||
|
this.platform.shng.addMonitor(accessory.targetdoorstate, this.shngTargetDoorStateCallback.bind(this));
|
||||||
|
this.deviceService.getCharacteristic(this.platform.Characteristic.TargetDoorState)
|
||||||
|
.onGet(this.getTargetDoorState.bind(this))
|
||||||
|
.onSet(this.setTargetDoorState.bind(this));
|
||||||
|
} else {
|
||||||
|
this.platform.log.error('GarageDoor: missing \"targetdoorstate\" in config.json!');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accessory.obstructiondetected) {
|
||||||
|
this.platform.shng.addMonitor(accessory.obstructiondetected, this.shngObstructionDetectedCallback.bind(this));
|
||||||
|
this.deviceService.getCharacteristic(this.platform.Characteristic.ObstructionDetected)
|
||||||
|
.onGet(this.getObstructionDetected.bind(this))
|
||||||
|
.onSet(this.setObstructionDetected.bind(this));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.platform.log.info("GarageDoor '%s' created!", accessory.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
identify(): void {
|
||||||
|
this.platform.log.info('Identify!');
|
||||||
|
}
|
||||||
|
|
||||||
|
getServices(): Service[] {
|
||||||
|
return [this.informationService, this.deviceService];
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentDoorState(): Nullable<CharacteristicValue> {
|
||||||
|
//getCurrentDoorState(value: CharacteristicValue) {
|
||||||
|
// this.currentDoorState = value as number;
|
||||||
|
this.platform.log.info('getCurrentDoorState:', this.accessory.name, 'is currently', this.currentDoorState);
|
||||||
|
return this.currentDoorState;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentDoorState(value: CharacteristicValue) {
|
||||||
|
this.currentDoorState = value as number;
|
||||||
|
this.platform.log.info('setCurrentDoorState:', this.accessory.name, 'was set to', this.currentDoorState);
|
||||||
|
this.platform.shng.setItem(this.accessory.currentdoorstate, this.currentDoorState);
|
||||||
|
}
|
||||||
|
|
||||||
|
getTargetDoorState(): Nullable<CharacteristicValue> {
|
||||||
|
//getTargetDoorState(value: CharacteristicValue) {
|
||||||
|
// this.targetDoorState = value as number;
|
||||||
|
this.platform.log.info('getTargetDoorState:', this.accessory.name, 'is currently', this.targetDoorState);
|
||||||
|
return this.targetDoorState;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTargetDoorState(value: CharacteristicValue) {
|
||||||
|
this.targetDoorState = value as number;
|
||||||
|
this.platform.log.info('setTargetDoorState:', this.accessory.name, 'was set to', this.targetDoorState);
|
||||||
|
this.platform.shng.setItem(this.accessory.targetdoorstate, this.targetDoorState);
|
||||||
|
}
|
||||||
|
|
||||||
|
getObstructionDetected(): Nullable<CharacteristicValue> {
|
||||||
|
this.platform.log.info('getObstructionDetected:', this.accessory.name, 'is currently', this.obstructionDetected);
|
||||||
|
return this.obstructionDetected;
|
||||||
|
}
|
||||||
|
|
||||||
|
setObstructionDetected(value: CharacteristicValue) {
|
||||||
|
this.obstructionDetected = value as boolean;
|
||||||
|
this.platform.log.info('setObstructionDetected:', this.accessory.name, 'was set to', this.obstructionDetected);
|
||||||
|
this.platform.shng.setItem(this.accessory.obstructiondetected, this.obstructionDetected);
|
||||||
|
}
|
||||||
|
|
||||||
|
shngCurrentDoorStateCallback(value: unknown): void {
|
||||||
|
this.platform.log.debug('shngCurrentDoorStateCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
this.currentDoorState = value;
|
||||||
|
this.deviceService.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, this.currentDoorState);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shngTargetDoorStateCallback(value: unknown): void {
|
||||||
|
this.platform.log.debug('shngTargetDoorStateCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
this.targetDoorState = value;
|
||||||
|
this.deviceService.updateCharacteristic(this.platform.Characteristic.TargetDoorState, this.targetDoorState);
|
||||||
|
} else {
|
||||||
|
this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shngObstructionDetectedCallback(value: unknown): void {
|
||||||
|
this.platform.log.debug('shngObstructionDetectedCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
|
||||||
|
if (typeof value === 'boolean') {
|
||||||
|
this.obstructionDetected = value;
|
||||||
|
this.deviceService.updateCharacteristic(this.platform.Characteristic.ObstructionDetected, this.obstructionDetected);
|
||||||
|
} else {
|
||||||
|
this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import {
|
||||||
|
AccessoryPlugin,
|
||||||
|
CharacteristicValue,
|
||||||
|
Service,
|
||||||
|
Nullable,
|
||||||
|
} from 'homebridge';
|
||||||
|
|
||||||
|
import { SmartHomeNGPlatform } from '../platform';
|
||||||
|
|
||||||
|
export class HumiditySensor implements AccessoryPlugin {
|
||||||
|
private readonly deviceService: Service;
|
||||||
|
private readonly informationService: Service;
|
||||||
|
|
||||||
|
public name: string;
|
||||||
|
private currentHumidity = 0;
|
||||||
|
|
||||||
|
constructor(private readonly platform: SmartHomeNGPlatform, private readonly accessory) {
|
||||||
|
this.name = accessory.name;
|
||||||
|
this.deviceService = new this.platform.Service.HumiditySensor(accessory.name);
|
||||||
|
|
||||||
|
// create handlers for required characteristics
|
||||||
|
this.deviceService.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
|
||||||
|
.onGet(this.getCurrentHumidity.bind(this));
|
||||||
|
|
||||||
|
this.informationService =
|
||||||
|
new this.platform.Service.AccessoryInformation()
|
||||||
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, accessory.manufacturer)
|
||||||
|
.setCharacteristic(this.platform.Characteristic.Model, accessory.model)
|
||||||
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.currenthumidity);
|
||||||
|
|
||||||
|
this.platform.shng.addMonitor(accessory.currenthumidity, this.shngCallback.bind(this));
|
||||||
|
this.platform.log.info('HumiditySensor', accessory.name, 'created!');
|
||||||
|
}
|
||||||
|
|
||||||
|
identify(): void {
|
||||||
|
this.platform.log.info('Identify!');
|
||||||
|
}
|
||||||
|
|
||||||
|
getServices(): Service[] {
|
||||||
|
return [this.informationService, this.deviceService];
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentHumidity(): Nullable<CharacteristicValue> {
|
||||||
|
this.platform.log.debug('getCurrentHumidity:', this.accessory.name, '=', this.currentHumidity);
|
||||||
|
return this.currentHumidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
shngCallback(value: unknown): void {
|
||||||
|
this.platform.log.debug('shngCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
this.currentHumidity = value;
|
||||||
|
} else {
|
||||||
|
this.platform.log.warn('Unknown type', typeof value, 'received for', this.accessory.name + ':', value);
|
||||||
|
}
|
||||||
|
this.deviceService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.currentHumidity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import {
|
||||||
|
AccessoryPlugin,
|
||||||
|
CharacteristicValue,
|
||||||
|
Service,
|
||||||
|
Nullable,
|
||||||
|
} from 'homebridge';
|
||||||
|
|
||||||
|
import { SmartHomeNGPlatform } from '../platform';
|
||||||
|
|
||||||
|
export class SecuritySystem implements AccessoryPlugin {
|
||||||
|
private readonly deviceService: Service;
|
||||||
|
private readonly informationService: Service;
|
||||||
|
|
||||||
|
public name: string;
|
||||||
|
private currentState = this.platform.Characteristic.SecuritySystemCurrentState.DISARMED;
|
||||||
|
private targetState = this.platform.Characteristic.SecuritySystemTargetState.DISARM;
|
||||||
|
|
||||||
|
constructor(private readonly platform: SmartHomeNGPlatform, private readonly accessory) {
|
||||||
|
this.name = accessory.name;
|
||||||
|
this.deviceService = new this.platform.Service.SecuritySystem(accessory.name);
|
||||||
|
|
||||||
|
|
||||||
|
// create handlers for required characteristics
|
||||||
|
this.deviceService.getCharacteristic(this.platform.Characteristic.SecuritySystemCurrentState)
|
||||||
|
.onGet(this.handleSecuritySystemCurrentStateGet.bind(this));
|
||||||
|
|
||||||
|
this.deviceService.getCharacteristic(this.platform.Characteristic.SecuritySystemTargetState)
|
||||||
|
.onGet(this.handleSecuritySystemTargetStateGet.bind(this))
|
||||||
|
.onSet(this.handleSecuritySystemTargetStateSet.bind(this));
|
||||||
|
|
||||||
|
this.informationService =
|
||||||
|
new this.platform.Service.AccessoryInformation()
|
||||||
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, accessory.manufacturer)
|
||||||
|
.setCharacteristic(this.platform.Characteristic.Model, accessory.model)
|
||||||
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.currentstate);
|
||||||
|
|
||||||
|
this.platform.shng.addMonitor(accessory.currentstate, this.shngCurrentStateCallback.bind(this));
|
||||||
|
this.platform.shng.addMonitor(accessory.targetState, this.shngTargetStateCallback.bind(this));
|
||||||
|
this.platform.log.info('SecuritySystem', accessory.name, 'created!');
|
||||||
|
}
|
||||||
|
|
||||||
|
identify(): void {
|
||||||
|
this.platform.log.info('Identify!');
|
||||||
|
}
|
||||||
|
|
||||||
|
getServices(): Service[] {
|
||||||
|
return [this.informationService, this.deviceService];
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSecuritySystemCurrentStateGet(): Nullable<CharacteristicValue> {
|
||||||
|
this.platform.log.info(
|
||||||
|
'handleSecuritySystemCurrentStateGet:',
|
||||||
|
this.accessory.name, '=',
|
||||||
|
this.currentState,
|
||||||
|
);
|
||||||
|
return this.currentState;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSecuritySystemTargetStateGet(): Nullable<CharacteristicValue> {
|
||||||
|
this.platform.log.info(
|
||||||
|
'handleSecuritySystemTargetStateGet:', this.accessory.name,
|
||||||
|
'is currently', this.targetState,
|
||||||
|
);
|
||||||
|
return this.targetState;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSecuritySystemTargetStateSet(value: CharacteristicValue) {
|
||||||
|
this.targetState = value as number;
|
||||||
|
this.platform.log.info('handleSecuritySystemTargetStateSet:', this.accessory.name, 'was set to', this.targetState);
|
||||||
|
this.platform.shng.setItem(this.accessory.targetstate, this.targetState);
|
||||||
|
}
|
||||||
|
|
||||||
|
shngCurrentStateCallback(value: unknown): void {
|
||||||
|
this.platform.log.debug('shngCurrentStateCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
this.currentState = value;
|
||||||
|
this.deviceService.updateCharacteristic(this.platform.Characteristic.SecuritySystemCurrentState, this.currentState);
|
||||||
|
} else {
|
||||||
|
this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shngTargetStateCallback(value: unknown): void {
|
||||||
|
this.platform.log.debug('shngTargetStateCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
this.targetState = value;
|
||||||
|
this.deviceService.updateCharacteristic(this.platform.Characteristic.SecuritySystemTargetState, this.targetState);
|
||||||
|
} else {
|
||||||
|
this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ export class Doorbell implements AccessoryPlugin {
|
|||||||
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.singlepress);
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.singlepress);
|
||||||
|
|
||||||
this.platform.shng.addMonitor(accessory.contactstate, this.shngCallback.bind(this));
|
this.platform.shng.addMonitor(accessory.contactstate, this.shngCallback.bind(this));
|
||||||
this.platform.log.info('ContactSensor', accessory.name, 'created!');
|
this.platform.log.info('Doorbell', accessory.name, 'created!');
|
||||||
}
|
}
|
||||||
|
|
||||||
identify(): void {
|
identify(): void {
|
||||||
|
|||||||
+21
-3
@@ -9,8 +9,6 @@ import {
|
|||||||
} from 'homebridge';
|
} from 'homebridge';
|
||||||
import { SmartHomeNG } from './SmartHomeNG';
|
import { SmartHomeNG } from './SmartHomeNG';
|
||||||
|
|
||||||
import { OccupancySensor } from './Accessories/OccupancySensor';
|
|
||||||
import { MotionSensor } from './Accessories/MotionSensor';
|
|
||||||
import { Switch } from './Accessories/Switch';
|
import { Switch } from './Accessories/Switch';
|
||||||
import { Outlet } from './Accessories/Outlet';
|
import { Outlet } from './Accessories/Outlet';
|
||||||
import { Fan } from './Accessories/Fan';
|
import { Fan } from './Accessories/Fan';
|
||||||
@@ -20,6 +18,11 @@ import { Thermostat } from './Accessories/Thermostat';
|
|||||||
import { WindowCovering } from './Accessories/WindowCovering';
|
import { WindowCovering } from './Accessories/WindowCovering';
|
||||||
import { ContactSensor } from './Accessories/ContactSensor';
|
import { ContactSensor } from './Accessories/ContactSensor';
|
||||||
import { Doorbell } from './Accessories/Doorbell';
|
import { Doorbell } from './Accessories/Doorbell';
|
||||||
|
import { SecuritySystem } from './Accessories/SecuritySystem';
|
||||||
|
import { OccupancySensor } from './Accessories/OccupancySensor';
|
||||||
|
import { MotionSensor } from './Accessories/MotionSensor';
|
||||||
|
import { GarageDoor } from './Accessories/GarageDoor';
|
||||||
|
import { HumiditySensor } from './Accessories/HumiditySensor';
|
||||||
|
|
||||||
function uncapitalizeKeys(obj): Record<string, unknown> {
|
function uncapitalizeKeys(obj): Record<string, unknown> {
|
||||||
function isObject(o: unknown): boolean {
|
function isObject(o: unknown): boolean {
|
||||||
@@ -105,6 +108,11 @@ export class SmartHomeNGPlatform implements StaticPlatformPlugin {
|
|||||||
devices.push(new Doorbell(this, accessory));
|
devices.push(new Doorbell(this, accessory));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Security system
|
||||||
|
case 'securitysystem':
|
||||||
|
devices.push(new SecuritySystem(this, accessory));
|
||||||
|
break;
|
||||||
|
|
||||||
// Switch
|
// Switch
|
||||||
case 'switch':
|
case 'switch':
|
||||||
devices.push(new Switch(this, accessory));
|
devices.push(new Switch(this, accessory));
|
||||||
@@ -125,7 +133,7 @@ export class SmartHomeNGPlatform implements StaticPlatformPlugin {
|
|||||||
devices.push(new Fan(this, accessory));
|
devices.push(new Fan(this, accessory));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// TemperatureSensor
|
// Temperature sensor
|
||||||
case 'temperaturesensor':
|
case 'temperaturesensor':
|
||||||
devices.push(new TemperatureSensor(this, accessory));
|
devices.push(new TemperatureSensor(this, accessory));
|
||||||
break;
|
break;
|
||||||
@@ -140,6 +148,16 @@ export class SmartHomeNGPlatform implements StaticPlatformPlugin {
|
|||||||
devices.push(new WindowCovering(this, accessory));
|
devices.push(new WindowCovering(this, accessory));
|
||||||
break;
|
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
|
// Show error for (yet ?) unsupported device
|
||||||
default:
|
default:
|
||||||
this.log.warn('Accessory type', accessory.type, 'for', accessory.name, 'not recognized !');
|
this.log.warn('Accessory type', accessory.type, 'for', accessory.name, 'not recognized !');
|
||||||
|
|||||||
Reference in new issue
Block a user