Added SecuritySystem
This commit is contained in:
parent
de26802e1d
commit
a03b5f787b
62
README.md
62
README.md
@ -6,19 +6,20 @@ You need to adapt your `config.json` !
|
|||||||
## 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 |
|
||||||
| [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 |
|
| [TemperatureSensor](#temperature-sensor) | Temperature sensor |
|
||||||
| [WindowCovering](#windowcovering) | Window covering (shutters, blinds, ...) |
|
| [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.
|
||||||
|
|
||||||
@ -271,6 +272,39 @@ This accessory can monitor and change the on/off state of a wall outlet. The out
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Security system
|
||||||
|
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)
|
||||||
|
| Parameter | Possible values | Mandatory | Description |
|
||||||
|
|:-------------|:----------------|:----------|:-------------------------------------------------|
|
||||||
|
| 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:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "SecuritySystem",
|
||||||
|
"name": "Intrusion alarm",
|
||||||
|
"currentState": "Technik.Alarmanlage.Status.Ist",
|
||||||
|
"targetState": "Technik.Alarmanlage.Status.Soll"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Temperature sensor
|
### Temperature sensor
|
||||||
This sensor show the actual temperature.
|
This sensor show the actual temperature.
|
||||||
|
|
||||||
@ -313,7 +347,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)
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"private": false,
|
"private": false,
|
||||||
"displayName": "SmartHomeNG",
|
"displayName": "SmartHomeNG",
|
||||||
"name": "homebridge-smarthomeng",
|
"name": "homebridge-smarthomeng",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"description": "A short description about what your plugin does.",
|
"description": "A short description about what your plugin does.",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
94
src/Accessories/SecuritySystem.ts
Normal file
94
src/Accessories/SecuritySystem.ts
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -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,9 @@ 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';
|
||||||
|
|
||||||
function uncapitalizeKeys(obj): Record<string, unknown> {
|
function uncapitalizeKeys(obj): Record<string, unknown> {
|
||||||
function isObject(o: unknown): boolean {
|
function isObject(o: unknown): boolean {
|
||||||
@ -105,6 +106,11 @@ export class SmartHomeNGPlatform implements StaticPlatformPlugin {
|
|||||||
devices.push(new Doorbell(this, accessory));
|
devices.push(new Doorbell(this, accessory));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Doorbell
|
||||||
|
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));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user