Added smooth temperature gradient

This commit is contained in:
Claudio Maggioni 2020-05-08 15:37:01 +02:00
parent 38425b8d68
commit e5426fa790
2 changed files with 188 additions and 217 deletions

View file

@ -72,8 +72,7 @@ class Sensor extends Component {
this.setState({ value: this.props.stateOrDevice.value }); this.setState({ value: this.props.stateOrDevice.value });
} else if ( } else if (
this.props.stateOrDevice.kind === "motionSensor" && this.props.stateOrDevice.kind === "motionSensor" &&
this.props.stateOrDevice.detected !== this.props.stateOrDevice.detected !== prevProps.stateOrDevice.detected
prevProps.stateOrDevice.detected
) { ) {
this.setState({ this.setState({
motion: true, motion: true,
@ -126,9 +125,11 @@ class Sensor extends Component {
temperatureColor = (value) => { temperatureColor = (value) => {
let hue = 100; let hue = 100;
if (value >= 20 && value < 30) { const min = 16;
hue = 50; const max = 20;
} else if (value >= 30) { if (value >= min && value < max) {
hue = 100 - ((value - min) * 100) / (max - min);
} else if (value >= max) {
hue = 0; hue = 0;
} }
return `hsl(${hue}, 100%, 50%)`; return `hsl(${hue}, 100%, 50%)`;
@ -140,23 +141,16 @@ class Sensor extends Component {
<div <div
style={{ style={{
...motionSensorOuterCircle, ...motionSensorOuterCircle,
backgroundColor: this.state.detected backgroundColor: this.state.detected ? "#505bda" : "#00bdaa",
? "#505bda"
: "#00bdaa",
}} }}
> >
<div <div
style={{ style={{
...motionSensorInnerCircle, ...motionSensorInnerCircle,
backgroundColor: this.state.detected backgroundColor: this.state.detected ? "#fe346e" : "#00bdaa",
? "#fe346e"
: "#00bdaa",
}} }}
> >
<Image <Image style={motionSensorIcon} src="/img/motionSensorIcon.svg" />
style={motionSensorIcon}
src="/img/motionSensorIcon.svg"
/>
<span style={nameMotionStyle}>Motion Sensor</span> <span style={nameMotionStyle}>Motion Sensor</span>
</div> </div>
</div> </div>
@ -180,11 +174,8 @@ class Sensor extends Component {
<CircularProgress <CircularProgress
strokeWidth="2rem" strokeWidth="2rem"
stroke={ stroke={
this.props.stateOrDevice.sensor === this.props.stateOrDevice.sensor === "TEMPERATURE"
"TEMPERATURE" ? this.temperatureColor(this.state.value)
? this.temperatureColor(
this.state.value
)
: this.colors.progress : this.colors.progress
} }
fill={this.colors.circle} fill={this.colors.circle}
@ -201,12 +192,7 @@ class Sensor extends Component {
fontWeight="bold" fontWeight="bold"
fill={this.colors.text} fill={this.colors.text}
> >
{ {+(Math.round(this.state.value + "e+2") + "e-2")}
+(
Math.round(this.state.value + "e+2") +
"e-2"
)
}
{this.units} {this.units}
</text> </text>
<text <text
@ -223,10 +209,7 @@ class Sensor extends Component {
{this.name} {this.name}
</text> </text>
</CircularInput> </CircularInput>
<Image <Image style={iconSensorStyle} src={`/img/${this.icon}`} />
style={iconSensorStyle}
src={`/img/${this.icon}`}
/>
</React.Fragment> </React.Fragment>
)} )}
</div> </div>

View file

@ -8,10 +8,7 @@ import ScenesNavbar from "./ScenesNavbar";
import HostsNavbar from "./HostsNavbar"; import HostsNavbar from "./HostsNavbar";
import MyHeader from "../components/HeaderController"; import MyHeader from "../components/HeaderController";
import { Grid, Responsive, Button, Menu } from "semantic-ui-react"; import { Grid, Responsive, Button, Menu } from "semantic-ui-react";
import { import { mobilePanelStyle } from "../components/dashboard/devices/styleComponents";
panelStyle,
mobilePanelStyle,
} from "../components/dashboard/devices/styleComponents";
import { RemoteService } from "../remote"; import { RemoteService } from "../remote";
import { connect } from "react-redux"; import { connect } from "react-redux";
@ -85,7 +82,7 @@ class Dashboard extends Component {
//in case a room has one. //in case a room has one.
let backgroundImageHelper; let backgroundImageHelper;
if (this.activeTab === "Devices") { if (this.activeTab === "Devices") {
backgroundImageHelper = this.props.allRooms; backgroundImageHelper = this.props.backgroundImage;
} else { } else {
backgroundImageHelper = null; backgroundImageHelper = null;
} }
@ -223,20 +220,11 @@ const mapStateToProps = (state, _) => ({
get currentRoom() { get currentRoom() {
return state.active.activeRoom; return state.active.activeRoom;
}, },
//this took me way longer to figure out than it should have get backgroundImage() {
get allRooms() { if (state.active.activeRoom === -1) {
if (state.active.activeRoom == -1) {
return null;
}
for (let i in state.rooms) {
if (i == state.active.activeRoom) {
//console.log("check",state.rooms[i].image)
if (state.rooms[i].image === undefined) {
return null; return null;
} else { } else {
return state.rooms[i].image; return state.rooms[state.active.activeRoom].image;
}
}
} }
}, },
}); });