mirror of
https://github.com/adrianjagielak/home-assistant-futurehome.git
synced 2025-10-04 10:47:10 +00:00
Use light
entity for out_lvl_switch if the device type is "light"
This commit is contained in:
parent
f216f4b719
commit
50500e97be
@ -16,6 +16,73 @@ 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';
|
||||||
|
|
||||||
|
if (isLightDevice) {
|
||||||
|
// Use light component for light devices
|
||||||
|
return {
|
||||||
|
components: {
|
||||||
|
[`${svc.addr}_light`]: {
|
||||||
|
unique_id: `${svc.addr}_light`,
|
||||||
|
platform: 'light',
|
||||||
|
name: 'Light',
|
||||||
|
brightness: true,
|
||||||
|
brightness_scale: maxLvl,
|
||||||
|
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: {
|
||||||
|
[commandTopic]: async (payload: string) => {
|
||||||
|
const command = JSON.parse(payload);
|
||||||
|
|
||||||
|
if (command.state === 'ON') {
|
||||||
|
let lvl = maxLvl;
|
||||||
|
if (command.brightness !== undefined) {
|
||||||
|
lvl = Math.round(command.brightness);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
return {
|
||||||
components: {
|
components: {
|
||||||
[svc.addr]: {
|
[svc.addr]: {
|
||||||
@ -48,4 +115,5 @@ export function out_lvl_switch__components(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user