fixed scenes, add multiple states

This commit is contained in:
britea 2020-05-01 19:55:08 +02:00
parent 9d8524c7c9
commit 6db8e928f1
4 changed files with 42 additions and 28 deletions

View File

@ -62,17 +62,20 @@ class NewSceneDevice extends Component {
}
createState() {
const device = this.props.devices.filter(
(e) => this.state.devicesAttached[0] === e.id
);
let data = {
sceneId: this.props.activeScene,
id: device[0].id,
kind: device[0].kind,
};
this.props
.saveState(data)
.catch((err) => console.error("error in creating state", err));
for (let i = 0; i < this.state.devicesAttached.length; i++) {
console.log("DIOPORCO", i, this.state.devicesAttached[i]);
let device = this.props.devices.filter(
(e) => this.state.devicesAttached[i] === e.id
);
let data = {
sceneId: this.props.activeScene,
id: device[0].id,
kind: device[0].kind,
};
this.props
.saveState(data)
.catch((err) => console.error("error in creating state", err));
}
this.resetState();
}

View File

@ -179,10 +179,12 @@ class Device extends React.Component {
? this.deviceDescription()
: this.stateDescription()}
</Card.Content>
<DeviceSettingsModal
ref={this.modalRef}
id={this.props.stateOrDevice.id}
/>
{this.props.tab === "Devices" ? (
<DeviceSettingsModal
ref={this.modalRef}
id={this.props.stateOrDevice.id}
/>
) : null}
</Card>
);
}

View File

@ -71,7 +71,7 @@ class Thermostats extends Component {
.catch((err) => console.error("thermostat update error", err));
} else {
this.props.updateState(
{ id: this.props.stateOrDevice.id, turnOn: turnOn },
{ id: this.props.stateOrDevice.id, on: turnOn },
this.props.stateOrDevice.kind
);
}
@ -186,19 +186,20 @@ class Thermostats extends Component {
// TODO Manage the state hereconsole.log("CHANGE", val.checked)
onChange={(e, val) => this.setMode(val.checked)}
/>
<span style={targetTemperature}>
{this.props.stateOrDevice.targetTemperature}ºC
{this.props.device.targetTemperature}ºC
</span>
<input
type="range"
min="0"
max="40"
className="slider-css"
value={this.props.stateOrDevice.targetTemperature}
onChange={(event) => this.handleChange(event.target.value)}
id="targetTemperature"
/>
{this.props.activeTab === "Devices" ? (
<input
type="range"
min="0"
max="40"
className="slider-css"
value={this.props.device.targetTemperature}
onChange={(event) => this.handleChange(event.target.value)}
id="targetTemperature"
/>
) : null}
<div style={stateTagContainer}>
<span style={stateTag}>{this.props.stateOrDevice.mode}</span>
</div>
@ -215,6 +216,14 @@ const mapStateToProps = (state, ownProps) => ({
return state.sceneStates[ownProps.id];
}
},
get device() {
if (state.active.activeTab === "Devices") {
return state.devices[ownProps.id];
} else {
return state.devices[state.sceneStates[ownProps.id].deviceId];
}
},
activeTab: state.activeTab,
});
const ThermostatContainer = connect(

View File

@ -423,7 +423,7 @@ export const RemoteService = {
updateState: (data, type) => {
return (dispatch) => {
let url;
if (data.on) {
if (data.on !== undefined) {
url = "/switchableState";
} else {
url = "/dimmableState";