Skip to content

Commit

Permalink
Added temperatureStepSize configuration parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
eibenp committed Nov 27, 2024
1 parent aa70856 commit 85f9efe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 43 deletions.
28 changes: 8 additions & 20 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,11 @@
}
]
},
"temperatureUnit": {
"type": "string",
"required": false,
"oneOf": [
{
"title": "Celsius",
"enum": [
"celsius"
]
},
{
"title": "Fahrenheit",
"enum": [
"fahrenheit"
]
}
]
"temperatureStepSize": {
"type": "number",
"minimum": 0.5,
"multipleOf": 0.5,
"required": false
},
"disabled": {
"type": "boolean"
Expand Down Expand Up @@ -376,10 +364,10 @@
}
},
{
"key": "devices[].temperatureUnit",
"key": "devices[].temperatureStepSize",
"flex": "1 1 50%",
"title": "Temperature unit:",
"description": "Temperature calculation mode (Fahrenheit if empty)",
"title": "Temperature step size:",
"description": "Valid values: 0.5 (for °F) and 1 (for °C)<BR />(0.5 if empty or invalid)",
"condition": {
"functionBody": "return (model.devices && model.devices[arrayIndices] && model.devices[arrayIndices].mac && /^[a-f0-9]{12}$/.test(model.devices[arrayIndices].mac) && model.devices[arrayIndices].disabled !== true);"
}
Expand Down
10 changes: 5 additions & 5 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig,
import { networkInterfaces } from 'os';

import { PLATFORM_NAME, PLUGIN_NAME, UDP_SCAN_PORT, DEFAULT_DEVICE_CONFIG, OVERRIDE_DEFAULT_SWING, ENCRYPTION_VERSION, TS_TYPE,
DEF_SCAN_INTERVAL, TEMPERATURE_LIMITS, TEMPERATURE_UNITS} from './settings';
DEF_SCAN_INTERVAL, TEMPERATURE_LIMITS, TEMPERATURE_STEPS} from './settings';
import { GreeAirConditioner } from './platformAccessory';
import commands from './commands';
import { version } from './version';
Expand Down Expand Up @@ -204,10 +204,10 @@ export class GreeACPlatform implements DynamicPlatformPlugin {
this.log.warn('Warning: Invalid minimum and maximum target temperature values detected ->',
`Accessory ${deviceInfo.mac} is using default values instead of the configured ones`);
}
if (deviceConfig.temperatureUnit && !Object.values(TEMPERATURE_UNITS).includes(deviceConfig.temperatureUnit)) {
this.log.warn(`Warning: Invalid temperature unit detected: ${deviceConfig.temperatureUnit} ->`,
`Accessory ${deviceInfo.mac} is using default unit (Fahrenheit) instead of the configured one`);
delete deviceConfig.temperatureUnit;
if (deviceConfig.temperatureStepSize !== undefined && !Object.values(TEMPERATURE_STEPS).includes(deviceConfig.temperatureStepSize)) {
this.log.warn(`Warning: Invalid temperature step size detected: ${deviceConfig.temperatureStepSize} ->`,
`Accessory ${deviceInfo.mac} is using default value (0.5) instead of the configured one`);
delete deviceConfig.temperatureStepSize;
}
Object.entries(DEFAULT_DEVICE_CONFIG).forEach(([key, value]) => {
if (deviceConfig[key] === undefined) {
Expand Down
16 changes: 3 additions & 13 deletions src/platformAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Service, CharacteristicValue } from 'homebridge';

import { GreeACPlatform, MyPlatformAccessory } from './platform';
import { PLATFORM_NAME, PLUGIN_NAME, DeviceConfig, TEMPERATURE_TABLE, OVERRIDE_DEFAULT_SWING, TS_TYPE, BINDING_TIMEOUT,
TEMPERATURE_LIMITS, TEMPERATURE_UNITS } from './settings';
TEMPERATURE_LIMITS } from './settings';
import { GreeAirConditionerTS } from './tsAccessory';
import crypto from './crypto';
import commands from './commands';
Expand Down Expand Up @@ -58,24 +58,14 @@ export class GreeAirConditioner {

initCharacteristics() {
// these characteristic properties are not updated by HomeKit, they are initialized only once
let minTempStep;
switch (this.deviceConfig.temperatureUnit) {
case TEMPERATURE_UNITS.celsius:
minTempStep = 1;
break;
case TEMPERATURE_UNITS.fahrenheit:
default:
minTempStep = 0.5;
break;
}

// Cooling Threshold Temperature Characteristic
// minValue / maxValue usually generates error messages in debug log:
// "Characteristic 'Cooling Threshold Temperature': characteristic was supplied illegal value ..."
// this is not a problem, this is information only that GREE is more restricitive than Apple's default
this.HeaterCooler?.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
.setProps({
minStep: minTempStep,
minStep: this.deviceConfig.temperatureStepSize,
minValue: Math.max(this.deviceConfig.minimumTargetTemperature, TEMPERATURE_LIMITS.coolingMinimum),
maxValue: Math.min(this.deviceConfig.maximumTargetTemperature, TEMPERATURE_LIMITS.coolingMaximum),
});
Expand All @@ -89,7 +79,7 @@ export class GreeAirConditioner {
// this is not a problem, this is information only that GREE is more restricitive than Apple's default
this.HeaterCooler?.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
.setProps({
minStep: minTempStep,
minStep: this.deviceConfig.temperatureStepSize,
minValue: Math.max(this.deviceConfig.minimumTargetTemperature, TEMPERATURE_LIMITS.heatingMinimum),
maxValue: Math.min(this.deviceConfig.maximumTargetTemperature, TEMPERATURE_LIMITS.heatingMaximum),
});
Expand Down
10 changes: 5 additions & 5 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export const TS_TYPE = {
child: 'child',
};

export const TEMPERATURE_UNITS = {
celsius: 'celsius',
fahrenheit: 'fahrenheit',
export const TEMPERATURE_STEPS = {
celsius: 1,
fahrenheit: 0.5,
};

export interface DeviceConfig {
Expand All @@ -42,7 +42,7 @@ export interface DeviceConfig {
maximumTargetTemperature: number;
xFanEnabled: boolean;
temperatureSensor: string;
temperatureUnit?: string;
temperatureStepSize?: number;
disabled?: boolean;
defaultVerticalSwing?: number;
overrideDefaultVerticalSwing?: number;
Expand All @@ -59,7 +59,7 @@ export const DEFAULT_DEVICE_CONFIG: DeviceConfig = {
maximumTargetTemperature: 30,
xFanEnabled: true,
temperatureSensor: TS_TYPE.disabled,
temperatureUnit: TEMPERATURE_UNITS.fahrenheit,
temperatureStepSize: TEMPERATURE_STEPS.fahrenheit,
defaultVerticalSwing: commands.swingVertical.value.default,
overrideDefaultVerticalSwing: OVERRIDE_DEFAULT_SWING.never,
encryptionVersion: ENCRYPTION_VERSION.auto,
Expand Down

0 comments on commit 85f9efe

Please sign in to comment.