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:
Andrea Brites Marto 2020-05-01 19:58:36 +02:00
commit 89a4f2f068
4 changed files with 42 additions and 28 deletions

View file

@ -62,8 +62,10 @@ 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(
(e) => this.state.devicesAttached[i] === e.id
); );
let data = { let data = {
sceneId: this.props.activeScene, sceneId: this.props.activeScene,
@ -73,6 +75,7 @@ class NewSceneDevice extends Component {
this.props this.props
.saveState(data) .saveState(data)
.catch((err) => console.error("error in creating state", err)); .catch((err) => console.error("error in creating state", err));
}
this.resetState(); this.resetState();
} }

View file

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

View file

@ -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>
{this.props.activeTab === "Devices" ? (
<input <input
type="range" type="range"
min="0" min="0"
max="40" max="40"
className="slider-css" className="slider-css"
value={this.props.stateOrDevice.targetTemperature} value={this.props.device.targetTemperature}
onChange={(event) => this.handleChange(event.target.value)} onChange={(event) => this.handleChange(event.target.value)}
id="targetTemperature" 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(

View file

@ -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";