-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Serge Wagener
committed
Feb 19, 2022
1 parent
de26802
commit a03b5f7
Showing
4 changed files
with
151 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters