-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes and Fakegato history support (#35)
* Add fakegato * Typo * Fix fakegato config * Fix fakegato config 2 Irrigation in use * Init fakegato immediately * Fix enhanced blind position update * FakeGato fixes * Only present power meter service * Some refactoring about HAP types * Add power meter aservice * Don't use outlet * Try to fix power meter service init * Fix service definition * Use HAP PowerManagement Service * Use getCharacteristic * Remove update * No power meter service * Add log * Remove unused imports * Use hap as dependency * Expose new service * Add get callback * Another try * Expose EVE characteristic through outlet service
- Loading branch information
1 parent
0f6bdea
commit 8e0e13f
Showing
11 changed files
with
716 additions
and
208 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,78 @@ | ||
import { BlindDeviceData, ComelitClient, ObjectStatus } from 'comelit-client'; | ||
import { ComelitPlatform } from '../comelit-platform'; | ||
import { Callback, PlatformAccessory } from 'homebridge'; | ||
import { PositionState } from './hap'; | ||
import { Blind } from './blind'; | ||
|
||
/** | ||
* Returns the position as a value between 0 and 255 | ||
* @param position number 0-100 | ||
*/ | ||
function getPositionAsByte(position: number) { | ||
return Math.round(position * 2.55); | ||
} | ||
|
||
/** | ||
* Returns the position as a value between 0 and 100 | ||
* @param position number 0-255 | ||
*/ | ||
function getPositionAsPerc(position: string) { | ||
return Math.round(parseInt(position) / 2.55); | ||
} | ||
|
||
export class EnhancedBlind extends Blind { | ||
constructor(platform: ComelitPlatform, accessory: PlatformAccessory, client: ComelitClient) { | ||
super(platform, accessory, client); | ||
} | ||
|
||
public async setPosition(position: number, callback: Callback) { | ||
const Characteristic = this.platform.Characteristic; | ||
try { | ||
const currentPosition = this.coveringService.getCharacteristic(Characteristic.CurrentPosition) | ||
.value as number; | ||
this.log.info(`Setting position to ${position}%. Current position is ${currentPosition}`); | ||
this.coveringService.setCharacteristic( | ||
Characteristic.PositionState, | ||
position > currentPosition ? PositionState.INCREASING : PositionState.DECREASING | ||
); | ||
await this.client.setBlindPosition(this.device.id, getPositionAsByte(position)); | ||
callback(); | ||
} catch (e) { | ||
this.log.error(e.message); | ||
callback(e); | ||
} | ||
} | ||
|
||
public update(data: BlindDeviceData) { | ||
const Characteristic = this.platform.Characteristic; | ||
const position = getPositionAsPerc(data.position); | ||
const status = parseInt(data.status); // can be 1 (increasing), 2 (decreasing) or 0 (stopped) | ||
switch (status) { | ||
case ObjectStatus.ON: | ||
this.positionState = PositionState.INCREASING; | ||
break; | ||
case ObjectStatus.OFF: { | ||
this.log.info( | ||
`Blind is now at position ${position} (it was ${ | ||
this.positionState === PositionState.DECREASING ? 'closing' : 'opening' | ||
})` | ||
); | ||
this.positionState = PositionState.STOPPED; | ||
this.coveringService.getCharacteristic(Characteristic.TargetPosition).updateValue(position); | ||
this.coveringService | ||
.getCharacteristic(Characteristic.CurrentPosition) | ||
.updateValue(position); | ||
break; | ||
} | ||
case ObjectStatus.IDLE: | ||
this.positionState = PositionState.DECREASING; | ||
break; | ||
} | ||
|
||
this.coveringService | ||
.getCharacteristic(Characteristic.PositionState) | ||
.updateValue(this.positionState); | ||
this.coveringService.getCharacteristic(Characteristic.TargetPosition).updateValue(position); | ||
this.coveringService.getCharacteristic(Characteristic.CurrentPosition).updateValue(position); | ||
} | ||
} |
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
Oops, something went wrong.