Skip to content

Commit

Permalink
refactor: use active speed threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandenaardweg committed Dec 28, 2022
1 parent ce55e61 commit 0d0d6eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/fan-accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Service, PlatformAccessory, CharacteristicValue, Nullable } from 'homeb
import { HomebridgeIthoDaalderop } from '@/platform';
import { IthoDaalderopAccessoryContext, IthoStatusSanitizedPayload } from './types';
import {
ACTIVE_SPEED_THRESHOLD,
DEFAULT_FAN_NAME,
MANUFACTURER,
MAX_ROTATION_SPEED,
Expand Down Expand Up @@ -328,7 +329,7 @@ export class FanAccessory {
return;
}

if (rotationSpeed < 10) {
if (rotationSpeed < ACTIVE_SPEED_THRESHOLD) {
if (currentFanStateValue === this.platform.Characteristic.CurrentFanState.IDLE) {
this.log.debug(`CurrentFanState: Already set to: ${currentFanStateName}. Ignoring.`);
return;
Expand Down Expand Up @@ -418,7 +419,7 @@ export class FanAccessory {

// A rotation speed of 0 will turn the fan off
// A rotation speed of 20 will turn the fan on
const speedValue = activate ? 20 : 0;
const speedValue = activate ? ACTIVE_SPEED_THRESHOLD : 0;

if (this.mqttApiClient) {
this.mqttApiClient.setSpeed(speedValue);
Expand Down
3 changes: 3 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ export const MQTT_CMD_TOPIC = 'itho/cmd';

// https://developers.homebridge.io/#/characteristic/RotationSpeed
export const MAX_ROTATION_SPEED = 100;

/** Any value above this value is considered "active" */
export const ACTIVE_SPEED_THRESHOLD = 20;

0 comments on commit 0d0d6eb

Please sign in to comment.