Skip to content

Commit

Permalink
feat: Legrand 067776(A): Improved PR#Koenkk#7412
Browse files Browse the repository at this point in the history
* Made tilt display dependant on calibration mode
  • Loading branch information
FabianMangold committed Apr 20, 2024
1 parent f2005cd commit 9b91ebd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/devices/legrand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
24 changes: 11 additions & 13 deletions src/lib/legrand.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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} = {
Expand Down Expand Up @@ -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 => {
Expand All @@ -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)
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 9b91ebd

Please sign in to comment.