Merge branch '89-fix-scenes' into 'dev'
fixed scenes, add multiple states Closes #89 See merge request sa4-2020/the-sanmarinoes/frontend!108
This commit is contained in:
commit
89a4f2f068
4 changed files with 42 additions and 28 deletions
|
@ -62,17 +62,20 @@ class NewSceneDevice extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
createState() {
|
createState() {
|
||||||
const device = this.props.devices.filter(
|
for (let i = 0; i < this.state.devicesAttached.length; i++) {
|
||||||
(e) => this.state.devicesAttached[0] === e.id
|
console.log("DIOPORCO", i, this.state.devicesAttached[i]);
|
||||||
);
|
let device = this.props.devices.filter(
|
||||||
let data = {
|
(e) => this.state.devicesAttached[i] === e.id
|
||||||
sceneId: this.props.activeScene,
|
);
|
||||||
id: device[0].id,
|
let data = {
|
||||||
kind: device[0].kind,
|
sceneId: this.props.activeScene,
|
||||||
};
|
id: device[0].id,
|
||||||
this.props
|
kind: device[0].kind,
|
||||||
.saveState(data)
|
};
|
||||||
.catch((err) => console.error("error in creating state", err));
|
this.props
|
||||||
|
.saveState(data)
|
||||||
|
.catch((err) => console.error("error in creating state", err));
|
||||||
|
}
|
||||||
this.resetState();
|
this.resetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,10 +179,12 @@ class Device extends React.Component {
|
||||||
? this.deviceDescription()
|
? this.deviceDescription()
|
||||||
: this.stateDescription()}
|
: this.stateDescription()}
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
<DeviceSettingsModal
|
{this.props.tab === "Devices" ? (
|
||||||
ref={this.modalRef}
|
<DeviceSettingsModal
|
||||||
id={this.props.stateOrDevice.id}
|
ref={this.modalRef}
|
||||||
/>
|
id={this.props.stateOrDevice.id}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Thermostats extends Component {
|
||||||
.catch((err) => console.error("thermostat update error", err));
|
.catch((err) => console.error("thermostat update error", err));
|
||||||
} else {
|
} else {
|
||||||
this.props.updateState(
|
this.props.updateState(
|
||||||
{ id: this.props.stateOrDevice.id, turnOn: turnOn },
|
{ id: this.props.stateOrDevice.id, on: turnOn },
|
||||||
this.props.stateOrDevice.kind
|
this.props.stateOrDevice.kind
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -186,19 +186,20 @@ class Thermostats extends Component {
|
||||||
// TODO Manage the state hereconsole.log("CHANGE", val.checked)
|
// TODO Manage the state hereconsole.log("CHANGE", val.checked)
|
||||||
onChange={(e, val) => this.setMode(val.checked)}
|
onChange={(e, val) => this.setMode(val.checked)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<span style={targetTemperature}>
|
<span style={targetTemperature}>
|
||||||
{this.props.stateOrDevice.targetTemperature}ºC
|
{this.props.device.targetTemperature}ºC
|
||||||
</span>
|
</span>
|
||||||
<input
|
{this.props.activeTab === "Devices" ? (
|
||||||
type="range"
|
<input
|
||||||
min="0"
|
type="range"
|
||||||
max="40"
|
min="0"
|
||||||
className="slider-css"
|
max="40"
|
||||||
value={this.props.stateOrDevice.targetTemperature}
|
className="slider-css"
|
||||||
onChange={(event) => this.handleChange(event.target.value)}
|
value={this.props.device.targetTemperature}
|
||||||
id="targetTemperature"
|
onChange={(event) => this.handleChange(event.target.value)}
|
||||||
/>
|
id="targetTemperature"
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
<div style={stateTagContainer}>
|
<div style={stateTagContainer}>
|
||||||
<span style={stateTag}>{this.props.stateOrDevice.mode}</span>
|
<span style={stateTag}>{this.props.stateOrDevice.mode}</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -215,6 +216,14 @@ const mapStateToProps = (state, ownProps) => ({
|
||||||
return state.sceneStates[ownProps.id];
|
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(
|
const ThermostatContainer = connect(
|
||||||
|
|
|
@ -423,7 +423,7 @@ export const RemoteService = {
|
||||||
updateState: (data, type) => {
|
updateState: (data, type) => {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
let url;
|
let url;
|
||||||
if (data.on) {
|
if (data.on !== undefined) {
|
||||||
url = "/switchableState";
|
url = "/switchableState";
|
||||||
} else {
|
} else {
|
||||||
url = "/dimmableState";
|
url = "/dimmableState";
|
||||||
|
|
Loading…
Reference in a new issue