fixed many things
This commit is contained in:
parent
cce1650bd9
commit
2a1cc0292c
6 changed files with 91 additions and 55 deletions
|
@ -3,19 +3,32 @@ import { connect } from "react-redux";
|
||||||
import { RemoteService } from "../../remote";
|
import { RemoteService } from "../../remote";
|
||||||
import Device from "./devices/Device";
|
import Device from "./devices/Device";
|
||||||
import NewSceneDevice from "./NewSceneDevice";
|
import NewSceneDevice from "./NewSceneDevice";
|
||||||
import { Grid } from "semantic-ui-react";
|
import { Grid, Button } from "semantic-ui-react";
|
||||||
|
|
||||||
class ScenesPanel extends Component {
|
class ScenesPanel extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
this.applyScene = this.applyScene.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
applyScene() {
|
||||||
|
console.log(this.props.activeScene);
|
||||||
|
this.props.sceneApply(this.props.activeScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Grid doubling columns={2} divided="vertically">
|
<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.isActiveDefaultScene
|
||||||
? this.props.sceneStates.map((e, i) => {
|
? this.props.sceneStates.map((e, i) => {
|
||||||
console.log(this.props.sceneStates);
|
|
||||||
return (
|
return (
|
||||||
<Grid.Column key={i}>
|
<Grid.Column key={i}>
|
||||||
<Device tab={this.props.tab} id={e.id} />
|
<Device tab={this.props.tab} id={e.id} />
|
||||||
|
|
|
@ -20,7 +20,8 @@ class Thermostats extends Component {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
targetTemperature: this.props.stateOrDevice.targetTemperature,
|
targetTemperature: this.props.stateOrDevice.targetTemperature,
|
||||||
internalSensorTemperature: this.props.stateOrDevice.internalSensorTemperature,
|
internalSensorTemperature: this.props.stateOrDevice
|
||||||
|
.internalSensorTemperature,
|
||||||
mode: this.props.stateOrDevice.mode,
|
mode: this.props.stateOrDevice.mode,
|
||||||
measuredTemperature: this.props.stateOrDevice.measuredTemperature,
|
measuredTemperature: this.props.stateOrDevice.measuredTemperature,
|
||||||
useExternalSensors: this.props.stateOrDevice.useExternalSensors,
|
useExternalSensors: this.props.stateOrDevice.useExternalSensors,
|
||||||
|
@ -68,7 +69,10 @@ class Thermostats extends Component {
|
||||||
.saveDevice({ ...this.props.stateOrDevice, turnOn })
|
.saveDevice({ ...this.props.stateOrDevice, turnOn })
|
||||||
.catch((err) => console.error("thermostat update error", err));
|
.catch((err) => console.error("thermostat update error", err));
|
||||||
} else {
|
} 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 })
|
.saveDevice({ ...this.props.stateOrDevice, on })
|
||||||
.catch((err) => console.error("thermostat update error", err));
|
.catch((err) => console.error("thermostat update error", err));
|
||||||
} else {
|
} 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 })
|
.saveDevice({ ...this.props.stateOrDevice, targetTemperature })
|
||||||
.catch((err) => console.error("thermostat update error", err));
|
.catch((err) => console.error("thermostat update error", err));
|
||||||
} else {
|
} 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 })
|
.saveDevice({ ...this.props.device, internalSensorTemperature })
|
||||||
.catch((err) => console.error("thermostat update error", err));
|
.catch((err) => console.error("thermostat update error", err));
|
||||||
} else {
|
} 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() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<div style={container}>
|
<div style={container}>
|
||||||
<h3 style={deviceName}>{this.props.stateOrDevice.name}</h3>
|
<h3 style={deviceName}>{this.props.stateOrDevice.name}</h3>
|
||||||
<div style={line}></div>
|
<div style={line}></div>
|
||||||
|
@ -187,8 +202,7 @@ const mapStateToProps = (state, ownProps) => ({
|
||||||
if (state.active.activeTab === "Devices") {
|
if (state.active.activeTab === "Devices") {
|
||||||
return state.devices[ownProps.id];
|
return state.devices[ownProps.id];
|
||||||
} else {
|
} else {
|
||||||
const sceneState = state.sceneStates[ownProps.id];
|
return state.sceneStates[ownProps.id];
|
||||||
return state.devices[sceneState];
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,7 +40,7 @@ class Videocam extends Component {
|
||||||
</video>
|
</video>
|
||||||
</div>
|
</div>
|
||||||
</StyledDivCamera>
|
</StyledDivCamera>
|
||||||
<Grid columns="equal" divide padded>
|
<Grid columns="equal" padded>
|
||||||
<Grid.Row textAlign="center">
|
<Grid.Row textAlign="center">
|
||||||
<Grid.Column>
|
<Grid.Column>
|
||||||
<VideocamModal
|
<VideocamModal
|
||||||
|
|
|
@ -386,7 +386,7 @@ export const RemoteService = {
|
||||||
|
|
||||||
return Endpoint.put(url, {}, data)
|
return Endpoint.put(url, {}, data)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
dispatch(actions.stateSave(res.data));
|
dispatch(actions.stateUpdate(res.data));
|
||||||
return res.data;
|
return res.data;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -418,9 +418,9 @@ export const RemoteService = {
|
||||||
let url = `/scene/${id}/apply`;
|
let url = `/scene/${id}/apply`;
|
||||||
|
|
||||||
return Endpoint.post(url)
|
return Endpoint.post(url)
|
||||||
.then((res)=> dispatch(actions.sceneApply(id)))
|
.then((res) => dispatch(actions.sceneApply(res.data)))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.warn('scene apply error',err);
|
console.warn("scene apply error", err);
|
||||||
throw new RemoteError(["Network error"]);
|
throw new RemoteError(["Network error"]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,7 +105,7 @@ function reducer(previousState, action) {
|
||||||
createOrUpdateScene(scene);
|
createOrUpdateScene(scene);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "STATE_UPDATE":
|
case "STATES_UPDATE":
|
||||||
//console.log(action.sceneStates);
|
//console.log(action.sceneStates);
|
||||||
newState = previousState;
|
newState = previousState;
|
||||||
change = null;
|
change = null;
|
||||||
|
@ -164,6 +164,9 @@ function reducer(previousState, action) {
|
||||||
|
|
||||||
newState = update(newState, change);
|
newState = update(newState, change);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "STATE_UPDATE":
|
||||||
|
//update the state
|
||||||
break;
|
break;
|
||||||
case "DEVICES_UPDATE":
|
case "DEVICES_UPDATE":
|
||||||
change = null;
|
change = null;
|
||||||
|
@ -368,7 +371,9 @@ function reducer(previousState, action) {
|
||||||
sceneStates: { $unset: [action.stateId] },
|
sceneStates: { $unset: [action.stateId] },
|
||||||
};
|
};
|
||||||
|
|
||||||
if (previousState.scenes[previousState.sceneStates[action.stateId].sceneId]) {
|
if (
|
||||||
|
previousState.scenes[previousState.sceneStates[action.stateId].sceneId]
|
||||||
|
) {
|
||||||
change.scenes = {
|
change.scenes = {
|
||||||
[previousState.sceneStates[action.stateId].sceneId]: {
|
[previousState.sceneStates[action.stateId].sceneId]: {
|
||||||
sceneStates: { $remove: [action.stateId] },
|
sceneStates: { $remove: [action.stateId] },
|
||||||
|
@ -380,12 +385,12 @@ function reducer(previousState, action) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "SCENE_APPLY":
|
case "SCENE_APPLY":
|
||||||
|
console.log(action);
|
||||||
//checking that the scene actually exists
|
//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`);
|
console.warn(`Scene ${action.sceneId} does not exist`);
|
||||||
break;
|
break;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "DEVICE_DELETE":
|
case "DEVICE_DELETE":
|
||||||
|
|
|
@ -30,10 +30,14 @@ const actions = {
|
||||||
sceneState,
|
sceneState,
|
||||||
}),
|
}),
|
||||||
statesUpdate: (sceneId, sceneStates) => ({
|
statesUpdate: (sceneId, sceneStates) => ({
|
||||||
type: "STATE_UPDATE",
|
type: "STATES_UPDATE",
|
||||||
sceneId,
|
sceneId,
|
||||||
sceneStates,
|
sceneStates,
|
||||||
}),
|
}),
|
||||||
|
stateUpdate: (state) => ({
|
||||||
|
type: "STATE_UPDATE",
|
||||||
|
state,
|
||||||
|
}),
|
||||||
devicesUpdate: (roomId, devices, partial = false) => ({
|
devicesUpdate: (roomId, devices, partial = false) => ({
|
||||||
type: "DEVICES_UPDATE",
|
type: "DEVICES_UPDATE",
|
||||||
roomId,
|
roomId,
|
||||||
|
|
Loading…
Reference in a new issue