UNPKG

homebridge-freeathome-local-api

Version:

Control your free@home setup using the local API provided by your System Access Point

117 lines 5.27 kB
import { FreeAtHomeAccessory } from "./freeAtHomeAccessory.js"; import { EmptyGuid, convertToString } from "./util.js"; /** * A shutter actuator accessory * @description * A shutter actuator can be used to control more or less any free@home device * that controls windows coverings. The rolling blind actuator, the attic window and * the awning actuator are also supported by this actuator. */ export class ShutterActuatorAccessory extends FreeAtHomeAccessory { platform; accessory; service; stateCurrentPosition; statePositionState; stateTargetPosition; stateObstructed; /** * Constructs a new Shutter Actuator accessory instance. * @param platform The free@home Homebridge platform controlling the accessory * @param accessory The platform accessory. */ constructor(platform, accessory) { super(platform, accessory); this.platform = platform; this.accessory = accessory; // set initial state this.stateCurrentPosition = 100 - parseInt(this.accessory.context.channel.outputs?.odp0001.value ?? "100"); this.statePositionState = this.getPositionState(this.accessory.context.channel.outputs?.odp0000.value); const targetPosition = this.accessory.context.channel.inputs?.idp0002.value; this.stateTargetPosition = targetPosition && this.statePositionState !== this.platform.Characteristic.PositionState.STOPPED ? 100 - parseInt(targetPosition) : this.stateCurrentPosition; this.stateObstructed = !!parseInt(this.accessory.context.channel.outputs?.odp0003.value ?? "0"); // get the Window Covering service if it exists, otherwise create a new service instance this.service = this.accessory.getService(this.platform.Service.WindowCovering) || this.accessory.addService(this.platform.Service.WindowCovering); // register handlers for the Current Position characteristic this.service .getCharacteristic(this.platform.Characteristic.CurrentPosition) .onGet(() => this.stateCurrentPosition) .setProps({ maxValue: 100, minValue: 0, minStep: 1, }); // register handlers for the Position State characteristic this.service .getCharacteristic(this.platform.Characteristic.PositionState) .onGet(() => this.statePositionState) .setProps({ validValues: [0, 1, 2], }); // register handlers for the Target Position characteristic this.service .getCharacteristic(this.platform.Characteristic.TargetPosition) .onGet(() => this.stateTargetPosition) .onSet(this.setTargetPosition.bind(this)) .setProps({ maxValue: 100, minValue: 0, minStep: 1, }); // register handlers for the Obstruction Detected characteristic this.service .getCharacteristic(this.platform.Characteristic.ObstructionDetected) .onGet(() => this.stateObstructed); } getPositionState(value) { switch (value) { case "2": return this.platform.Characteristic.PositionState.INCREASING; case "3": return this.platform.Characteristic.PositionState.DECREASING; default: return this.platform.Characteristic.PositionState.STOPPED; } } async setTargetPosition(value) { // avoid unneccessary updates or update value if (value == this.stateTargetPosition) return; else this.stateTargetPosition = value; // log event this.platform.log.info(`${this.accessory.displayName} (Shutter Actuator ${this.serialNumber}) set characteristic TargetPosition -> ${convertToString(value)}`); // set data point at SysAP await this.platform.sysap.setDatapoint(EmptyGuid, this.accessory.context.deviceSerial, this.accessory.context.channelId, "idp0002", convertToString(100 - this.stateTargetPosition)); } updateDatapoint(datapoint, value) { // ignore unknown data points switch (datapoint) { case "odp0000": this.statePositionState = this.getPositionState(value); // do the update this.doUpdateDatapoint("Shutter Actuator", this.service, this.platform.Characteristic.PositionState, this.statePositionState); return; case "odp0001": this.stateCurrentPosition = 100 - parseInt(value); this.doUpdateDatapoint("Shutter Actuator", this.service, this.platform.Characteristic.CurrentPosition, this.stateCurrentPosition); return; case "odp0003": this.stateObstructed = !!parseInt(value); this.doUpdateDatapoint("Shutter Actuator", this.service, this.platform.Characteristic.ObstructionDetected, this.stateObstructed); return; default: return; } } } //# sourceMappingURL=shutterActuatorAccessory.js.map