fixed many things

This commit is contained in:
britea 2020-04-26 13:38:54 +02:00
parent cce1650bd9
commit 2a1cc0292c
6 changed files with 91 additions and 55 deletions

View File

@ -3,19 +3,32 @@ import { connect } from "react-redux";
import { RemoteService } from "../../remote";
import Device from "./devices/Device";
import NewSceneDevice from "./NewSceneDevice";
import { Grid } from "semantic-ui-react";
import { Grid, Button } from "semantic-ui-react";
class ScenesPanel extends Component {
constructor(props) {
super(props);
this.applyScene = this.applyScene.bind(this);
}
applyScene() {
console.log(this.props.activeScene);
this.props.sceneApply(this.props.activeScene);
}
render() {
return (
<Grid doubling columns={2} divided="vertically">
{!this.props.isActiveDefaultScene ? (
<Grid.Row centered>
<Button color="blue" onClick={this.applyScene}>
Apply Scene
</Button>
</Grid.Row>
) : null}
{!this.props.isActiveDefaultScene
? this.props.sceneStates.map((e, i) => {
console.log(this.props.sceneStates);
return (
<Grid.Column key={i}>
<Device tab={this.props.tab} id={e.id} />

View File

@ -20,7 +20,8 @@ class Thermostats extends Component {
super(props);
this.state = {
targetTemperature: this.props.stateOrDevice.targetTemperature,
internalSensorTemperature: this.props.stateOrDevice.internalSensorTemperature,
internalSensorTemperature: this.props.stateOrDevice
.internalSensorTemperature,
mode: this.props.stateOrDevice.mode,
measuredTemperature: this.props.stateOrDevice.measuredTemperature,
useExternalSensors: this.props.stateOrDevice.useExternalSensors,
@ -68,7 +69,10 @@ class Thermostats extends Component {
.saveDevice({ ...this.props.stateOrDevice, turnOn })
.catch((err) => console.error("thermostat update error", err));
} else {
this.props.updateState({ id: this.props.sceneState.id, turnOn: turnOn },this.props.sceneState.kind);
this.props.updateState(
{ id: this.props.sceneState.id, turnOn: turnOn },
this.props.sceneState.kind
);
}
}
@ -79,7 +83,10 @@ class Thermostats extends Component {
.saveDevice({ ...this.props.stateOrDevice, on })
.catch((err) => console.error("thermostat update error", err));
} else {
this.props.updateState({ id: this.props.sceneState.id, on: on },this.props.sceneState.kind);
this.props.updateState(
{ id: this.props.sceneState.id, on: on },
this.props.sceneState.kind
);
}
};
@ -90,7 +97,10 @@ class Thermostats extends Component {
.saveDevice({ ...this.props.stateOrDevice, targetTemperature })
.catch((err) => console.error("thermostat update error", err));
} else {
this.props.updateState({id: this.props.sceneState.id, targetTemperature: targetTemperature},this.props.sceneState.kind);
this.props.updateState(
{ id: this.props.sceneState.id, targetTemperature: targetTemperature },
this.props.sceneState.kind
);
}
}
@ -118,7 +128,13 @@ class Thermostats extends Component {
.saveDevice({ ...this.props.device, internalSensorTemperature })
.catch((err) => console.error("thermostat update error", err));
} else {
this.props.updateState({ id: this.props.sceneState.id, internalSensorTemperature:internalSensorTemperature },this.props.sceneState.kind);
this.props.updateState(
{
id: this.props.sceneState.id,
internalSensorTemperature: internalSensorTemperature,
},
this.props.sceneState.kind
);
}
}
@ -151,7 +167,6 @@ class Thermostats extends Component {
render() {
return (
<div style={container}>
<h3 style={deviceName}>{this.props.stateOrDevice.name}</h3>
<div style={line}></div>
@ -187,8 +202,7 @@ const mapStateToProps = (state, ownProps) => ({
if (state.active.activeTab === "Devices") {
return state.devices[ownProps.id];
} else {
const sceneState = state.sceneStates[ownProps.id];
return state.devices[sceneState];
return state.sceneStates[ownProps.id];
}
},
});

View File

@ -40,7 +40,7 @@ class Videocam extends Component {
</video>
</div>
</StyledDivCamera>
<Grid columns="equal" divide padded>
<Grid columns="equal" padded>
<Grid.Row textAlign="center">
<Grid.Column>
<VideocamModal

View File

@ -386,7 +386,7 @@ export const RemoteService = {
return Endpoint.put(url, {}, data)
.then((res) => {
dispatch(actions.stateSave(res.data));
dispatch(actions.stateUpdate(res.data));
return res.data;
})
.catch((err) => {
@ -418,9 +418,9 @@ export const RemoteService = {
let url = `/scene/${id}/apply`;
return Endpoint.post(url)
.then((res)=> dispatch(actions.sceneApply(id)))
.then((res) => dispatch(actions.sceneApply(res.data)))
.catch((err) => {
console.warn('scene apply error',err);
console.warn("scene apply error", err);
throw new RemoteError(["Network error"]);
});
};

View File

@ -105,7 +105,7 @@ function reducer(previousState, action) {
createOrUpdateScene(scene);
}
break;
case "STATE_UPDATE":
case "STATES_UPDATE":
//console.log(action.sceneStates);
newState = previousState;
change = null;
@ -164,6 +164,9 @@ function reducer(previousState, action) {
newState = update(newState, change);
break;
case "STATE_UPDATE":
//update the state
break;
case "DEVICES_UPDATE":
change = null;
@ -368,7 +371,9 @@ function reducer(previousState, action) {
sceneStates: { $unset: [action.stateId] },
};
if (previousState.scenes[previousState.sceneStates[action.stateId].sceneId]) {
if (
previousState.scenes[previousState.sceneStates[action.stateId].sceneId]
) {
change.scenes = {
[previousState.sceneStates[action.stateId].sceneId]: {
sceneStates: { $remove: [action.stateId] },
@ -380,12 +385,12 @@ function reducer(previousState, action) {
break;
case "SCENE_APPLY":
console.log(action);
//checking that the scene actually exists
if (!(action.sceneId in previousState.scenes)) {
/*if (!(action.sceneId in previousState.scenes)) {
console.warn(`Scene ${action.sceneId} does not exist`);
break;
}
}*/
break;
case "DEVICE_DELETE":

View File

@ -30,10 +30,14 @@ const actions = {
sceneState,
}),
statesUpdate: (sceneId, sceneStates) => ({
type: "STATE_UPDATE",
type: "STATES_UPDATE",
sceneId,
sceneStates,
}),
stateUpdate: (state) => ({
type: "STATE_UPDATE",
state,
}),
devicesUpdate: (roomId, devices, partial = false) => ({
type: "DEVICES_UPDATE",
roomId,