Fix to socket state reducer and state updated in devices that use circularinput
This commit is contained in:
parent
0664d502fe
commit
b070273c73
3 changed files with 29 additions and 5 deletions
|
@ -44,6 +44,12 @@ class Light extends Component {
|
||||||
this.setIntensity = this.setIntensity.bind(this);
|
this.setIntensity = this.setIntensity.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps, prevState) {
|
||||||
|
if (this.props.device.intensity !== prevProps.device.intensity) {
|
||||||
|
this.setState({ intensity: this.props.device.intensity, timeout: null });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get turnedOn() {
|
get turnedOn() {
|
||||||
return this.props.device.on;
|
return this.props.device.on;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,20 @@ class Sensor extends Component {
|
||||||
return this.props.device.name;
|
return this.props.device.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps) {
|
||||||
|
if (
|
||||||
|
this.props.device.kind === "sensor" &&
|
||||||
|
this.props.device.value !== prevProps.device.value
|
||||||
|
) {
|
||||||
|
this.setState({ value: this.props.device.value });
|
||||||
|
} else if (
|
||||||
|
this.props.device.kind === "motionSensor" &&
|
||||||
|
this.props.device.detected !== prevProps.device.detected
|
||||||
|
) {
|
||||||
|
this.setState({ motion: true, detected: this.props.device.detected });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (this.props.device.kind === "sensor") {
|
if (this.props.device.kind === "sensor") {
|
||||||
switch (this.props.device.sensor) {
|
switch (this.props.device.sensor) {
|
||||||
|
|
|
@ -89,12 +89,16 @@ function reducer(previousState, action) {
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const device of action.devices) {
|
for (const device of action.devices) {
|
||||||
const roomId = previousState.devices[device.id].roomId;
|
if (!previousState.devices[device.id]) continue;
|
||||||
change.rooms[roomId] = change.rooms[roomId] || {
|
|
||||||
devices: { $remove: [] },
|
|
||||||
};
|
|
||||||
change.rooms[roomId].devices.$remove.push(device.id);
|
|
||||||
change.devices.$unset.push(device.id);
|
change.devices.$unset.push(device.id);
|
||||||
|
const roomId = previousState.devices[device.id].roomId;
|
||||||
|
|
||||||
|
if (roomId in previousState.rooms) {
|
||||||
|
change.rooms[roomId] = change.rooms[roomId] || {
|
||||||
|
devices: { $remove: [] },
|
||||||
|
};
|
||||||
|
change.rooms[roomId].devices.$remove.push(device.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// otherwise, just delete all devices and all joins
|
// otherwise, just delete all devices and all joins
|
||||||
|
|
Loading…
Reference in a new issue