fixed problem in scene state

This commit is contained in:
britea 2020-04-25 18:23:40 +02:00
parent d231ce7e84
commit 2d9bdf63fb
2 changed files with 60 additions and 46 deletions

View file

@ -127,52 +127,59 @@ class Device extends React.Component {
tab={this.props.tab} tab={this.props.tab}
/> />
); );
case "":
return "";
default: default:
throw new Error("Device type unknown"); //throw new Error("Device type unknown");
return undefined;
} }
} }
render() { render() {
return ( {
<Segment> if (this.props.type !== "") {
<Grid columns={2}> return (
<Grid.Column>{this.renderDeviceComponent()}</Grid.Column> <Segment>
{this.props.tab === "Devices" ? ( <Grid columns={2}>
<Grid.Column textAlign="center"> <Grid.Column>{this.renderDeviceComponent()}</Grid.Column>
<Header as="h3">{this.props.stateOrDevice.name}</Header> {this.props.tab === "Devices" ? (
<Button <Grid.Column textAlign="center">
color="blue" <Header as="h3">{this.props.stateOrDevice.name}</Header>
icon <Button
onClick={this.edit} color="blue"
labelPosition="left" icon
> onClick={this.edit}
<Icon name="pencil" /> labelPosition="left"
Edit >
</Button> <Icon name="pencil" />
{this.props.stateOrDevice.kind === "smartPlug" ? ( Edit
<Button </Button>
color="orange" {this.props.stateOrDevice.kind === "smartPlug" ? (
icon <Button
onClick={this.resetSmartPlug} color="orange"
labelPosition="left" icon
> onClick={this.resetSmartPlug}
<Icon name="undo" /> labelPosition="left"
Reset >
</Button> <Icon name="undo" />
) : null} Reset
</Grid.Column> </Button>
) : ( ) : null}
<Grid.Column textAlign="center"> </Grid.Column>
<Header as="h3"> ) : (
{this.props.stateOrDevice ? this.props.stateOrDevice.name : ""} <Grid.Column textAlign="center">
</Header> <Header as="h3">
</Grid.Column> {this.props.stateOrDevice
)} ? this.props.stateOrDevice.name
</Grid> : ""}
</Segment> </Header>
); </Grid.Column>
)}
</Grid>
</Segment>
);
} else {
return null;
}
}
} }
} }
/* /*
@ -211,9 +218,14 @@ const mapStateToProps = (state, ownProps) => ({
}, },
get type() { get type() {
if (state.active.activeTab === "Scenes") { if (state.active.activeTab === "Scenes") {
const id = state.sceneStates[ownProps.id].deviceId; if (state.sceneStates[ownProps.id]) {
console.log(id, state.devices[id].kind); console.log(state.sceneStates[ownProps.id], ownProps.id);
return state.devices[id].kind; const id = state.sceneStates[ownProps.id].deviceId;
console.log(id, state.devices[id].kind);
return state.devices[id].kind;
} else {
return "";
}
} else { } else {
return null; return null;
} }

View file

@ -81,7 +81,9 @@ function reducer(previousState, action) {
const updateSceneStateProps = (state) => { const updateSceneStateProps = (state) => {
change.sceneStates[state.id] = {}; change.sceneStates[state.id] = {};
change.sceneStates[state.id] = { $set: state.id }; for (const key in state) {
change.sceneStates[state.id][key] = { $set: state[key] };
}
}; };
switch (action.type) { switch (action.type) {
@ -104,7 +106,7 @@ function reducer(previousState, action) {
} }
break; break;
case "STATE_UPDATE": case "STATE_UPDATE":
console.log(action.sceneStates); //console.log(action.sceneStates);
newState = previousState; newState = previousState;
change = null; change = null;