Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overrideHaConfig meta definition #7685

Merged
merged 7 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading