Skip to content

Commit

Permalink
feat(ignore): Refactor ledvance to modernExtend (#6670)
Browse files Browse the repository at this point in the history
* feat(ignore): Refactor ledvance to modernExtend

* updates
  • Loading branch information
Koenkk authored Dec 9, 2023
1 parent 7a4e199 commit c361f9b
Show file tree
Hide file tree
Showing 12 changed files with 395 additions and 486 deletions.
22 changes: 13 additions & 9 deletions scripts/modernExtendRefactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ project.getSourceFiles().forEach((sourceFile) => {

let changed = true;
let save = false;
const type = 'philipsLight';
const type = 'ledvanceLight';
while (changed) {
changed = false;
const definitions = sourceFile.getVariableStatementOrThrow('definitions').getDescendantsOfKind(SyntaxKind.ObjectLiteralExpression);
Expand All @@ -32,12 +32,12 @@ project.getSourceFiles().forEach((sourceFile) => {
const fromZigbee = childs.find((c) => c.getFirstChildByKind(SyntaxKind.Identifier)?.getText() === 'fromZigbee');
const toZigbee = childs.find((c) => c.getFirstChildByKind(SyntaxKind.Identifier)?.getText() === 'toZigbee');
const meta = childs.find((c) => c.getFirstChildByKind(SyntaxKind.Identifier)?.getText() === 'meta');
const ota = childs.find((c) => c.getFirstChildByKind(SyntaxKind.Identifier)?.getText() === 'ota');

if ((extend?.getFullText().includes('extend: philips.extend.light_onoff_brightness_colortemp(') ||
extend?.getFullText().includes('extend: philips.extend.light_onoff_brightness_colortemp_color(') ||
extend?.getFullText().includes('extend: philips.extend.light_onoff_brightness(') ||
extend?.getFullText().includes('extend: philips.extend.light_onoff_brightness_colortemp_color_gradient(') ||
extend?.getFullText().includes('extend: philips.extend.light_onoff_brightness_color(')) &&
if ((extend?.getFullText().includes('extend: ledvance.extend.light_onoff_brightness_colortemp(') ||
extend?.getFullText().includes('extend: ledvance.extend.light_onoff_brightness_colortemp_color(') ||
extend?.getFullText().includes('extend: ledvance.extend.light_onoff_brightness(') ||
extend?.getFullText().includes('extend: ledvance.extend.light_onoff_brightness_color(')) &&
!fromZigbee && !toZigbee && !configure && !exposes) {
console.log(`Handling ${model?.getFullText().trim()}`);
const newOpts: {[s: string]: unknown} = {};
Expand All @@ -56,7 +56,8 @@ project.getSourceFiles().forEach((sourceFile) => {
if (opts[opts.length - 1] === ',') {
opts = opts.substring(0, opts.length - 1);
}
for (const [key, value] of Object.entries(eval(`(${opts})`))) {
const evalOpts = Object.entries(eval(`(${opts})`));
for (const [key, value] of evalOpts) {
if (key === 'colorTempRange') {
// @ts-expect-error
newOpts.colorTemp = {...newOpts.colorTemp, range: value};
Expand All @@ -69,9 +70,9 @@ project.getSourceFiles().forEach((sourceFile) => {
newOpts.effect = !value;
} else if (key === 'disableHueEffects') {
newOpts.hueEffect = !value;
} else if (key === 'supportsHueAndSaturation') {
} else if (key === 'supportsHueAndSaturation' || key === 'preferHueAndSaturation') {
// @ts-expect-error
newOpts.color = {...newOpts.color, modes: ['xy', 'hs']};
newOpts.color = {...newOpts.color, modes: evalOpts.preferHueAndSaturation ? ['hs', 'xy'] : ['xy', 'hs']};
} else if (key === 'extraEffects') {
// @ts-expect-error
newOpts.gradient = {...newOpts.gradient, extraEffects: value};
Expand All @@ -96,6 +97,9 @@ project.getSourceFiles().forEach((sourceFile) => {
}
meta.remove();
}
if (ota) {
ota.remove();
}

localTotalDefinitionsWithModernExtend += 1;
extend.replaceWithText(`extend: [${type}(${JSON.stringify(newOpts).split(`"`).join('')
Expand Down
21 changes: 0 additions & 21 deletions src/converters/toZigbee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {Zcl} from 'zigbee-herdsman';
const manufacturerOptions = {
sunricher: {manufacturerCode: Zcl.ManufacturerCode.SHENZHEN_SUNRICH},
xiaomi: {manufacturerCode: Zcl.ManufacturerCode.LUMI_UNITED_TECH, disableDefaultResponse: true},
osram: {manufacturerCode: Zcl.ManufacturerCode.OSRAM},
eurotronic: {manufacturerCode: Zcl.ManufacturerCode.JENNIC},
danfoss: {manufacturerCode: Zcl.ManufacturerCode.DANFOSS},
hue: {manufacturerCode: Zcl.ManufacturerCode.PHILIPS},
Expand Down Expand Up @@ -2653,26 +2652,6 @@ const converters2 = {
await entity.read('aqaraOpple', [0x040a], manufacturerOptions.xiaomi);
},
} satisfies Tz.Converter,
ledvance_commands: {
/* deprecated osram_*/
key: ['set_transition', 'remember_state', 'osram_set_transition', 'osram_remember_state'],
convertSet: async (entity, key, value, meta) => {
if (key === 'osram_set_transition' || key === 'set_transition') {
if (value) {
utils.assertNumber(value, key);
const transition = (value > 1) ? Number((Math.round(Number((value * 2).toFixed(1))) / 2).toFixed(1)) * 10 : 1;
const payload = {0x0012: {value: transition, type: 0x21}, 0x0013: {value: transition, type: 0x21}};
await entity.write('genLevelCtrl', payload);
}
} else if (key == 'osram_remember_state' || key == 'remember_state') {
if (value === true) {
await entity.command('manuSpecificOsram', 'saveStartupParams', {}, manufacturerOptions.osram);
} else if (value === false) {
await entity.command('manuSpecificOsram', 'resetStartupParams', {}, manufacturerOptions.osram);
}
}
},
} satisfies Tz.Converter,
SPZ01_power_outage_memory: {
key: ['power_outage_memory'],
convertSet: async (entity, key, value, meta) => {
Expand Down
Loading

0 comments on commit c361f9b

Please sign in to comment.