From 85f9efe61f08001c9b08d95b558209124c22f488 Mon Sep 17 00:00:00 2001 From: eibenp Date: Wed, 27 Nov 2024 22:43:13 +0100 Subject: [PATCH] Added temperatureStepSize configuration parameter --- config.schema.json | 28 ++++++++-------------------- src/platform.ts | 10 +++++----- src/platformAccessory.ts | 16 +++------------- src/settings.ts | 10 +++++----- 4 files changed, 21 insertions(+), 43 deletions(-) diff --git a/config.schema.json b/config.schema.json index dec1ab9..cfe77c5 100644 --- a/config.schema.json +++ b/config.schema.json @@ -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" @@ -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)
(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);" } diff --git a/src/platform.ts b/src/platform.ts index f0452ba..80a673b 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -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'; @@ -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) { diff --git a/src/platformAccessory.ts b/src/platformAccessory.ts index 633ac2b..575c19a 100644 --- a/src/platformAccessory.ts +++ b/src/platformAccessory.ts @@ -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'; @@ -58,16 +58,6 @@ 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: @@ -75,7 +65,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.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), }); @@ -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), }); diff --git a/src/settings.ts b/src/settings.ts index ea68257..64ed876 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -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 { @@ -42,7 +42,7 @@ export interface DeviceConfig { maximumTargetTemperature: number; xFanEnabled: boolean; temperatureSensor: string; - temperatureUnit?: string; + temperatureStepSize?: number; disabled?: boolean; defaultVerticalSwing?: number; overrideDefaultVerticalSwing?: number; @@ -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,