@@ -41,9 +62,64 @@ export default class DeviceTrigger extends Component
{
hass={hass}
label="Trigger"
/>
+ {extraFieldsData && (
+
+ )}
);
}
+
+ public componentDidMount() {
+ if (!this.state.capabilities) {
+ this._getCapabilities();
+ }
+ if (this.props.trigger) {
+ this._origTrigger = this.props.trigger;
+ }
+ }
+
+ public componentDidUpdate(prevProps) {
+ if (prevProps.trigger !== this.props.trigger) {
+ this._getCapabilities();
+ }
+ }
+
+ private async _getCapabilities() {
+ const trigger = this.props.trigger;
+
+ const capabilities = trigger.domain
+ ? await fetchDeviceTriggerCapabilities(this.props.hass, trigger)
+ : null;
+ this.setState({ ...this.state, capabilities });
+ }
+
+ private _extraFieldsChanged(ev) {
+ if (!ev.detail.path) {
+ return;
+ }
+ const item = ev.detail.path.replace("data.", "");
+ const value = ev.detail.value || undefined;
+
+ this.props.onChange(this.props.index, {
+ ...this.props.trigger,
+ [item]: value,
+ });
+ }
+
+ private _extraFieldsComputeLabelCallback(localize) {
+ // Returns a callback for ha-form to calculate labels per schema object
+ return (schema) =>
+ localize(
+ `ui.panel.config.automation.editor.triggers.type.device.extra_fields.${
+ schema.name
+ }`
+ ) || schema.name;
+ }
}
(DeviceTrigger as any).defaultConfig = {
diff --git a/src/panels/lovelace/cards/hui-picture-glance-card.ts b/src/panels/lovelace/cards/hui-picture-glance-card.ts
index 58992f7afa..abc489358c 100644
--- a/src/panels/lovelace/cards/hui-picture-glance-card.ts
+++ b/src/panels/lovelace/cards/hui-picture-glance-card.ts
@@ -27,6 +27,7 @@ import { longPress } from "../common/directives/long-press-directive";
import { processConfigEntities } from "../common/process-config-entities";
import { handleClick } from "../common/handle-click";
import { PictureGlanceCardConfig, ConfigEntity } from "./types";
+import { hasConfigOrEntityChanged } from "../common/has-changed";
const STATES_OFF = new Set(["closed", "locked", "not_home", "off"]);
@@ -86,19 +87,16 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
}
protected shouldUpdate(changedProps: PropertyValues): boolean {
- if (changedProps.has("_config")) {
+ if (hasConfigOrEntityChanged(this, changedProps)) {
return true;
}
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
- if (!oldHass) {
- return true;
- }
if (this._entitiesDialog) {
for (const entity of this._entitiesDialog) {
if (
- oldHass.states[entity.entity] !== this.hass!.states[entity.entity]
+ oldHass!.states[entity.entity] !== this.hass!.states[entity.entity]
) {
return true;
}
@@ -108,7 +106,7 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
if (this._entitiesToggle) {
for (const entity of this._entitiesToggle) {
if (
- oldHass.states[entity.entity] !== this.hass!.states[entity.entity]
+ oldHass!.states[entity.entity] !== this.hass!.states[entity.entity]
) {
return true;
}
diff --git a/src/translations/en.json b/src/translations/en.json
index 8af25be437..e2bb1457e7 100644
--- a/src/translations/en.json
+++ b/src/translations/en.json
@@ -722,7 +722,12 @@
"type_select": "Trigger type",
"type": {
"device": {
- "label": "Device"
+ "label": "Device",
+ "extra_fields": {
+ "above": "Above",
+ "below": "Below",
+ "for": "Duration"
+ }
},
"event": {
"label": "Event",