Skip to content

Commit

Permalink
fix for devices that dont have both swing modes
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenVdb committed Oct 22, 2024
1 parent 72e630e commit 3ec8fdc
Show file tree
Hide file tree
Showing 5 changed files with 374 additions and 11 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [2.7.0-beta.1] - 2024-10-20
## [2.7.0-beta.5] - 2024-10-22

### Added

Expand All @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Update Altherma support (fixes
https://github.com/JeroenVdb/homebridge-daikin-cloud/issues/81)
- Fix for devices that don't have both horizontal and vertical swing (fixes https://github.com/JeroenVdb/homebridge-daikin-cloud/issues/89)

## [2.6.0-beta.5] - 2024-08-11

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"displayName": "Daikin Cloud",
"platformname": "daikincloud",
"name": "homebridge-daikin-cloud",
"version": "2.7.0-beta.4",
"version": "2.7.0-beta.5",
"description": "Integrate with the Daikin Cloud to control your Daikin air conditioning via the cloud",
"license": "Apache-2.0",
"repository": {
Expand Down
31 changes: 22 additions & 9 deletions src/climateControlService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CharacteristicValue, PlatformAccessory, Service} from 'homebridge';
import {DaikinCloudAccessoryContext, DaikinCloudPlatform} from './platform';
import {DaikinCloudRepo} from "./repository/daikinCloudRepo";
import {DaikinCloudRepo} from './repository/daikinCloudRepo';

export class ClimateControlService {
readonly platform: DaikinCloudPlatform;
Expand Down Expand Up @@ -402,18 +402,23 @@ export class ClimateControlService {
const daikinSwingMode = swingMode === 1 ? DaikinFanDirectionHorizontalModes.SWING : DaikinFanDirectionHorizontalModes.STOP;
this.platform.log.debug(`[${this.name}] SET SwingMode, swingmode to: ${swingMode}/${daikinSwingMode}`);

await this.accessory.context.device.setData(this.managementPointId, 'fanControl', `/operationModes/${this.getCurrentOperationMode()}/fanDirection/horizontal/currentMode`, daikinSwingMode);
await this.accessory.context.device.setData(this.managementPointId, 'fanControl', `/operationModes/${this.getCurrentOperationMode()}/fanDirection/vertical/currentMode`, daikinSwingMode);
if (this.hasSwingModeHorizontalFeature()) {
await this.accessory.context.device.setData(this.managementPointId, 'fanControl', `/operationModes/${this.getCurrentOperationMode()}/fanDirection/horizontal/currentMode`, daikinSwingMode);
}

if (this.hasSwingModeVerticalFeature()) {
await this.accessory.context.device.setData(this.managementPointId, 'fanControl', `/operationModes/${this.getCurrentOperationMode()}/fanDirection/vertical/currentMode`, daikinSwingMode);
}

this.platform.forceUpdateDevices();
} catch (e) {
this.platform.log.error('Failed to set', e, JSON.stringify(DaikinCloudRepo.maskSensitiveCloudDeviceData(this.accessory.context.device.desc), null, 4));
}
}

async handleSwingModeGet(): Promise<CharacteristicValue> {

const verticalSwingMode = this.accessory.context.device.getData(this.managementPointId, 'fanControl', `/operationModes/${this.getCurrentOperationMode()}/fanDirection/vertical/currentMode`).value;
const horizontalSwingMode = this.accessory.context.device.getData(this.managementPointId, 'fanControl', `/operationModes/${this.getCurrentOperationMode()}/fanDirection/vertical/currentMode`).value;
const verticalSwingMode = this.hasSwingModeVerticalFeature() ? this.accessory.context.device.getData(this.managementPointId, 'fanControl', `/operationModes/${this.getCurrentOperationMode()}/fanDirection/vertical/currentMode`).value : null;
const horizontalSwingMode = this.hasSwingModeHorizontalFeature() ? this.accessory.context.device.getData(this.managementPointId, 'fanControl', `/operationModes/${this.getCurrentOperationMode()}/fanDirection/horizontal/currentMode`).value : null;
this.platform.log.debug(`[${this.name}] GET SwingMode, verticalSwingMode: ${verticalSwingMode}, last update: ${this.accessory.context.device.getLastUpdated()}`);
this.platform.log.debug(`[${this.name}] GET SwingMode, horizontalSwingMode: ${horizontalSwingMode}, last update: ${this.accessory.context.device.getLastUpdated()}`);

Expand Down Expand Up @@ -570,12 +575,20 @@ export class ClimateControlService {
}
}

hasSwingModeFeature() {
hasSwingModeVerticalFeature() {
const verticalSwing = this.accessory.context.device.getData(this.managementPointId, 'fanControl', `/operationModes/${this.getCurrentOperationMode()}/fanDirection/vertical/currentMode`);
const horizontalSwing = this.accessory.context.device.getData(this.managementPointId, 'fanControl', `/operationModes/${this.getCurrentOperationMode()}/fanDirection/horizontal/currentMode`);
this.platform.log.debug(`[${this.name}] hasSwingModeFeature, verticalSwing: ${Boolean(verticalSwing)}`);
return Boolean(verticalSwing);
}

hasSwingModeHorizontalFeature() {
const horizontalSwing = this.accessory.context.device.getData(this.managementPointId, 'fanControl', `/operationModes/${this.getCurrentOperationMode()}/fanDirection/horizontal/currentMode`);
this.platform.log.debug(`[${this.name}] hasSwingModeFeature, horizontalSwing: ${Boolean(horizontalSwing)}`);
return Boolean(verticalSwing || horizontalSwing);
return Boolean(horizontalSwing);
}

hasSwingModeFeature() {
return Boolean(this.hasSwingModeVerticalFeature() || this.hasSwingModeHorizontalFeature());
}

hasPowerfulModeFeature() {
Expand Down
6 changes: 6 additions & 0 deletions test/daikinAirConditioningAccessory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import {unknownJan} from "./fixtures/unknown-jan";
import {unknownKitchenGuests} from "./fixtures/unknown-kitchen-guests";
import {dx23Airco} from "./fixtures/dx23-airco";
import {dx4Airco} from "./fixtures/dx4-airco";
import {dx23Airco2} from "./fixtures/dx23-airco-2";

test.each<Array<string | string | any>>([
['dx4', 'climateControl', dx4Airco],
['dx23', 'climateControl', dx23Airco],
['dx23-2', 'climateControl', dx23Airco2],
['unknown', 'climateControl', unknownKitchenGuests],
['unknown2', 'climateControl', unknownJan],
])('Create DaikinCloudAirConditioningAccessory with %s device', async (name: string, climateControlEmbeddedId, deviceJson) => {
Expand Down Expand Up @@ -43,6 +45,10 @@ test.each<Array<string | string | any>>([
if (!name.includes('unknown')) {
expect(await homebridgeAccessory.service?.handleHeatingThresholdTemperatureGet()).toBeDefined();
}

expect(async () => {
await homebridgeAccessory.service.handleSwingModeSet(1);
}).not.toThrow();
});

test.each<Array<string | string | any>>([
Expand Down
Loading

0 comments on commit 3ec8fdc

Please sign in to comment.