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,
|
||||||
|
@ -63,34 +64,43 @@ class Thermostats extends Component {
|
||||||
//i came to the conclusion that is not possible to set mode.
|
//i came to the conclusion that is not possible to set mode.
|
||||||
//this.mode = "HEATING";
|
//this.mode = "HEATING";
|
||||||
const turnOn = mode;
|
const turnOn = mode;
|
||||||
if(this.props.tab==="Devices"){
|
if (this.props.tab === "Devices") {
|
||||||
this.props
|
this.props
|
||||||
.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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onClickDevice = () => {
|
onClickDevice = () => {
|
||||||
const on = !this.turnedOn;
|
const on = !this.turnedOn;
|
||||||
if(this.props.tab==="Devices"){
|
if (this.props.tab === "Devices") {
|
||||||
this.props
|
this.props
|
||||||
.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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//It seems to work
|
//It seems to work
|
||||||
saveTargetTemperature(targetTemperature) {
|
saveTargetTemperature(targetTemperature) {
|
||||||
if(this.props.tab==="Devices"){
|
if (this.props.tab === "Devices") {
|
||||||
this.props
|
this.props
|
||||||
.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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,12 +123,18 @@ class Thermostats extends Component {
|
||||||
|
|
||||||
//I have no idea why it doesn't want to update the temperature
|
//I have no idea why it doesn't want to update the temperature
|
||||||
saveInternalSensorTemperature(internalSensorTemperature) {
|
saveInternalSensorTemperature(internalSensorTemperature) {
|
||||||
if(this.props.tab==="Devices"){
|
if (this.props.tab === "Devices") {
|
||||||
this.props
|
this.props
|
||||||
.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>
|
||||||
|
@ -183,12 +198,11 @@ class Thermostats extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => ({
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
get stateOrDevice(){
|
get stateOrDevice() {
|
||||||
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) => {
|
||||||
|
@ -396,15 +396,15 @@ export const RemoteService = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteState: (id, type)=>{
|
deleteState: (id, type) => {
|
||||||
return (dispatch)=>{
|
return (dispatch) => {
|
||||||
let url;
|
let url;
|
||||||
if (type === "dimmableState") {
|
if (type === "dimmableState") {
|
||||||
url = "/dimmableState";
|
url = "/dimmableState";
|
||||||
} else {
|
} else {
|
||||||
url = "/switchableState";
|
url = "/switchableState";
|
||||||
}
|
}
|
||||||
return Endpoint.delete(url+`/${id}`)
|
return Endpoint.delete(url + `/${id}`)
|
||||||
.then((_) => dispatch(actions.stateDelete(id)))
|
.then((_) => dispatch(actions.stateDelete(id)))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.warn("state delete error", err);
|
console.warn("state delete error", err);
|
||||||
|
@ -413,14 +413,14 @@ export const RemoteService = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
sceneApply: (id)=>{
|
sceneApply: (id) => {
|
||||||
return (dispatch)=>{
|
return (dispatch) => {
|
||||||
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,21 +30,25 @@ 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,
|
||||||
devices,
|
devices,
|
||||||
partial,
|
partial,
|
||||||
}),
|
}),
|
||||||
stateDelete: (stateId)=>({
|
stateDelete: (stateId) => ({
|
||||||
type: "STATE_DELETE",
|
type: "STATE_DELETE",
|
||||||
stateId,
|
stateId,
|
||||||
}),
|
}),
|
||||||
sceneApply: (sceneId)=>({
|
sceneApply: (sceneId) => ({
|
||||||
type: "SCENE_APPLY",
|
type: "SCENE_APPLY",
|
||||||
sceneId,
|
sceneId,
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in a new issue