55 lines
1.1 KiB
JavaScript
55 lines
1.1 KiB
JavaScript
// vim: set sw=2 ts=2 sts=2 et :
|
|
|
|
class StrategyDeviceButtons {
|
|
|
|
static async generateView(info) {
|
|
const { device_name } = info.view.strategy.options;
|
|
|
|
const [devices, entities] = await Promise.all([
|
|
info.hass.callWS({ type: "config/device_registry/list" }),
|
|
info.hass.callWS({ type: "config/entity_registry/list" }),
|
|
]);
|
|
|
|
const cards = [];
|
|
|
|
let device_id;
|
|
for (const device of devices) {
|
|
if (device.name == device_name) {
|
|
device_id = device.id;
|
|
break;
|
|
}
|
|
}
|
|
if (!device_id) {
|
|
console.error("Could not find device id");
|
|
}
|
|
|
|
for (const entity of entities) {
|
|
if (device_id && entity.device_id == device_id) {
|
|
cards.push({
|
|
type: "button",
|
|
entity: entity.entity_id,
|
|
show_state: true,
|
|
tap_action: {
|
|
action: "toggle",
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
return {
|
|
"type": "panel",
|
|
"cards": [
|
|
{
|
|
type: "grid",
|
|
columns: 4,
|
|
cards,
|
|
},
|
|
],
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
customElements.define("ll-strategy-device-buttons", StrategyDeviceButtons);
|