@@ -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/translations/en.json b/src/translations/en.json
index 5e082f51f2..4129c53f58 100755
--- a/src/translations/en.json
+++ b/src/translations/en.json
@@ -737,7 +737,12 @@
"type_select": "Trigger type",
"type": {
"device": {
- "label": "Device"
+ "label": "Device",
+ "extra_fields": {
+ "above": "Above",
+ "below": "Below",
+ "for": "Duration"
+ }
},
"event": {
"label": "Event",