Skip to content

Commit

Permalink
fix: Fix HA discovery for Bosch BTH-RA (#7685)
Browse files Browse the repository at this point in the history
* Add `overrideHaConfig`

* Make `overrideHaConfig` an optional function

* Add `overrideHaConfig` for Bosch BTH-RA

* Remove unused imports
  • Loading branch information
burmistrzak authored Jun 29, 2024
1 parent 578ec18 commit caf39c1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/devices/bosch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,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. ' +
Expand Down
8 changes: 8 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
/**
Expand Down Expand Up @@ -160,6 +164,10 @@ export interface DefinitionMeta {
* @defaultValue false
*/
coverPositionTiltDisableReport?: boolean,
/**
* Override the Home Assistant discovery payload using a custom function.
*/
overrideHaConfig?(configs: DiscoveryEntry[]): void,
}

export type Configure = (device: Zh.Device, coordinatorEndpoint: Zh.Endpoint, definition: Definition) => Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit caf39c1

Please sign in to comment.