Merge branch '116-fix-bug-eslint' into 'dev'
fix bugs eslint Closes #116 See merge request sa4-2020/the-sanmarinoes/frontend!153
This commit is contained in:
commit
c583c0e73e
2 changed files with 67 additions and 28 deletions
|
@ -323,6 +323,38 @@ class AutomationSaveModal extends Component {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkRange(deviceKind, devicesWithPercentage, trigger, error, device) {
|
||||||
|
if (!trigger.device || !trigger.operand || !trigger.value) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
if (trigger.value < 0) {
|
||||||
|
error.message = 'Values cannot be negative';
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
// If the device's range is a percentage, values cannot exceed 100
|
||||||
|
if (
|
||||||
|
devicesWithPercentage.includes(deviceKind)
|
||||||
|
&& trigger.value > 100
|
||||||
|
) {
|
||||||
|
error.message = "The value can't exceed 100, as it's a percentage";
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
deviceKind === 'sensor'
|
||||||
|
&& device.sensor === 'HUMIDITY'
|
||||||
|
&& trigger.value > 100
|
||||||
|
) {
|
||||||
|
error.message = "The value can't exceed 100, as it's a percentage";
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkBool(trigger, error) {
|
||||||
|
if (!trigger.device || trigger.on === null || trigger.on === undefined) return error;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
_checkNewTrigger(trigger, isCondition = false) {
|
_checkNewTrigger(trigger, isCondition = false) {
|
||||||
const error = {
|
const error = {
|
||||||
result: false,
|
result: false,
|
||||||
|
@ -347,32 +379,28 @@ class AutomationSaveModal extends Component {
|
||||||
const devicesWithPercentage = ['dimmableLight', 'curtains', 'knobDimmer'];
|
const devicesWithPercentage = ['dimmableLight', 'curtains', 'knobDimmer'];
|
||||||
|
|
||||||
switch (isCondition ? conditionKind : triggerKind) {
|
switch (isCondition ? conditionKind : triggerKind) {
|
||||||
case 'booleanTrigger' || 'booleanCondition':
|
case 'booleanTrigger':
|
||||||
if (!trigger.device || trigger.on === null || trigger.on === undefined) return error;
|
const checkBoolTrigger = this.checkBool(trigger, error);
|
||||||
|
if (checkBoolTrigger) {
|
||||||
|
return checkBoolTrigger;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'rangeTrigger' || 'rangeCondition':
|
case 'booleanCondition':
|
||||||
if (!trigger.device || !trigger.operand || !trigger.value) {
|
const checkBoolCond = this.checkBool(trigger, error);
|
||||||
return error;
|
if (checkBoolCond) {
|
||||||
|
return checkBoolCond;
|
||||||
}
|
}
|
||||||
if (trigger.value < 0) {
|
break;
|
||||||
error.message = 'Values cannot be negative';
|
case 'rangeTrigger':
|
||||||
return error;
|
const checkRangeTrigger = this.checkRange(deviceKind, devicesWithPercentage, trigger, error, device);
|
||||||
|
if (checkRangeTrigger) {
|
||||||
|
return checkRangeTrigger;
|
||||||
}
|
}
|
||||||
// If the device's range is a percentage, values cannot exceed 100
|
break;
|
||||||
if (
|
case 'rangeCondition':
|
||||||
devicesWithPercentage.includes(deviceKind)
|
const checkRangeCond = this.checkRange(deviceKind, devicesWithPercentage, trigger, error, device);
|
||||||
&& trigger.value > 100
|
if (checkRangeCond) {
|
||||||
) {
|
return checkRangeCond;
|
||||||
error.message = "The value can't exceed 100, as it's a percentage";
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
deviceKind === 'sensor'
|
|
||||||
&& device.sensor === 'HUMIDITY'
|
|
||||||
&& trigger.value > 100
|
|
||||||
) {
|
|
||||||
error.message = "The value can't exceed 100, as it's a percentage";
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'thermostatCondition':
|
case 'thermostatCondition':
|
||||||
|
@ -462,12 +490,24 @@ class AutomationSaveModal extends Component {
|
||||||
return this.props.scenes.filter((e) => e.name.includes(this.scenesFilter));
|
return this.props.scenes.filter((e) => e.name.includes(this.scenesFilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generateBoolKey(trigger) {
|
||||||
|
return `${trigger.device}${trigger.on}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
generateRangeKey(trigger) {
|
||||||
|
return `${trigger.device}${trigger.operand}${trigger.value}`;
|
||||||
|
}
|
||||||
|
|
||||||
_generateKey = (trigger, isCondition = false) => {
|
_generateKey = (trigger, isCondition = false) => {
|
||||||
switch (isCondition ? this.conditionKind(trigger) : this.triggerKind(trigger)) {
|
switch (isCondition ? this.conditionKind(trigger) : this.triggerKind(trigger)) {
|
||||||
case 'booleanTrigger' || 'booleanCondition':
|
case 'booleanTrigger':
|
||||||
return `${trigger.device}${trigger.on}`;
|
return this.generateBoolKey(trigger);
|
||||||
case 'rangeTrigger' || 'rangeCondition':
|
case 'booleanCondition':
|
||||||
return `${trigger.device}${trigger.operand}${trigger.value}`;
|
return this.generateBoolKey(trigger);
|
||||||
|
case 'rangeTrigger':
|
||||||
|
return this.generateRangeKey(trigger);
|
||||||
|
case 'rangeCondition':
|
||||||
|
return this.generateRangeKey(trigger);
|
||||||
case 'thermostatCondition':
|
case 'thermostatCondition':
|
||||||
return `${trigger.device}${trigger.operand}${trigger.mode}`;
|
return `${trigger.device}${trigger.operand}${trigger.mode}`;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -578,7 +578,6 @@ export const RemoteService = {
|
||||||
);
|
);
|
||||||
const rangeConditionList = conditionList.filter((condition) => 'operand' in condition && 'value' in condition);
|
const rangeConditionList = conditionList.filter((condition) => 'operand' in condition && 'value' in condition);
|
||||||
const booleanConditionList = conditionList.filter((condition) => 'on' in condition);
|
const booleanConditionList = conditionList.filter((condition) => 'on' in condition);
|
||||||
debugger;
|
|
||||||
const thermostatConditionList = conditionList.filter((condition) => 'operand' in condition && 'mode' in condition);
|
const thermostatConditionList = conditionList.filter((condition) => 'operand' in condition && 'mode' in condition);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue