added updateState to store
This commit is contained in:
parent
a3eff85149
commit
1484026afd
5 changed files with 87 additions and 27 deletions
|
@ -23,9 +23,13 @@ class Curtain extends Component {
|
||||||
|
|
||||||
onClickDevice = () => {
|
onClickDevice = () => {
|
||||||
const on = !this.turnedOn;
|
const on = !this.turnedOn;
|
||||||
this.props
|
if(this.props.tab==="Devices"){
|
||||||
.saveDevice({ ...this.props.device, on })
|
this.props
|
||||||
.catch((err) => console.error("curtains update error", err));
|
.saveDevice({ ...this.props.device, on })
|
||||||
|
.catch((err) => console.error("curtains update error", err));
|
||||||
|
}else{
|
||||||
|
this.props.updateState({ ...this.props.device, on },this.props.type);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
setIntensity(intensity) {
|
setIntensity(intensity) {
|
||||||
|
@ -49,9 +53,13 @@ class Curtain extends Component {
|
||||||
|
|
||||||
saveIntensity = () => {
|
saveIntensity = () => {
|
||||||
const intensity = Math.round(this.state.intensity);
|
const intensity = Math.round(this.state.intensity);
|
||||||
this.props
|
if(this.props.tab==="Devices"){
|
||||||
.saveDevice({ ...this.props.device, intensity })
|
this.props
|
||||||
.catch((err) => console.error("curtains update error", err));
|
.saveDevice({ ...this.props.device, intensity })
|
||||||
|
.catch((err) => console.error("curtain update error", err));
|
||||||
|
}else{
|
||||||
|
this.props.updateState({ ...this.props.device, on },this.props.type);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
helper = () => {
|
helper = () => {
|
||||||
|
|
|
@ -59,9 +59,14 @@ class Light extends Component {
|
||||||
|
|
||||||
onClickDevice = () => {
|
onClickDevice = () => {
|
||||||
const on = !this.turnedOn;
|
const on = !this.turnedOn;
|
||||||
this.props
|
if(this.props.tab==="Devices"){
|
||||||
.saveDevice({ ...this.props.device, on })
|
this.props
|
||||||
.catch((err) => console.error("regular light update error", err));
|
.saveDevice({ ...this.props.device, on })
|
||||||
|
.catch((err) => console.error("regular light update error", err));
|
||||||
|
}else{
|
||||||
|
this.props.updateState({ ...this.props.device, on },this.props.type);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
getIcon = () => {
|
getIcon = () => {
|
||||||
|
@ -89,9 +94,13 @@ class Light extends Component {
|
||||||
|
|
||||||
saveIntensity = () => {
|
saveIntensity = () => {
|
||||||
const intensity = Math.round(this.state.intensity);
|
const intensity = Math.round(this.state.intensity);
|
||||||
this.props
|
if(this.props.tab==="Devices"){
|
||||||
.saveDevice({ ...this.props.device, intensity })
|
this.props
|
||||||
.catch((err) => console.error("intensity light update error", err));
|
.saveDevice({ ...this.props.device, intensity })
|
||||||
|
.catch((err) => console.error("regular light update error", err));
|
||||||
|
}else{
|
||||||
|
this.props.updateState({ ...this.props.device, on },this.props.type);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -150,5 +159,6 @@ class Light extends Component {
|
||||||
const mapStateToProps = (state, ownProps) => ({
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
device: state.devices[ownProps.id],
|
device: state.devices[ownProps.id],
|
||||||
});
|
});
|
||||||
|
|
||||||
const LightContainer = connect(mapStateToProps, RemoteService)(Light);
|
const LightContainer = connect(mapStateToProps, RemoteService)(Light);
|
||||||
export default LightContainer;
|
export default LightContainer;
|
||||||
|
|
|
@ -33,9 +33,13 @@ class SmartPlug extends Component {
|
||||||
|
|
||||||
onClickDevice = () => {
|
onClickDevice = () => {
|
||||||
const on = !this.turnedOn;
|
const on = !this.turnedOn;
|
||||||
this.props
|
if(this.props.tab==="Devices"){
|
||||||
.saveDevice({ ...this.props.device, on })
|
this.props
|
||||||
.catch((err) => console.error("smart plug update error", err));
|
.saveDevice({ ...this.props.device, on })
|
||||||
|
.catch((err) => console.error("smart plug update error", err));
|
||||||
|
}else{
|
||||||
|
this.props.updateState({ ...this.props.device, on },this.props.type);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getIcon = () => {
|
getIcon = () => {
|
||||||
|
|
|
@ -63,23 +63,35 @@ 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;
|
||||||
this.props
|
if(this.props.tab==="Devices"){
|
||||||
.saveDevice({ ...this.props.device, turnOn })
|
this.props
|
||||||
.catch((err) => console.error("regular light update error", err));
|
.saveDevice({ ...this.props.device, turnOn })
|
||||||
|
.catch((err) => console.error("thermostat update error", err));
|
||||||
|
}else{
|
||||||
|
this.props.updateState({ ...this.props.device, on },this.props.type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onClickDevice = () => {
|
onClickDevice = () => {
|
||||||
const on = !this.turnedOn;
|
const on = !this.turnedOn;
|
||||||
this.props
|
if(this.props.tab==="Devices"){
|
||||||
.saveDevice({ ...this.props.device, on })
|
this.props
|
||||||
.catch((err) => console.error("regular light update error", err));
|
.saveDevice({ ...this.props.device, on })
|
||||||
|
.catch((err) => console.error("thermostat update error", err));
|
||||||
|
}else{
|
||||||
|
this.props.updateState({ ...this.props.device, on },this.props.type);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//It seems to work
|
//It seems to work
|
||||||
saveTargetTemperature(targetTemperature) {
|
saveTargetTemperature(targetTemperature) {
|
||||||
this.props
|
if(this.props.tab==="Devices"){
|
||||||
.saveDevice({ ...this.props.device, targetTemperature })
|
this.props
|
||||||
.catch((err) => console.error(" update error", err));
|
.saveDevice({ ...this.props.device, targetTemperature })
|
||||||
|
.catch((err) => console.error("thermostat update error", err));
|
||||||
|
}else{
|
||||||
|
this.props.updateState({ ...this.props.device, on },this.props.type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTargetTemperature(newTemp) {
|
setTargetTemperature(newTemp) {
|
||||||
|
@ -101,9 +113,13 @@ 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) {
|
||||||
this.props
|
if(this.props.tab==="Devices"){
|
||||||
.saveDevice({ ...this.props.device, internalSensorTemperature })
|
this.props
|
||||||
.catch((err) => console.error(" update error", err));
|
.saveDevice({ ...this.props.device, internalSensorTemperature })
|
||||||
|
.catch((err) => console.error("thermostat update error", err));
|
||||||
|
}else{
|
||||||
|
this.props.updateState({ ...this.props.device, on },this.props.type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setInternalSensorTemperature(newTemp) {
|
setInternalSensorTemperature(newTemp) {
|
||||||
|
|
|
@ -374,6 +374,28 @@ export const RemoteService = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
updateState: (data,type)=>{
|
||||||
|
return (dispatch) => {
|
||||||
|
let url;
|
||||||
|
if(type=="dimmableState"){
|
||||||
|
url="/dimmableState"
|
||||||
|
}else{
|
||||||
|
url="/switchableState"
|
||||||
|
}
|
||||||
|
|
||||||
|
return Endpoint["put"](url, {}, data)
|
||||||
|
.then((res) => {
|
||||||
|
dispatch(actions.stateSave(res.data));
|
||||||
|
return res.data;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.warn("Update device: ", data, "error: ", err);
|
||||||
|
throw new RemoteError(["Network error"]);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates/Updates a device with the given data. If
|
* Creates/Updates a device with the given data. If
|
||||||
* data.id is truthy, then a update call is performed,
|
* data.id is truthy, then a update call is performed,
|
||||||
|
|
Loading…
Reference in a new issue