From 9b91ebdbfb4befbeb9f8768d13dcd5d59d5046db Mon Sep 17 00:00:00 2001 From: Fabian Mangold Date: Sat, 20 Apr 2024 13:24:34 +0200 Subject: [PATCH] feat: Legrand 067776(A): Improved PR##7412 * Made tilt display dependant on calibration mode --- src/devices/legrand.ts | 4 ++-- src/lib/legrand.ts | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/devices/legrand.ts b/src/devices/legrand.ts index a6d40704388bc..469f998b9238d 100644 --- a/src/devices/legrand.ts +++ b/src/devices/legrand.ts @@ -126,7 +126,7 @@ const definitions: Definition[] = [ toZigbee: [tz.cover_state, tz.cover_position_tilt, tzLegrand.identify, tzLegrand.led_mode, tzLegrand.calibration_mode(false)], exposes: (device, options) => { return [ - _067776.getCover(options), + _067776.getCover(device), e.action(['moving', 'identify']), eLegrand.identify(), eLegrand.ledInDark(), @@ -187,7 +187,7 @@ const definitions: Definition[] = [ toZigbee: [tz.cover_state, tz.cover_position_tilt, tzLegrand.identify, tzLegrand.led_mode, tzLegrand.calibration_mode(true)], exposes: (device, options) => { return [ - _067776.getCover(options), + _067776.getCover(device), e.action(['moving', 'identify']), eLegrand.identify(), eLegrand.ledInDark(), diff --git a/src/lib/legrand.ts b/src/lib/legrand.ts index a281582cd99f9..5ed5e1d7dd562 100644 --- a/src/lib/legrand.ts +++ b/src/lib/legrand.ts @@ -1,5 +1,5 @@ import {Zcl} from 'zigbee-herdsman'; -import {Fz, Tz, OnEvent, KeyValue, KeyValueString, KeyValueAny} from '../lib/types'; +import {Fz, Tz, Zh, OnEvent, KeyValueString, KeyValueAny} from '../lib/types'; import * as exposes from './exposes'; import * as utils from '../lib/utils'; import {logger} from './logger'; @@ -8,12 +8,12 @@ const NS = 'zhc:legrand'; const e = exposes.presets; const ea = exposes.access; -const shutterCalibrationModes: {[k: number]: {description: string, onlyNLLV: boolean}} = { - 0: {description: 'classic_nllv', onlyNLLV: true}, - 1: {description: 'specific_nllv', onlyNLLV: true}, - 2: {description: 'up_down_stop', onlyNLLV: false}, - 3: {description: 'temporal', onlyNLLV: false}, - 4: {description: 'venetian_bso', onlyNLLV: false}, +const shutterCalibrationModes: {[k: number]: {description: string, onlyNLLV: boolean, supportsTilt: boolean}} = { + 0: {description: 'classic_nllv', onlyNLLV: true, supportsTilt: false}, + 1: {description: 'specific_nllv', onlyNLLV: true, supportsTilt: false}, + 2: {description: 'up_down_stop', onlyNLLV: false, supportsTilt: false}, + 3: {description: 'temporal', onlyNLLV: false, supportsTilt: false}, + 4: {description: 'venetian_bso', onlyNLLV: false, supportsTilt: true}, }; const ledModes:{[k: number]: string} = { @@ -46,9 +46,6 @@ const optsLegrand = { .withFeature(e.enum('effect', ea.SET, Object.values(ledEffects)).withLabel('Effect')) .withFeature(e.enum('color', ea.SET, Object.values(ledColors)).withLabel('Color')); }, - tiltControl: () => { - return new exposes.Binary('tilt_control', ea.SET, 'Show', 'Hide').withDescription('Defines if this cover shall display a tilt control.'); - }, }; const getApplicableCalibrationModes = (isNLLVSwitch: boolean): KeyValueString => { @@ -60,10 +57,12 @@ const getApplicableCalibrationModes = (isNLLVSwitch: boolean): KeyValueString => export const legrandOptions = {manufacturerCode: Zcl.ManufacturerCode.LEGRAND_GROUP, disableDefaultResponse: true}; export const _067776 = { - getCover: (options: KeyValue) => { + getCover: (device: Zh.Device) => { const c = e.cover_position(); - const showTilt = (options?.tilt_control ?? 'Show') === 'Show' ? true : false; + const calMode = Number(device?.getEndpoint(1)?.clusters?.closuresWindowCovering?.attributes?.calibrationMode); + const showTilt = calMode ? (shutterCalibrationModes[calMode]?.supportsTilt === true): false; + if (showTilt) { c.addFeature(new exposes.Numeric('tilt', ea.ALL) .withValueMin(0).withValueMax(100) @@ -124,7 +123,6 @@ export const tzLegrand = { calibration_mode: (isNLLVSwitch: boolean) => { return { key: ['calibration_mode'], - options: [optsLegrand.tiltControl()], convertSet: async (entity, key, value, meta) => { const applicableModes = getApplicableCalibrationModes(isNLLVSwitch); utils.validateValue(value, Object.values(applicableModes));