Revert "Use light entity for out_lvl_switch if the device type is "light""

This reverts commit 50500e97be95ec3dfde929e27e776242848b5425.
This commit is contained in:
Adrian Jagielak 2025-09-27 02:25:52 +02:00
parent 653df93807
commit a8c61c4658
No known key found for this signature in database
GPG Key ID: 0818CF7AF6C62BFB

View File

@ -16,104 +16,36 @@ export function out_lvl_switch__components(
const minLvl = svc.props?.min_lvl ?? 0; const minLvl = svc.props?.min_lvl ?? 0;
const maxLvl = svc.props?.max_lvl ?? 100; const maxLvl = svc.props?.max_lvl ?? 100;
const isLightDevice = device.type?.type === 'light'; return {
components: {
if (isLightDevice) { [svc.addr]: {
// Use light component for light devices unique_id: svc.addr,
return { platform: 'number',
components: { name: 'Level Switch',
[`${svc.addr}_light`]: { min: minLvl,
unique_id: `${svc.addr}_light`, max: maxLvl,
platform: 'light', step: 1,
name: 'Light', command_topic: commandTopic,
brightness: true, optimistic: false,
brightness_scale: maxLvl, value_template: `{{ value_json['${svc.addr}'].lvl }}`,
command_topic: commandTopic,
optimistic: false,
state_topic: `${topicPrefix}${svc.addr}/state`,
state_value_template: `{% if value_json['${svc.addr}'].lvl > 0 %}ON{% else %}OFF{% endif %}`,
brightness_state_topic: `${topicPrefix}${svc.addr}/state`,
brightness_value_template: `{{ value_json['${svc.addr}'].lvl }}`,
},
// Remove the no longer needed `number` entity by setting it to an empty value
[svc.addr]: {
unique_id: svc.addr,
} as any,
}, },
},
commandHandlers: { commandHandlers: {
[commandTopic]: async (payload: string) => { [commandTopic]: async (payload: string) => {
const command = JSON.parse(payload); const lvl = parseInt(payload, 10);
if (Number.isNaN(lvl)) {
return;
}
if (command.state === 'ON') { await sendFimpMsg({
let lvl = maxLvl; address: svc.addr!,
if (command.brightness !== undefined) { service: 'out_lvl_switch',
lvl = Math.round(command.brightness); cmd: 'cmd.lvl.set',
} val: lvl,
val_t: 'int',
await sendFimpMsg({ });
address: svc.addr!,
service: 'out_lvl_switch',
cmd: 'cmd.lvl.set',
val: lvl,
val_t: 'int',
});
} else if (command.state === 'OFF') {
await sendFimpMsg({
address: svc.addr!,
service: 'out_lvl_switch',
cmd: 'cmd.lvl.set',
val: minLvl,
val_t: 'int',
});
} else if (command.brightness !== undefined) {
const lvl = Math.round(command.brightness);
await sendFimpMsg({
address: svc.addr!,
service: 'out_lvl_switch',
cmd: 'cmd.lvl.set',
val: lvl,
val_t: 'int',
});
}
},
}, },
}; },
} else { };
// Use number component for non-light devices
return {
components: {
[svc.addr]: {
unique_id: svc.addr,
platform: 'number',
name: 'Level Switch',
min: minLvl,
max: maxLvl,
step: 1,
command_topic: commandTopic,
optimistic: false,
value_template: `{{ value_json['${svc.addr}'].lvl }}`,
},
},
commandHandlers: {
[commandTopic]: async (payload: string) => {
const lvl = parseInt(payload, 10);
if (Number.isNaN(lvl)) {
return;
}
await sendFimpMsg({
address: svc.addr!,
service: 'out_lvl_switch',
cmd: 'cmd.lvl.set',
val: lvl,
val_t: 'int',
});
},
},
};
}
} }