Merge branch 'master' of github.com:Foxi352/homebridge-smarthomeng

This commit is contained in:
Serge Wagener 2022-03-15 16:39:23 +01:00
commit 59fe9963a1
2 changed files with 37 additions and 7 deletions

View File

@ -141,9 +141,10 @@ 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:

View File

@ -1,3 +1,4 @@
import { Int16 } from 'hap-nodejs';
import { import {
AccessoryPlugin, AccessoryPlugin,
CharacteristicValue, CharacteristicValue,
@ -13,6 +14,7 @@ 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;
@ -22,14 +24,20 @@ 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);
} }
@ -52,8 +60,19 @@ export class Fan implements AccessoryPlugin {
this.platform.shng.setItem(this.accessory.active, this.active); this.platform.shng.setItem(this.accessory.active, this.active);
} }
shngCallback(value: unknown): void { getRotationSpeed(): Nullable<CharacteristicValue> {
this.platform.log.debug('shngCallback:', this.accessory.name, '=', value, '(' + typeof value + ')'); this.platform.log.info('getRotationSpeed:', this.accessory.name, 'is currently', this.rotationSpeed);
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);
@ -61,4 +80,14 @@ 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);
}
}
} }