mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix device automations from device page (#17145)
This commit is contained in:
parent
21caac4240
commit
6a2cad1af3
@ -1,11 +1,9 @@
|
|||||||
import { consume } from "@lit-labs/context";
|
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { property, state } from "lit/decorators";
|
import { property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import "../../../../components/ha-chip";
|
import "../../../../components/ha-chip";
|
||||||
import "../../../../components/ha-chip-set";
|
import "../../../../components/ha-chip-set";
|
||||||
import { showAutomationEditor } from "../../../../data/automation";
|
import { showAutomationEditor } from "../../../../data/automation";
|
||||||
import { fullEntitiesContext } from "../../../../data/context";
|
|
||||||
import {
|
import {
|
||||||
DeviceAction,
|
DeviceAction,
|
||||||
DeviceAutomation,
|
DeviceAutomation,
|
||||||
@ -32,11 +30,9 @@ export abstract class HaDeviceAutomationCard<
|
|||||||
|
|
||||||
@property({ attribute: false }) public automations: T[] = [];
|
@property({ attribute: false }) public automations: T[] = [];
|
||||||
|
|
||||||
@state() public _showSecondary = false;
|
@property({ attribute: false }) entityReg?: EntityRegistryEntry[];
|
||||||
|
|
||||||
@state()
|
@state() public _showSecondary = false;
|
||||||
@consume({ context: fullEntitiesContext, subscribe: true })
|
|
||||||
_entityReg!: EntityRegistryEntry[];
|
|
||||||
|
|
||||||
abstract headerKey: Parameters<typeof this.hass.localize>[0];
|
abstract headerKey: Parameters<typeof this.hass.localize>[0];
|
||||||
|
|
||||||
@ -67,7 +63,7 @@ export abstract class HaDeviceAutomationCard<
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (this.automations.length === 0) {
|
if (this.automations.length === 0 || !this.entityReg) {
|
||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
const automations = this._showSecondary
|
const automations = this._showSecondary
|
||||||
@ -89,7 +85,7 @@ export abstract class HaDeviceAutomationCard<
|
|||||||
>
|
>
|
||||||
${this._localizeDeviceAutomation(
|
${this._localizeDeviceAutomation(
|
||||||
this.hass,
|
this.hass,
|
||||||
this._entityReg,
|
this.entityReg!,
|
||||||
automation
|
automation
|
||||||
)}
|
)}
|
||||||
</ha-chip>
|
</ha-chip>
|
||||||
|
@ -109,6 +109,7 @@ export class DialogDeviceAutomation extends LitElement {
|
|||||||
<ha-device-triggers-card
|
<ha-device-triggers-card
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.automations=${this._triggers}
|
.automations=${this._triggers}
|
||||||
|
.entityReg=${this._params.entityReg}
|
||||||
></ha-device-triggers-card>
|
></ha-device-triggers-card>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
@ -117,6 +118,7 @@ export class DialogDeviceAutomation extends LitElement {
|
|||||||
<ha-device-conditions-card
|
<ha-device-conditions-card
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.automations=${this._conditions}
|
.automations=${this._conditions}
|
||||||
|
.entityReg=${this._params.entityReg}
|
||||||
></ha-device-conditions-card>
|
></ha-device-conditions-card>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
@ -126,6 +128,7 @@ export class DialogDeviceAutomation extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.automations=${this._actions}
|
.automations=${this._actions}
|
||||||
.script=${this._params.script}
|
.script=${this._params.script}
|
||||||
|
.entityReg=${this._params.entityReg}
|
||||||
></ha-device-actions-card>
|
></ha-device-actions-card>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { DeviceRegistryEntry } from "../../../../data/device_registry";
|
import { DeviceRegistryEntry } from "../../../../data/device_registry";
|
||||||
|
import { EntityRegistryEntry } from "../../../../data/entity_registry";
|
||||||
|
|
||||||
export interface DeviceAutomationDialogParams {
|
export interface DeviceAutomationDialogParams {
|
||||||
device: DeviceRegistryEntry;
|
device: DeviceRegistryEntry;
|
||||||
|
entityReg: EntityRegistryEntry[];
|
||||||
script?: boolean;
|
script?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ import {
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
|
import { consume } from "@lit-labs/context";
|
||||||
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||||
import { SENSOR_ENTITIES } from "../../../common/const";
|
import { SENSOR_ENTITIES } from "../../../common/const";
|
||||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||||
@ -84,6 +85,7 @@ import {
|
|||||||
loadDeviceRegistryDetailDialog,
|
loadDeviceRegistryDetailDialog,
|
||||||
showDeviceRegistryDetailDialog,
|
showDeviceRegistryDetailDialog,
|
||||||
} from "./device-registry-detail/show-dialog-device-registry-detail";
|
} from "./device-registry-detail/show-dialog-device-registry-detail";
|
||||||
|
import { fullEntitiesContext } from "../../../data/context";
|
||||||
|
|
||||||
export interface EntityRegistryStateEntry extends EntityRegistryEntry {
|
export interface EntityRegistryStateEntry extends EntityRegistryEntry {
|
||||||
stateName?: string | null;
|
stateName?: string | null;
|
||||||
@ -137,6 +139,10 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
|
|
||||||
@state() private _deviceAlerts?: DeviceAlert[];
|
@state() private _deviceAlerts?: DeviceAlert[];
|
||||||
|
|
||||||
|
@state()
|
||||||
|
@consume({ context: fullEntitiesContext, subscribe: true })
|
||||||
|
_entityReg!: EntityRegistryEntry[];
|
||||||
|
|
||||||
private _logbookTime = { recent: 86400 };
|
private _logbookTime = { recent: 86400 };
|
||||||
|
|
||||||
private _device = memoizeOne(
|
private _device = memoizeOne(
|
||||||
@ -422,12 +428,13 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
)
|
)
|
||||||
: this.hass.localize(
|
: this.hass.localize(
|
||||||
"ui.panel.config.devices.automation.create",
|
"ui.panel.config.devices.automation.create",
|
||||||
"type",
|
{
|
||||||
this.hass.localize(
|
type: this.hass.localize(
|
||||||
`ui.panel.config.devices.type.${
|
`ui.panel.config.devices.type.${
|
||||||
device.entry_type || "device"
|
device.entry_type || "device"
|
||||||
}`
|
}`
|
||||||
)
|
),
|
||||||
|
}
|
||||||
)}
|
)}
|
||||||
.path=${mdiPlusCircle}
|
.path=${mdiPlusCircle}
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
@ -1180,6 +1187,7 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
private _showScriptDialog() {
|
private _showScriptDialog() {
|
||||||
showDeviceAutomationDialog(this, {
|
showDeviceAutomationDialog(this, {
|
||||||
device: this._device(this.deviceId, this.devices)!,
|
device: this._device(this.deviceId, this.devices)!,
|
||||||
|
entityReg: this._entityReg,
|
||||||
script: true,
|
script: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1187,6 +1195,7 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
private _showAutomationDialog() {
|
private _showAutomationDialog() {
|
||||||
showDeviceAutomationDialog(this, {
|
showDeviceAutomationDialog(this, {
|
||||||
device: this._device(this.deviceId, this.devices)!,
|
device: this._device(this.deviceId, this.devices)!,
|
||||||
|
entityReg: this._entityReg,
|
||||||
script: false,
|
script: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user