runned beautifier
This commit is contained in:
parent
b9be38d467
commit
5b2bd7cc48
6 changed files with 981 additions and 1029 deletions
|
@ -106,7 +106,7 @@ class NewDevice extends Component {
|
||||||
switch: "New switch",
|
switch: "New switch",
|
||||||
buttonDimmer: "New button dimmer",
|
buttonDimmer: "New button dimmer",
|
||||||
knobDimmer: "New knob dimmer",
|
knobDimmer: "New knob dimmer",
|
||||||
securityCamera: "New security camera"
|
securityCamera: "New security camera",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.state.deviceName === "") {
|
if (this.state.deviceName === "") {
|
||||||
|
@ -192,7 +192,7 @@ class NewDevice extends Component {
|
||||||
text: "Security Camera",
|
text: "Security Camera",
|
||||||
value: "securityCamera",
|
value: "securityCamera",
|
||||||
image: { avatar: true, src: "/img/plusMinus.svg" },
|
image: { avatar: true, src: "/img/plusMinus.svg" },
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
const sensorOptions = [
|
const sensorOptions = [
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,10 +98,7 @@ const Endpoint = {
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
localStorage.setItem("token", res.data.jwttoken);
|
localStorage.setItem("token", res.data.jwttoken);
|
||||||
localStorage.setItem(
|
localStorage.setItem("exp", new Date().getTime() + 5 * 60 * 60 * 1000);
|
||||||
"exp",
|
|
||||||
new Date().getTime() + 5 * 60 * 60 * 1000
|
|
||||||
);
|
|
||||||
return res.data.jwttoken;
|
return res.data.jwttoken;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -302,10 +299,7 @@ export const RemoteService = {
|
||||||
fetchDevices: (roomId = null) => {
|
fetchDevices: (roomId = null) => {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
return Endpoint.get(roomId ? `/room/${roomId}/device` : "/device")
|
return Endpoint.get(roomId ? `/room/${roomId}/device` : "/device")
|
||||||
.then(
|
.then((res) => void dispatch(actions.devicesUpdate(roomId, res.data)))
|
||||||
(res) =>
|
|
||||||
void dispatch(actions.devicesUpdate(roomId, res.data))
|
|
||||||
)
|
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(`Fetch devices roomId=${roomId} error`, err);
|
console.error(`Fetch devices roomId=${roomId} error`, err);
|
||||||
throw new RemoteError(["Network error"]);
|
throw new RemoteError(["Network error"]);
|
||||||
|
@ -321,8 +315,7 @@ export const RemoteService = {
|
||||||
fetchAutomations: () => {
|
fetchAutomations: () => {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
return Endpoint.get("/automation/")
|
return Endpoint.get("/automation/")
|
||||||
.then(
|
.then((res) => {
|
||||||
(res) => {
|
|
||||||
const length = res.data.length;
|
const length = res.data.length;
|
||||||
const automations = [];
|
const automations = [];
|
||||||
|
|
||||||
|
@ -332,30 +325,26 @@ export const RemoteService = {
|
||||||
name,
|
name,
|
||||||
id,
|
id,
|
||||||
triggers: [],
|
triggers: [],
|
||||||
scenes: []
|
scenes: [],
|
||||||
}
|
};
|
||||||
|
|
||||||
return Endpoint.get(`/booleanTrigger/${id}`)
|
return Endpoint.get(`/booleanTrigger/${id}`).then((res) => {
|
||||||
.then(res => {
|
|
||||||
automation.triggers.push(...res.data);
|
automation.triggers.push(...res.data);
|
||||||
return Endpoint.get(`/rangeTrigger/${id}`)
|
return Endpoint.get(`/rangeTrigger/${id}`).then((res) => {
|
||||||
.then(res => {
|
|
||||||
automation.triggers.push(...res.data);
|
automation.triggers.push(...res.data);
|
||||||
return Endpoint.get(`/scenePriority/${id}`)
|
return Endpoint.get(`/scenePriority/${id}`).then((res) => {
|
||||||
.then(res => {
|
|
||||||
automation.scenes.push(...res.data);
|
automation.scenes.push(...res.data);
|
||||||
automations.push(automation);
|
automations.push(automation);
|
||||||
if ((index + 1) === length) {
|
if (index + 1 === length) {
|
||||||
return void dispatch(actions.automationsUpdate(automations));
|
return void dispatch(
|
||||||
|
actions.automationsUpdate(automations)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
)
|
});
|
||||||
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(`Fetch automations error`, err);
|
console.error(`Fetch automations error`, err);
|
||||||
throw new RemoteError(["Network error"]);
|
throw new RemoteError(["Network error"]);
|
||||||
|
@ -374,15 +363,9 @@ export const RemoteService = {
|
||||||
fetchStates: (sceneId) => {
|
fetchStates: (sceneId) => {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
return Endpoint.get(`/scene/${sceneId}/states`)
|
return Endpoint.get(`/scene/${sceneId}/states`)
|
||||||
.then(
|
.then((res) => void dispatch(actions.statesUpdate(sceneId, res.data)))
|
||||||
(res) =>
|
|
||||||
void dispatch(actions.statesUpdate(sceneId, res.data))
|
|
||||||
)
|
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(
|
console.error(`Fetch devices sceneId=${sceneId} error`, err);
|
||||||
`Fetch devices sceneId=${sceneId} error`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
throw new RemoteError(["Network error"]);
|
throw new RemoteError(["Network error"]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -467,7 +450,6 @@ export const RemoteService = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates/Updates an automation with the given data. If
|
* Creates/Updates an automation with the given data. If
|
||||||
* data.id is truthy, then a update call is performed,
|
* data.id is truthy, then a update call is performed,
|
||||||
|
@ -487,11 +469,15 @@ export const RemoteService = {
|
||||||
let urlRangeTrigger = "/rangeTrigger";
|
let urlRangeTrigger = "/rangeTrigger";
|
||||||
let urlScenePriority = "/scenePriority";
|
let urlScenePriority = "/scenePriority";
|
||||||
|
|
||||||
let rangeTriggerList = triggerList.filter(trigger => trigger.hasOwnProperty("operand"));
|
let rangeTriggerList = triggerList.filter((trigger) =>
|
||||||
let booleanTriggerList = triggerList.filter(trigger => !trigger.hasOwnProperty("operand"));
|
trigger.hasOwnProperty("operand")
|
||||||
|
);
|
||||||
|
let booleanTriggerList = triggerList.filter(
|
||||||
|
(trigger) => !trigger.hasOwnProperty("operand")
|
||||||
|
);
|
||||||
|
|
||||||
return Endpoint["post"](urlAutomation, {}, automation)
|
return Endpoint["post"](urlAutomation, {}, automation).then(
|
||||||
.then(async automationRes => {
|
async (automationRes) => {
|
||||||
const { id } = automationRes.data;
|
const { id } = automationRes.data;
|
||||||
// Introduce the range triggers in the automation
|
// Introduce the range triggers in the automation
|
||||||
for (let t of rangeTriggerList) {
|
for (let t of rangeTriggerList) {
|
||||||
|
@ -499,9 +485,9 @@ export const RemoteService = {
|
||||||
automationId: id,
|
automationId: id,
|
||||||
deviceId: t.device,
|
deviceId: t.device,
|
||||||
operator: t.operand,
|
operator: t.operand,
|
||||||
range: t.value
|
range: t.value,
|
||||||
};
|
};
|
||||||
let resRange = await Endpoint.post(urlRangeTrigger, {}, trigger)
|
let resRange = await Endpoint.post(urlRangeTrigger, {}, trigger);
|
||||||
automation.triggers.push(resRange.data);
|
automation.triggers.push(resRange.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,9 +495,13 @@ export const RemoteService = {
|
||||||
const trigger = {
|
const trigger = {
|
||||||
automationId: id,
|
automationId: id,
|
||||||
deviceId: t.device,
|
deviceId: t.device,
|
||||||
on: t.value
|
on: t.value,
|
||||||
};
|
};
|
||||||
let resBoolean = await Endpoint.post(urlBooleanTrigger, {}, trigger)
|
let resBoolean = await Endpoint.post(
|
||||||
|
urlBooleanTrigger,
|
||||||
|
{},
|
||||||
|
trigger
|
||||||
|
);
|
||||||
automation.triggers.push(resBoolean.data);
|
automation.triggers.push(resBoolean.data);
|
||||||
console.log("TRIGGERS: ", automation);
|
console.log("TRIGGERS: ", automation);
|
||||||
}
|
}
|
||||||
|
@ -521,16 +511,19 @@ export const RemoteService = {
|
||||||
automationId: id,
|
automationId: id,
|
||||||
priority,
|
priority,
|
||||||
sceneId,
|
sceneId,
|
||||||
}
|
};
|
||||||
let resScenes = await Endpoint["post"](urlScenePriority, {}, scenePriority)
|
let resScenes = await Endpoint["post"](
|
||||||
|
urlScenePriority,
|
||||||
|
{},
|
||||||
|
scenePriority
|
||||||
|
);
|
||||||
automation.scenes.push(resScenes.data);
|
automation.scenes.push(resScenes.data);
|
||||||
}
|
}
|
||||||
automation.id = id;
|
automation.id = id;
|
||||||
dispatch(actions.automationSave(automation));
|
dispatch(actions.automationSave(automation));
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -548,12 +541,7 @@ export const RemoteService = {
|
||||||
saveState: (data) => {
|
saveState: (data) => {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
let url =
|
let url =
|
||||||
"/" +
|
"/" + data.kind + "/" + data.id + "/state?sceneId=" + data.sceneId;
|
||||||
data.kind +
|
|
||||||
"/" +
|
|
||||||
data.id +
|
|
||||||
"/state?sceneId=" +
|
|
||||||
data.sceneId;
|
|
||||||
|
|
||||||
return Endpoint["post"](url, {}, data)
|
return Endpoint["post"](url, {}, data)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
@ -610,10 +598,7 @@ export const RemoteService = {
|
||||||
const inputDevice = await Endpoint.get(getUrl);
|
const inputDevice = await Endpoint.get(getUrl);
|
||||||
delete inputDevice.outputs;
|
delete inputDevice.outputs;
|
||||||
dispatch(
|
dispatch(
|
||||||
actions.deviceOperationUpdate([
|
actions.deviceOperationUpdate([...res.data, inputDevice.data])
|
||||||
...res.data,
|
|
||||||
inputDevice.data,
|
|
||||||
])
|
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -694,17 +679,13 @@ export const RemoteService = {
|
||||||
smartPlugReset(smartPlugId) {
|
smartPlugReset(smartPlugId) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
return Endpoint.delete(`/smartPlug/${smartPlugId}/meter`)
|
return Endpoint.delete(`/smartPlug/${smartPlugId}/meter`)
|
||||||
.then((res) =>
|
.then((res) => dispatch(actions.deviceOperationUpdate([res.data])))
|
||||||
dispatch(actions.deviceOperationUpdate([res.data]))
|
|
||||||
)
|
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.warn(`Smartplug reset error`, err);
|
console.warn(`Smartplug reset error`, err);
|
||||||
throw new RemoteError(["Network error"]);
|
throw new RemoteError(["Network error"]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a room
|
* Deletes a room
|
||||||
* @param {Number} roomId the id of the room to delete
|
* @param {Number} roomId the id of the room to delete
|
||||||
|
@ -732,7 +713,6 @@ export const RemoteService = {
|
||||||
throw new RemoteError(["Network error"]);
|
throw new RemoteError(["Network error"]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -768,11 +748,9 @@ export const RemoteService = {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
;
|
|
||||||
|
|
||||||
for (const key in RemoteService
|
for (const key in RemoteService) {
|
||||||
) {
|
|
||||||
RemoteService[key] = RemoteService[key].bind(RemoteService);
|
RemoteService[key] = RemoteService[key].bind(RemoteService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,11 +92,7 @@ class Dashboard extends Component {
|
||||||
name="Devices"
|
name="Devices"
|
||||||
content="Devices"
|
content="Devices"
|
||||||
active={this.activeTab === "Devices"}
|
active={this.activeTab === "Devices"}
|
||||||
color={
|
color={this.activeTab === "Devices" ? "yellow" : "grey"}
|
||||||
this.activeTab === "Devices"
|
|
||||||
? "yellow"
|
|
||||||
: "grey"
|
|
||||||
}
|
|
||||||
onClick={this.selectTab}
|
onClick={this.selectTab}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
|
@ -104,11 +100,7 @@ class Dashboard extends Component {
|
||||||
name="Scenes"
|
name="Scenes"
|
||||||
content="Scenes"
|
content="Scenes"
|
||||||
active={this.activeTab === "Scenes"}
|
active={this.activeTab === "Scenes"}
|
||||||
color={
|
color={this.activeTab === "Scenes" ? "yellow" : "grey"}
|
||||||
this.activeTab === "Scenes"
|
|
||||||
? "yellow"
|
|
||||||
: "grey"
|
|
||||||
}
|
|
||||||
onClick={this.selectTab}
|
onClick={this.selectTab}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
|
@ -116,11 +108,7 @@ class Dashboard extends Component {
|
||||||
name="Automations"
|
name="Automations"
|
||||||
content="Automations"
|
content="Automations"
|
||||||
active={this.activeTab === "Automations"}
|
active={this.activeTab === "Automations"}
|
||||||
color={
|
color={this.activeTab === "Automations" ? "yellow" : "grey"}
|
||||||
this.activeTab === "Automations"
|
|
||||||
? "yellow"
|
|
||||||
: "grey"
|
|
||||||
}
|
|
||||||
onClick={this.selectTab}
|
onClick={this.selectTab}
|
||||||
/>
|
/>
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
|
@ -131,9 +119,7 @@ class Dashboard extends Component {
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
|
|
||||||
<Grid.Column width={13}>
|
<Grid.Column width={13}>
|
||||||
<div style={panelStyle}>
|
<div style={panelStyle}>{this.renderTab(this.activeTab)}</div>
|
||||||
{this.renderTab(this.activeTab)}
|
|
||||||
</div>
|
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
</Grid.Row>
|
</Grid.Row>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -152,11 +138,7 @@ class Dashboard extends Component {
|
||||||
name="Devices"
|
name="Devices"
|
||||||
content="Devices"
|
content="Devices"
|
||||||
active={this.activeTab === "Devices"}
|
active={this.activeTab === "Devices"}
|
||||||
color={
|
color={this.activeTab === "Devices" ? "yellow" : "grey"}
|
||||||
this.activeTab === "Devices"
|
|
||||||
? "yellow"
|
|
||||||
: "grey"
|
|
||||||
}
|
|
||||||
onClick={this.selectTab}
|
onClick={this.selectTab}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
|
@ -164,11 +146,7 @@ class Dashboard extends Component {
|
||||||
name="Scenes"
|
name="Scenes"
|
||||||
content="Scenes"
|
content="Scenes"
|
||||||
active={this.activeTab === "Scenes"}
|
active={this.activeTab === "Scenes"}
|
||||||
color={
|
color={this.activeTab === "Scenes" ? "yellow" : "grey"}
|
||||||
this.activeTab === "Scenes"
|
|
||||||
? "yellow"
|
|
||||||
: "grey"
|
|
||||||
}
|
|
||||||
onClick={this.selectTab}
|
onClick={this.selectTab}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
|
@ -176,11 +154,7 @@ class Dashboard extends Component {
|
||||||
name="Automations"
|
name="Automations"
|
||||||
content="Automations"
|
content="Automations"
|
||||||
active={this.activeTab === "Automations"}
|
active={this.activeTab === "Automations"}
|
||||||
color={
|
color={this.activeTab === "Automations" ? "yellow" : "grey"}
|
||||||
this.activeTab === "Automations"
|
|
||||||
? "yellow"
|
|
||||||
: "grey"
|
|
||||||
}
|
|
||||||
onClick={this.selectTab}
|
onClick={this.selectTab}
|
||||||
/>
|
/>
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
|
|
Loading…
Reference in a new issue