@@ -41,9 +59,65 @@ export default class DeviceTrigger extends Component
{
hass={hass}
label="Trigger"
/>
+ {this.state.capabilities && this.state.capabilities.extra_fields && (
+
+ )}
);
}
+
+ public componentDidMount() {
+ const hass = this.props.hass;
+ const trigger = this.props.trigger;
+
+ if (!this.state.capabilities && trigger.domain) {
+ fetchDeviceTriggerCapabilities(hass, trigger).then((capabilities) => {
+ 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;
+ }
+
+ private _extraFieldsComputeSuffixCallback() {
+ // Returns a callback for ha-form to calculate suffixes per schema object
+ return (schema) => {
+ let description = "";
+ if (schema.description) {
+ description = schema.description.unit_of_measurement || "";
+ }
+ return description;
+ };
+ }
}
(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",