Skip to content

Commit

Permalink
- add support for optional capabilities in capabilityMap
Browse files Browse the repository at this point in the history
- switches for fan oscillation and optional mode are added only if supported in device's capabilitie
  • Loading branch information
lucaponzanelli committed Sep 3, 2023
1 parent 9e16fd1 commit b902884
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
This is a smartthings plugin for Homebridge. This requires no access to the legacy smartthings app, and doesn't
require a lot of work to install. It will discover devices automatically as well as unregister devices that are removed
from your smarttthings network. This is currently under development.
## New in version 1.5.15
* Support for optional capaiblities declaration
* AirConditionerService adds fan oscillation switch and optional mode switch only if supported by device's capabilitites
## New in version 1.5.14
* Support for air conditioners optional modes (i.e., Sleep, Speed, WindFree, WindFreeSleep)
* Stop logging warning if battery is low
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "SmartThings Plugin",
"name": "homebridge-smartthings-ik",
"version": "1.5.14",
"version": "1.5.15",
"description": "Connects SmartThings devices to Homebridge. Automatically discovers devices.",
"license": "Apache-2.0",
"repository": {
Expand Down Expand Up @@ -51,4 +51,4 @@
"url": "https://venmo.com/?txn=pay&audience=public&recipients=ira-klein-3"
}
]
}
}
17 changes: 12 additions & 5 deletions src/multiServiceAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ export class MultiServiceAccessory {
'switch',
'airConditionerMode',
'airConditionerFanMode',
'fanOscillationMode',
'thermostatCoolingSetpoint',
'temperatureMeasurement',
],
optionalCapabilities: [
'fanOscillationMode',
'relativeHumidityMeasurement',
'custom.airConditionerOptionalMode',
],
Expand Down Expand Up @@ -200,6 +202,7 @@ export class MultiServiceAccessory {
component: any,
capabilitiesToCover: string[],
capabilities: string[],
optionalCapabilities: string[],
serviceConstructor: any,
): string[] {
// this.log.debug(`Testing ${serviceConstructor.name} for capabilities ${capabilitiesToCover}`);
Expand All @@ -209,13 +212,15 @@ export class MultiServiceAccessory {
return capabilitiesToCover;
}

this.log.debug(`Creating instance of ${serviceConstructor.name} for capabilities ${capabilities}`);
const serviceInstance = new serviceConstructor(this.platform, this.accessory, componentId, capabilities, this, this.name, component);
const allCapabilities = capabilities.concat(optionalCapabilities.filter(e => capabilitiesToCover.includes(e)))

this.log.debug(`Creating instance of ${serviceConstructor.name} for capabilities ${allCapabilities}`);
const serviceInstance = new serviceConstructor(this.platform, this.accessory, componentId, allCapabilities, this, this.name, component);
this.services.push(serviceInstance);

this.log.debug(`Registered ${serviceConstructor.name} for capabilities ${capabilities}`);
this.log.debug(`Registered ${serviceConstructor.name} for capabilities ${allCapabilities}`);
// remove covered capabilities and return unused
return capabilitiesToCover.filter(e => !capabilities.includes(e));
return capabilitiesToCover.filter(e => !allCapabilities.includes(e));
}

public addComponent(componentId: string, capabilities: string[]) {
Expand All @@ -239,6 +244,7 @@ export class MultiServiceAccessory {
component,
capabilitiesToCover,
entry.capabilities,
entry.optionalCapabilities || [],
entry.service,
);
});
Expand All @@ -250,6 +256,7 @@ export class MultiServiceAccessory {
component,
capabilitiesToCover,
[capability],
[],
service,
);
});
Expand Down
27 changes: 18 additions & 9 deletions src/services/airConditionerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,26 @@ export class AirConditionerService extends BaseService {
this.fanService = this.setupFan(platform, multiServiceAccessory);

// Exposing this sensor is optional since some Samsung air conditioner always report 0 as relative humidity level
if (this.platform.config.ExposeHumiditySensorForAirConditioners) {
// or the device might not support it
if (this.isCapabilitySupported('relativeHumidityMeasurement') && this.platform.config.ExposeHumiditySensorForAirConditioners) {
this.humidityService = this.setupHumiditySensor(platform, multiServiceAccessory);
}

this.optionalMode = OptionalMode[this.platform.config.OptionalModeForAirConditioners];

// Expose a switch for the optional mode.
// If the selected optional mode is undefined or not supported, changes to the switch will have no effect.
this.optionalModeSwitchService = this.setupOptionalModeSwitch(platform, multiServiceAccessory);
// Optional mode switch is exposed only if the related capability is suppoorted
if (this.isCapabilitySupported('custom.airConditionerOptionalMode')) {
this.optionalMode = OptionalMode[this.platform.config.OptionalModeForAirConditioners];

}
// Expose a switch for the optional mode.
// If the selected optional mode is undefined or not supported, changes to the switch will have no effect.
this.optionalModeSwitchService = this.setupOptionalModeSwitch(platform, multiServiceAccessory);
}

}

private isCapabilitySupported(capability): boolean {
return this.capabilities.find(c => c === capability) != undefined;
}

private setupThermostat(platform: IKHomeBridgeHomebridgePlatform, multiServiceAccessory: MultiServiceAccessory): Service {
this.log.debug(`Expose Thermostat for ${this.name}`);
Expand Down Expand Up @@ -126,9 +133,11 @@ export class AirConditionerService extends BaseService {
.onGet(this.getSwitchState.bind(this))
.onSet(this.setSwitchState.bind(this));

this.service.getCharacteristic(platform.Characteristic.SwingMode)
.onGet(this.getSwingMode.bind(this))
.onSet(this.setSwingMode.bind(this));
if (this.isCapabilitySupported('fanOscillationMode')) {
this.service.getCharacteristic(platform.Characteristic.SwingMode)
.onGet(this.getSwingMode.bind(this))
.onSet(this.setSwingMode.bind(this));
}

this.service.getCharacteristic(platform.Characteristic.RotationSpeed)
.onSet(this.setFanLevel.bind(this))
Expand Down

0 comments on commit b902884

Please sign in to comment.