scene apply preparations

This commit is contained in:
Jacob Salvi 2020-04-26 11:09:49 +02:00
parent 34f83c9cce
commit 07f4a8ee43
4 changed files with 27 additions and 0 deletions

View File

@ -231,6 +231,7 @@ const mapStateToProps = (state, ownProps) => ({
}
},
get type() {
console.log("ALPACA",state,ownProps);
if (state.active.activeTab === "Scenes") {
if (state.sceneStates[ownProps.id]) {
console.log(state.sceneStates[ownProps.id], ownProps.id);

View File

@ -413,6 +413,19 @@ export const RemoteService = {
};
},
sceneApply: (id)=>{
return (dispatch)=>{
let url=`/scene/${id}/apply`;
return Endpoint.post(url)
.then((res)=> dispatch(actions.sceneApply(id)))
.catch((err)=>{
console.warn('scene apply error',err);
throw new RemoteError(["Network error"]);
});
};
},
/**
* Creates/Updates a device with the given data. If
* data.id is truthy, then a update call is performed,

View File

@ -377,6 +377,15 @@ function reducer(previousState, action) {
}
newState = update(previousState, change);
break;
case "SCENE_APPLY":
if (!(action.sceneId in previousState.scenes)) {
console.warn(`Scene ${action.sceneId} does not exist`);
break;
}
break;
case "DEVICE_DELETE":
if (!(action.deviceId in previousState.devices)) {

View File

@ -44,6 +44,10 @@ const actions = {
type: "STATE_DELETE",
stateId,
}),
sceneApply: (sceneId)=>({
type: "SCENE_APPLY",
sceneId,
}),
deviceOperationUpdate: (devices) => ({
type: "DEVICES_UPDATE",
devices,