From 41c61a289553239f4e87639e0bfae4d9ce145ee2 Mon Sep 17 00:00:00 2001 From: Zack Barett Date: Thu, 26 May 2022 15:05:17 -0500 Subject: [PATCH] Update Narrow Order on Device Page (#12801) Co-authored-by: Bram Kragten --- .../config/devices/ha-config-device-page.ts | 532 +++++++++--------- 1 file changed, 263 insertions(+), 269 deletions(-) diff --git a/src/panels/config/devices/ha-config-device-page.ts b/src/panels/config/devices/ha-config-device-page.ts index cfca8b845e..e5cb27109d 100644 --- a/src/panels/config/devices/ha-config-device-page.ts +++ b/src/panels/config/devices/ha-config-device-page.ts @@ -332,6 +332,267 @@ export class HaConfigDevicePage extends LitElement { this._renderIntegrationInfo(device, integrations, deviceInfo); + const automationCard = isComponentLoaded(this.hass, "automation") + ? html` + +

+ ${this.hass.localize( + "ui.panel.config.devices.automation.automations_heading" + )} + +

+ ${this._related?.automation?.length + ? html` +
+ ${this._related.automation.map((automation) => { + const entityState = this.hass.states[automation]; + return entityState + ? html`
+ + + + ${computeStateName(entityState)} + + + + + ${!entityState.attributes.id + ? html` + + ${this.hass.localize( + "ui.panel.config.devices.cant_edit" + )} + + ` + : ""} +
` + : ""; + })} +
+ ` + : html` +
+ ${this.hass.localize( + "ui.panel.config.devices.add_prompt", + "name", + this.hass.localize( + "ui.panel.config.devices.automation.automations" + ), + "type", + this.hass.localize( + `ui.panel.config.devices.type.${ + device.entry_type || "device" + }` + ) + )} +
+ `} +
+ ` + : ""; + + const sceneCard = + isComponentLoaded(this.hass, "scene") && entities.length + ? html` + +

+ ${this.hass.localize( + "ui.panel.config.devices.scene.scenes_heading" + )} + + +

+ ${this._related?.scene?.length + ? html` +
+ ${this._related.scene.map((scene) => { + const entityState = this.hass.states[scene]; + return entityState + ? html` +
+ + + + ${computeStateName(entityState)} + + + + + ${!entityState.attributes.id + ? html` + + ${this.hass.localize( + "ui.panel.config.devices.cant_edit" + )} + + ` + : ""} +
+ ` + : ""; + })} +
+ ` + : html` +
+ ${this.hass.localize( + "ui.panel.config.devices.add_prompt", + "name", + this.hass.localize( + "ui.panel.config.devices.scene.scenes" + ), + "type", + this.hass.localize( + `ui.panel.config.devices.type.${ + device.entry_type || "device" + }` + ) + )} +
+ `} +
+ ` + : ""; + + const scriptCard = isComponentLoaded(this.hass, "script") + ? html` + +

+ ${this.hass.localize( + "ui.panel.config.devices.script.scripts_heading" + )} + +

+ ${this._related?.script?.length + ? html` +
+ ${this._related.script.map((script) => { + const entityState = this.hass.states[script]; + return entityState + ? html` + + + + ${computeStateName(entityState)} + + + + + ` + : ""; + })} +
+ ` + : html` +
+ ${this.hass.localize( + "ui.panel.config.devices.add_prompt", + "name", + this.hass.localize( + "ui.panel.config.devices.script.scripts" + ), + "type", + this.hass.localize( + `ui.panel.config.devices.type.${ + device.entry_type || "device" + }` + ) + )} +
+ `} +
+ ` + : ""; + return html` - - ${ - isComponentLoaded(this.hass, "automation") - ? html` - -

- ${this.hass.localize( - "ui.panel.config.devices.automation.automations_heading" - )} - -

- ${this._related?.automation?.length - ? html` -
- ${this._related.automation.map((automation) => { - const entityState = - this.hass.states[automation]; - return entityState - ? html`
- - - - ${computeStateName(entityState)} - - - - - ${!entityState.attributes.id - ? html` - - ${this.hass.localize( - "ui.panel.config.devices.cant_edit" - )} - - ` - : ""} -
` - : ""; - })} -
- ` - : html` -
- ${this.hass.localize( - "ui.panel.config.devices.add_prompt", - "name", - this.hass.localize( - "ui.panel.config.devices.automation.automations" - ), - "type", - this.hass.localize( - `ui.panel.config.devices.type.${ - device.entry_type || "device" - }` - ) - )} -
- `} -
- ` - : "" - } - ${ - isComponentLoaded(this.hass, "scene") && entities.length - ? html` - -

- ${this.hass.localize( - "ui.panel.config.devices.scene.scenes_heading" - )} - - -

- ${this._related?.scene?.length - ? html` -
- ${this._related.scene.map((scene) => { - const entityState = this.hass.states[scene]; - return entityState - ? html` -
- - - - ${computeStateName(entityState)} - - - - - ${!entityState.attributes.id - ? html` - - ${this.hass.localize( - "ui.panel.config.devices.cant_edit" - )} - - ` - : ""} -
- ` - : ""; - })} -
- ` - : html` -
- ${this.hass.localize( - "ui.panel.config.devices.add_prompt", - "name", - this.hass.localize( - "ui.panel.config.devices.scene.scenes" - ), - "type", - this.hass.localize( - `ui.panel.config.devices.type.${ - device.entry_type || "device" - }` - ) - )} -
- `} -
- ` - : "" - } - ${ - isComponentLoaded(this.hass, "script") - ? html` - -

- ${this.hass.localize( - "ui.panel.config.devices.script.scripts_heading" - )} - -

- ${this._related?.script?.length - ? html` -
- ${this._related.script.map((script) => { - const entityState = this.hass.states[script]; - return entityState - ? html` - - - - ${computeStateName(entityState)} - - - - - ` - : ""; - })} -
- ` - : html` -
- ${this.hass.localize( - "ui.panel.config.devices.add_prompt", - "name", - this.hass.localize( - "ui.panel.config.devices.script.scripts" - ), - "type", - this.hass.localize( - `ui.panel.config.devices.type.${ - device.entry_type || "device" - }` - ) - )} -
- `} -
- ` - : "" - } + ${!this.narrow ? [automationCard, sceneCard, scriptCard] : ""}
${["control", "sensor", "config", "diagnostic"].map((category) => @@ -798,6 +791,7 @@ export class HaConfigDevicePage extends LitElement { )}
+ ${this.narrow ? [automationCard, sceneCard, scriptCard] : ""} ${ isComponentLoaded(this.hass, "logbook") ? html`