Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fan rotation direction support. #94

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/accessory/FanAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default class FanAccessory extends BaseAccessory {
this.configureRotationSpeedOn();
}

this.configureRotationDirection();

this.configureLightOn();
this.configureLightBrightness();
}
Expand Down Expand Up @@ -54,6 +56,10 @@ export default class FanAccessory extends BaseAccessory {
return undefined;
}

getFanDirection() {
return this.getSchema('fan_direction');
}

getLightOnSchema() {
return this.getSchema('light')
|| this.getSchema('switch_led');
Expand All @@ -66,16 +72,21 @@ export default class FanAccessory extends BaseAccessory {

configureActive() {
const schema = this.getFanActiveSchema()!;
if (!schema) {
return;
}

const { ACTIVE, INACTIVE } = this.Characteristic.Active;
this.fanService().getCharacteristic(this.Characteristic.Active)
.onGet(() => {
const status = this.getStatus(schema.code)!;
return status.value as boolean;
return status.value as boolean ? ACTIVE : INACTIVE;
})
.onSet(value => {
const status = this.getStatus(schema.code)!;
this.sendCommands([{
code: status.code,
value: (value === this.Characteristic.Active.ACTIVE) ? true : false,
value: (value === ACTIVE) ? true : false,
}], true);
});
}
Expand Down Expand Up @@ -134,6 +145,23 @@ export default class FanAccessory extends BaseAccessory {
.setProps(props);
}

configureRotationDirection() {
const schema = this.getFanDirection();
if (!schema) {
return;
}

const { CLOCKWISE, COUNTER_CLOCKWISE } = this.Characteristic.RotationDirection;
this.fanService().getCharacteristic(this.Characteristic.RotationDirection)
.onGet(() => {
const status = this.getStatus(schema.code)!;
return (status.value !== 'reverse') ? CLOCKWISE : COUNTER_CLOCKWISE;
})
.onSet(value => {
this.sendCommands([{ code: schema.code, value: (value === CLOCKWISE) ? 'forward' : 'reverse' }]);
});
}

configureLightOn() {
const schema = this.getLightOnSchema();
if (!schema) {
Expand Down