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