Merge branch '59-added-motion-sensor-update' into 'dev'
added motion sensor update Closes #59 See merge request sa4-2020/the-sanmarinoes/frontend!62
This commit is contained in:
commit
cee6e3ce59
4 changed files with 171 additions and 46 deletions
82
smart-hut/src/components/FilterDevices.js
Normal file
82
smart-hut/src/components/FilterDevices.js
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
import { Dropdown } from "semantic-ui-react";
|
||||||
|
import React, { Component } from "react";
|
||||||
|
|
||||||
|
export default class FilterDevices extends Component {
|
||||||
|
render() {
|
||||||
|
const tagOptions = [
|
||||||
|
{
|
||||||
|
key: "regularLight",
|
||||||
|
text: "regularLight",
|
||||||
|
value: "regularLight",
|
||||||
|
label: { color: "red", empty: true, circular: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "dimmableLight",
|
||||||
|
text: "dimmableLight",
|
||||||
|
value: "dimmableLight",
|
||||||
|
label: { color: "blue", empty: true, circular: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "buttonDimmer",
|
||||||
|
text: "buttonDimmer",
|
||||||
|
value: "buttonDimmer",
|
||||||
|
label: { color: "black", empty: true, circular: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "knobDimmer",
|
||||||
|
text: "knobDimmer",
|
||||||
|
value: "knobDimmer",
|
||||||
|
label: { color: "purple", empty: true, circular: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "motionSensor",
|
||||||
|
text: "motionSensor",
|
||||||
|
value: "motionSensor",
|
||||||
|
label: { color: "orange", empty: true, circular: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "sensor",
|
||||||
|
text: "sensor",
|
||||||
|
value: "sensor",
|
||||||
|
label: { empty: true, circular: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "smartPlug",
|
||||||
|
text: "smartPlug",
|
||||||
|
value: "smartPlug",
|
||||||
|
label: { color: "pink", empty: true, circular: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "switch",
|
||||||
|
text: "switch",
|
||||||
|
value: "switch",
|
||||||
|
label: { color: "green", empty: true, circular: true },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dropdown
|
||||||
|
text="Filter Devices"
|
||||||
|
icon="filter"
|
||||||
|
floating
|
||||||
|
labeled
|
||||||
|
button
|
||||||
|
className="icon"
|
||||||
|
>
|
||||||
|
<Dropdown.Menu>
|
||||||
|
<Dropdown.Divider />
|
||||||
|
<Dropdown.Header icon="tags" content="Tag Device" />
|
||||||
|
<Dropdown.Menu scrolling>
|
||||||
|
{tagOptions.map((option) => (
|
||||||
|
<Dropdown.Item
|
||||||
|
key={option.value}
|
||||||
|
{...option}
|
||||||
|
onClick={this.props.filterDevices}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Dropdown.Menu>
|
||||||
|
</Dropdown.Menu>
|
||||||
|
</Dropdown>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,15 @@ const DeviceType = (props) => {
|
||||||
edit={props.edit}
|
edit={props.edit}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
case "motionSensor":
|
||||||
|
return (
|
||||||
|
<Sensor
|
||||||
|
updateDev={props.updateDeviceUi}
|
||||||
|
onChangeData={props.changeDeviceData}
|
||||||
|
device={props.device}
|
||||||
|
edit={props.edit}
|
||||||
|
/>
|
||||||
|
);
|
||||||
case "buttonDimmer":
|
case "buttonDimmer":
|
||||||
return (
|
return (
|
||||||
<DefaultDimmer
|
<DefaultDimmer
|
||||||
|
|
|
@ -31,6 +31,7 @@ export default class NewDevice extends Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
step: 1,
|
step: 1,
|
||||||
openModal: false,
|
openModal: false,
|
||||||
|
motion: false,
|
||||||
};
|
};
|
||||||
this.baseState = this.state;
|
this.baseState = this.state;
|
||||||
this.createDevice = this.createDevice.bind(this);
|
this.createDevice = this.createDevice.bind(this);
|
||||||
|
@ -68,7 +69,12 @@ export default class NewDevice extends Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
setTypeOfSensor = (e, d) => {
|
setTypeOfSensor = (e, d) => {
|
||||||
|
console.log(d.value);
|
||||||
|
if (d.value === "motionSensor") {
|
||||||
|
this.setState({ typeOfSensor: d.value, motion: true });
|
||||||
|
} else {
|
||||||
this.setState({ typeOfSensor: d.value });
|
this.setState({ typeOfSensor: d.value });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
setLightsDimmerSwitch = (e, d) => {
|
setLightsDimmerSwitch = (e, d) => {
|
||||||
|
@ -81,7 +87,7 @@ export default class NewDevice extends Component {
|
||||||
params: {
|
params: {
|
||||||
name: this.state.deviceName,
|
name: this.state.deviceName,
|
||||||
},
|
},
|
||||||
device: this.state.typeOfDevice,
|
device: this.state.motion ? "motionSensor" : this.state.typeOfDevice,
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (this.state.typeOfDevice) {
|
switch (this.state.typeOfDevice) {
|
||||||
|
@ -89,8 +95,10 @@ export default class NewDevice extends Component {
|
||||||
data.params["intensity"] = 1;
|
data.params["intensity"] = 1;
|
||||||
break;
|
break;
|
||||||
case "sensor":
|
case "sensor":
|
||||||
|
if (!this.state.motion) {
|
||||||
data.params["sensor"] = this.state.typeOfSensor;
|
data.params["sensor"] = this.state.typeOfSensor;
|
||||||
data.params["value"] = 0;
|
data.params["value"] = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "switch":
|
case "switch":
|
||||||
data.params["lights"] = this.state.lightsAttached;
|
data.params["lights"] = this.state.lightsAttached;
|
||||||
|
|
|
@ -29,19 +29,25 @@ import { sensorText, style, valueStyle } from "./SensorStyle";
|
||||||
import Settings from "./DeviceSettings";
|
import Settings from "./DeviceSettings";
|
||||||
import { StyledDiv } from "./styleComponents";
|
import { StyledDiv } from "./styleComponents";
|
||||||
import { call } from "../../../client_server";
|
import { call } from "../../../client_server";
|
||||||
|
import { nameStyle } from "./LightStyle";
|
||||||
|
import { iconStyle } from "./styleComponents";
|
||||||
|
import { Image } from "semantic-ui-react";
|
||||||
|
|
||||||
export default class Sensor extends Component {
|
export default class Sensor extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
turnedOn: false,
|
|
||||||
value: 0,
|
value: 0,
|
||||||
|
motion: false,
|
||||||
};
|
};
|
||||||
this.units = "";
|
this.units = "";
|
||||||
this.stateCallback = (e) => {
|
this.stateCallback = (e) => {
|
||||||
this.setState(Object.assign(this.state, e));
|
this.setState(Object.assign(this.state, e));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.iconOn = "/img/lightOn.svg";
|
||||||
|
this.iconOff = "/img/lightOff.svg";
|
||||||
|
|
||||||
call.socketSubscribe(this.props.device.id, this.stateCallback);
|
call.socketSubscribe(this.props.device.id, this.stateCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +63,7 @@ export default class Sensor extends Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
if (this.props.device.kind === "sensor") {
|
||||||
switch (this.props.device.sensor) {
|
switch (this.props.device.sensor) {
|
||||||
case "TEMPERATURE":
|
case "TEMPERATURE":
|
||||||
this.units = "ºC";
|
this.units = "ºC";
|
||||||
|
@ -73,7 +80,20 @@ export default class Sensor extends Component {
|
||||||
this.setState({
|
this.setState({
|
||||||
value: this.props.device.value,
|
value: this.props.device.value,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
detected: this.props.device.detected,
|
||||||
|
motion: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getIcon = () => {
|
||||||
|
if (this.state.detected) {
|
||||||
|
return this.iconOn;
|
||||||
|
}
|
||||||
|
return this.iconOff;
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
@ -85,7 +105,12 @@ export default class Sensor extends Component {
|
||||||
this.props.onChangeData(id, newSettings)
|
this.props.onChangeData(id, newSettings)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
{this.state.motion ? (
|
||||||
|
<div onClick={this.props.edit.mode ? () => {} : this.onClickDevice}>
|
||||||
|
<Image src={this.getIcon()} style={iconStyle} />
|
||||||
|
<h5 style={nameStyle}>Motion Sensor</h5>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<CircularInput value={this.state.value / 100} style={style}>
|
<CircularInput value={this.state.value / 100} style={style}>
|
||||||
<CircularTrack />
|
<CircularTrack />
|
||||||
<CircularProgress />
|
<CircularProgress />
|
||||||
|
@ -111,6 +136,7 @@ export default class Sensor extends Component {
|
||||||
{this.setName()}
|
{this.setName()}
|
||||||
</text>
|
</text>
|
||||||
</CircularInput>
|
</CircularInput>
|
||||||
|
)}
|
||||||
</StyledDiv>
|
</StyledDiv>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue