From f95becbc9d34fed9400311029d94e3efda91267b Mon Sep 17 00:00:00 2001 From: burmistrzak <61958704+burmistrzak@users.noreply.github.com> Date: Mon, 24 Jun 2024 00:52:34 +0200 Subject: [PATCH 1/4] Add `overrideHaConfig` --- src/lib/types.ts | 4 ++++ test/index.test.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/types.ts b/src/lib/types.ts index 7b148e877859d..039413416a936 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -160,6 +160,10 @@ export interface DefinitionMeta { * @defaultValue false */ coverPositionTiltDisableReport?: boolean, + /** + * Override the Home Assistant discovery payload. + */ + overrideHaConfig?: { [s: string]: string | Array }, } export type Configure = (device: Zh.Device, coordinatorEndpoint: Zh.Endpoint, definition: Definition) => Promise; diff --git a/test/index.test.js b/test/index.test.js index 7d5593055fd0c..69619d75e8c14 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -313,7 +313,7 @@ describe('index.js', () => { if (device.meta) { - containsOnly(['disableActionGroup', 'multiEndpoint', 'multiEndpointSkip', 'multiEndpointEnforce', 'applyRedFix', 'disableDefaultResponse', 'supportsEnhancedHue', 'timeout', 'supportsHueAndSaturation', 'battery', 'coverInverted', 'turnsOffAtBrightness1', 'coverStateFromTilt', 'pinCodeCount', 'tuyaThermostatSystemMode', 'tuyaThermostatPreset', 'tuyaDatapoints', 'tuyaThermostatPresetToSystemMode', 'thermostat', 'separateWhite', 'publishDuplicateTransaction', 'tuyaSendCommand', 'coverPositionTiltDisableReport'], Object.keys(device.meta)); + containsOnly(['disableActionGroup', 'multiEndpoint', 'multiEndpointSkip', 'multiEndpointEnforce', 'applyRedFix', 'disableDefaultResponse', 'supportsEnhancedHue', 'timeout', 'supportsHueAndSaturation', 'battery', 'coverInverted', 'turnsOffAtBrightness1', 'coverStateFromTilt', 'pinCodeCount', 'tuyaThermostatSystemMode', 'tuyaThermostatPreset', 'tuyaDatapoints', 'tuyaThermostatPresetToSystemMode', 'thermostat', 'separateWhite', 'publishDuplicateTransaction', 'tuyaSendCommand', 'coverPositionTiltDisableReport', 'overrideHaConfig'], Object.keys(device.meta)); } if (device.zigbeeModel) { From cbd624680e6abf2066cc0d750b4e046e42949fc3 Mon Sep 17 00:00:00 2001 From: burmistrzak <61958704+burmistrzak@users.noreply.github.com> Date: Fri, 28 Jun 2024 21:07:20 +0200 Subject: [PATCH 2/4] Make `overrideHaConfig` an optional function --- src/lib/types.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/types.ts b/src/lib/types.ts index f151f65453ecf..b27c4823d66a0 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -42,6 +42,10 @@ export type WhiteLabel = {vendor: string, model: string, description?: string}; export interface OtaUpdateAvailableResult {available: boolean, currentFileVersion: number, otaFileVersion: number} +export interface MockProperty {property: string, value: KeyValue | string} +// eslint-disable-next-line camelcase +export interface DiscoveryEntry {mockProperties: MockProperty[], type: string, object_id: string, discovery_payload: KeyValue} + export interface DefinitionMeta { separateWhite?: boolean, /** @@ -161,9 +165,9 @@ export interface DefinitionMeta { */ coverPositionTiltDisableReport?: boolean, /** - * Override the Home Assistant discovery payload. + * Override the Home Assistant discovery payload using a custom function. */ - overrideHaConfig?: { [s: string]: string | Array }, + overrideHaConfig?(configs: DiscoveryEntry[]): void, } export type Configure = (device: Zh.Device, coordinatorEndpoint: Zh.Endpoint, definition: Definition) => Promise; From baf8d9f5761a1a82742cfb36e8007b9ed9bd4885 Mon Sep 17 00:00:00 2001 From: burmistrzak <61958704+burmistrzak@users.noreply.github.com> Date: Fri, 28 Jun 2024 22:03:28 +0200 Subject: [PATCH 3/4] Add `overrideHaConfig` for Bosch BTH-RA --- src/devices/bosch.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/devices/bosch.ts b/src/devices/bosch.ts index c011e135c91a0..20883c1f5ea40 100644 --- a/src/devices/bosch.ts +++ b/src/devices/bosch.ts @@ -14,6 +14,7 @@ import * as constants from '../lib/constants'; import * as globalStore from '../lib/store'; import { Tz, Fz, Definition, KeyValue, ModernExtend, Expose, + MockProperty, DiscoveryEntry, } from '../lib/types'; import {logger} from '../lib/logger'; const e = exposes.presets; @@ -1264,6 +1265,23 @@ const definitions: Definition[] = [ model: 'BTH-RA', vendor: 'Bosch', description: 'Radiator thermostat II', + meta: { + overrideHaConfig: (configs) => { + const entry = configs.findIndex((e) => e.type === 'climate'); + if (entry) { + const commandTopic = configs[entry].discovery_payload.mode_command_topic as string; + configs[entry].discovery_payload.mode_command_topic = + commandTopic.substring(0, commandTopic.lastIndexOf('/system_mode')); + configs[entry].discovery_payload.mode_command_template = `{% set values = ` + + `{ 'auto':'schedule','heat':'manual','off':'pause'} %}` + + `{"operating_mode": "{{ values[value] if value in values.keys() else 'pause' }}"}`; + configs[entry].discovery_payload.mode_state_template = `{% set values = ` + + `{'schedule':'auto','manual':'heat','pause':'off'} %}` + + `{% set value = value_json.operating_mode %}{{ values[value] if value in values.keys() else 'off' }}`; + configs[entry].discovery_payload.modes = ['off', 'heat', 'auto']; + } + }, + }, exposes: [ e.climate() .withLocalTemperature(ea.STATE_GET, 'Temperature used by the heating algorithm. ' + From 994db2afb51b667a5c19cfd69b87c20daa0da773 Mon Sep 17 00:00:00 2001 From: burmistrzak <61958704+burmistrzak@users.noreply.github.com> Date: Fri, 28 Jun 2024 22:05:30 +0200 Subject: [PATCH 4/4] Remove unused imports --- src/devices/bosch.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/devices/bosch.ts b/src/devices/bosch.ts index 20883c1f5ea40..0e17f8cd7b161 100644 --- a/src/devices/bosch.ts +++ b/src/devices/bosch.ts @@ -14,7 +14,6 @@ import * as constants from '../lib/constants'; import * as globalStore from '../lib/store'; import { Tz, Fz, Definition, KeyValue, ModernExtend, Expose, - MockProperty, DiscoveryEntry, } from '../lib/types'; import {logger} from '../lib/logger'; const e = exposes.presets;