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:
Andrea Brites Marto 2020-05-21 16:49:44 +02:00
commit c583c0e73e
2 changed files with 67 additions and 28 deletions

View file

@ -323,6 +323,38 @@ class AutomationSaveModal extends Component {
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) {
const error = {
result: false,
@ -347,32 +379,28 @@ class AutomationSaveModal extends Component {
const devicesWithPercentage = ['dimmableLight', 'curtains', 'knobDimmer'];
switch (isCondition ? conditionKind : triggerKind) {
case 'booleanTrigger' || 'booleanCondition':
if (!trigger.device || trigger.on === null || trigger.on === undefined) return error;
case 'booleanTrigger':
const checkBoolTrigger = this.checkBool(trigger, error);
if (checkBoolTrigger) {
return checkBoolTrigger;
}
break;
case 'rangeTrigger' || 'rangeCondition':
if (!trigger.device || !trigger.operand || !trigger.value) {
return error;
case 'booleanCondition':
const checkBoolCond = this.checkBool(trigger, error);
if (checkBoolCond) {
return checkBoolCond;
}
if (trigger.value < 0) {
error.message = 'Values cannot be negative';
return error;
break;
case 'rangeTrigger':
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
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;
break;
case 'rangeCondition':
const checkRangeCond = this.checkRange(deviceKind, devicesWithPercentage, trigger, error, device);
if (checkRangeCond) {
return checkRangeCond;
}
break;
case 'thermostatCondition':
@ -462,12 +490,24 @@ class AutomationSaveModal extends Component {
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) => {
switch (isCondition ? this.conditionKind(trigger) : this.triggerKind(trigger)) {
case 'booleanTrigger' || 'booleanCondition':
return `${trigger.device}${trigger.on}`;
case 'rangeTrigger' || 'rangeCondition':
return `${trigger.device}${trigger.operand}${trigger.value}`;
case 'booleanTrigger':
return this.generateBoolKey(trigger);
case 'booleanCondition':
return this.generateBoolKey(trigger);
case 'rangeTrigger':
return this.generateRangeKey(trigger);
case 'rangeCondition':
return this.generateRangeKey(trigger);
case 'thermostatCondition':
return `${trigger.device}${trigger.operand}${trigger.mode}`;
default:

View file

@ -578,7 +578,6 @@ export const RemoteService = {
);
const rangeConditionList = conditionList.filter((condition) => '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);