diff --git a/smart-hut/src/components/dashboard/AutomationCreationModal.js b/smart-hut/src/components/dashboard/AutomationCreationModal.js
index 4780e9f..75c3168 100644
--- a/smart-hut/src/components/dashboard/AutomationCreationModal.js
+++ b/smart-hut/src/components/dashboard/AutomationCreationModal.js
@@ -49,8 +49,21 @@ const deviceStateOptions = [
{ key: 'on', text: 'on', value: true },
];
+const thermostatOptions = [
+ { key: 'HEATING', text: 'HEATING', value: 'HEATING' },
+ { key: 'COOLING', text: 'COOLING', value: 'COOLING' },
+ { key: 'IDLE', text: 'IDLE', value: 'IDLE' },
+ { key: 'OFF', text: 'OFF', value: 'OFF' },
+];
+
+const thermostatOperands = [
+ { key: 'EQUAL', text: '=', value: 'EQUAL' },
+ { key: 'NOTEQUAL', text: '\u2260', value: 'NOTEQUAL' },
+];
+
const CreateTrigger = (props) => {
const [activeOperand, setActiveOperand] = useState(true);
+ const [activeThermostat, setActiveThermostat] = useState(false);
const operandsRef = useRef(null);
const valuesRef = useRef(null);
const notAdmitedDevices = ['buttonDimmer'];
@@ -72,7 +85,7 @@ const CreateTrigger = (props) => {
const onChange = (e, val) => {
props.inputChange(val);
setActiveOperand(hasOperand.has(props.devices[val.value].kind));
-
+ setActiveThermostat(props.devices[val.value].kind === 'thermostat');
if (operandsRef.current) operandsRef.current.setValue('');
if (valuesRef.current) valuesRef.current.inputRef.current.valueAsNumber = undefined;
};
@@ -92,30 +105,55 @@ const CreateTrigger = (props) => {
placeholder="Device"
/>
- {activeOperand ? (
- <>
-
- props.inputChange(val)}
- ref={operandsRef}
- name="operand"
- compact
- selection
- options={operands}
- />
-
-
- {
+ {
+ activeThermostat ? (
+ <>
+
+ props.inputChange(val)}
+ ref={operandsRef}
+ name="operand"
+ compact
+ selection
+ options={thermostatOperands}
+ />
+
+
+ props.inputChange(val)}
+ placeholder="State"
+ name="mode"
+ compact
+ selection
+ options={thermostatOptions}
+ />
+
+ >
+)
+ : activeOperand ? (
+ <>
+
+ props.inputChange(val)}
+ ref={operandsRef}
+ name="operand"
+ compact
+ selection
+ options={operands}
+ />
+
+
+ {
props.inputChange(val);
}}
- ref={valuesRef}
- name="value"
- type="number"
- placeholder="Value"
- />
-
- >
+ ref={valuesRef}
+ name="value"
+ type="number"
+ placeholder="Value"
+ />
+
+ >
) : (
{
options={deviceStateOptions}
/>
- )}
+ )
+}
@@ -165,7 +204,9 @@ const SceneItem = (props) => {
const Trigger = ({
deviceName, trigger, onRemove, index,
}) => {
- const { operand, value, on } = trigger;
+ const {
+ operand, value, on, mode,
+} = trigger;
let symbol;
if (operand) {
symbol = operands.filter((opt) => opt.key === operand)[0].text;
@@ -175,7 +216,7 @@ const Trigger = ({
e.name.includes(this.scenesFilter));
}
- _generateKey = (trigger) => {
- switch (this.triggerKind(trigger)) {
- case 'booleanTrigger':
+ _generateKey = (trigger, isCondition = false) => {
+ switch (isCondition ? this.conditionKind(trigger) : this.triggerKind(trigger)) {
+ case 'booleanTrigger' || 'booleanCondition':
return `${trigger.device}${trigger.on}`;
- case 'rangeTrigger':
+ case 'rangeTrigger' || 'rangeCondition':
return `${trigger.device}${trigger.operand}${trigger.value}`;
+ case 'thermostatCondition':
+ return `${trigger.device}${trigger.operand}${trigger.mode}`;
default:
throw new Error('theoretically unreachable statement');
}
@@ -670,7 +721,7 @@ class AutomationSaveModal extends Component {
const deviceName = this.deviceList.filter(
(d) => d.id === condition.device,
)[0].name;
- const key = this._generateKey(condition);
+ const key = this._generateKey(condition, true);
return (
'operand' in condition && 'value' in condition);
const booleanConditionList = conditionList.filter((condition) => 'on' in condition);
+ debugger;
const thermostatConditionList = conditionList.filter((condition) => 'operand' in condition && 'mode' in condition);