Add colors that show the current state
This commit is contained in:
parent
a9ff3d9f35
commit
30adb36bae
3 changed files with 34 additions and 2 deletions
|
|
@ -43,7 +43,7 @@ const config : Config = {
|
||||||
rundumleuchte: {
|
rundumleuchte: {
|
||||||
state: "/service/openhab/out/pca301_rundumleuchte/state",
|
state: "/service/openhab/out/pca301_rundumleuchte/state",
|
||||||
command: "/service/openhab/in/pca301_rundumleuchte/command",
|
command: "/service/openhab/in/pca301_rundumleuchte/command",
|
||||||
value: "ON",
|
value: "OFF",
|
||||||
values: { on: "ON", off: "OFF" }
|
values: { on: "ON", off: "OFF" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -52,6 +52,7 @@ const config : Config = {
|
||||||
name: "LED Stahlträger",
|
name: "LED Stahlträger",
|
||||||
position: [360, 80],
|
position: [360, 80],
|
||||||
icon: "wb_incandescent",
|
icon: "wb_incandescent",
|
||||||
|
iconColor: state => state.led_stahltraeger == "on" ? "#CCCC00" : "#000000",
|
||||||
ui: [
|
ui: [
|
||||||
{
|
{
|
||||||
type: "toggle",
|
type: "toggle",
|
||||||
|
|
@ -64,6 +65,7 @@ const config : Config = {
|
||||||
name: "Snackbar",
|
name: "Snackbar",
|
||||||
position: [560, 200],
|
position: [560, 200],
|
||||||
icon: "kitchen",
|
icon: "kitchen",
|
||||||
|
iconColor: state => state.snackbar == "on" ? "#E20074" : "#000000",
|
||||||
ui: [
|
ui: [
|
||||||
{
|
{
|
||||||
type: "toggle",
|
type: "toggle",
|
||||||
|
|
@ -76,6 +78,7 @@ const config : Config = {
|
||||||
name: "Twinkle",
|
name: "Twinkle",
|
||||||
position: [500, 280],
|
position: [500, 280],
|
||||||
icon: "wb_incandescent",
|
icon: "wb_incandescent",
|
||||||
|
iconColor: state => state.twinkle == "on" ? "#CCCC00" : "#000000",
|
||||||
ui: [
|
ui: [
|
||||||
{
|
{
|
||||||
type: "toggle",
|
type: "toggle",
|
||||||
|
|
@ -88,6 +91,7 @@ const config : Config = {
|
||||||
name: "Fliegenbratgerät",
|
name: "Fliegenbratgerät",
|
||||||
position: [450, 320],
|
position: [450, 320],
|
||||||
icon: "whatshot",
|
icon: "whatshot",
|
||||||
|
iconColor: state => state.flyfry == "on" ? "#6666FF" : "#000000",
|
||||||
ui: [
|
ui: [
|
||||||
{
|
{
|
||||||
type: "toggle",
|
type: "toggle",
|
||||||
|
|
@ -100,6 +104,15 @@ const config : Config = {
|
||||||
name: "Artnet",
|
name: "Artnet",
|
||||||
position: [560,165],
|
position: [560,165],
|
||||||
icon: "wb_incandescent",
|
icon: "wb_incandescent",
|
||||||
|
iconColor: state =>
|
||||||
|
({
|
||||||
|
off: "#000000",
|
||||||
|
yellow: "#CCCC00",
|
||||||
|
red: "#FF0000",
|
||||||
|
purple: "#FF00FF",
|
||||||
|
green: "#00FF00",
|
||||||
|
cycle: "#CCCC00"
|
||||||
|
})[state.artnet],
|
||||||
ui: [
|
ui: [
|
||||||
{
|
{
|
||||||
type: "toggle",
|
type: "toggle",
|
||||||
|
|
@ -141,6 +154,7 @@ const config : Config = {
|
||||||
name: "Rundumleuchte",
|
name: "Rundumleuchte",
|
||||||
position: [240,210],
|
position: [240,210],
|
||||||
icon: "wb_sunny",
|
icon: "wb_sunny",
|
||||||
|
iconColor: state => state.rundumleuchte == "on" ? "#CCCC00" : "#000000",
|
||||||
ui: [
|
ui: [
|
||||||
{
|
{
|
||||||
type: "toggle",
|
type: "toggle",
|
||||||
|
|
|
||||||
19
src/map.js
19
src/map.js
|
|
@ -11,11 +11,28 @@ import ReactDOM from "react-dom";
|
||||||
// convert width/height coordinates to -height/width coordinates
|
// convert width/height coordinates to -height/width coordinates
|
||||||
const c = (p) => [-p[1], p[0]]
|
const c = (p) => [-p[1], p[0]]
|
||||||
|
|
||||||
|
const keyOf = (map: Map<any,any>, value: any) : ?any =>
|
||||||
|
((keys) => keys[R.findIndex(k => map[k] == value, keys)])
|
||||||
|
(R.keys(map));
|
||||||
|
|
||||||
|
const color = (iconColor, state: State) => {
|
||||||
|
console.log(
|
||||||
|
R.mapObjIndexed((x,k) => keyOf(Config.topics[k].values, x), state.values)
|
||||||
|
); return iconColor == null ? "#000000" :
|
||||||
|
iconColor(
|
||||||
|
R.mapObjIndexed((x,k) => keyOf(Config.topics[k].values, x), state.values)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const iconHtml = (el, state: State) =>
|
||||||
|
"<i class=\"material-icons\" style=\""
|
||||||
|
+ "color:" + color(el.iconColor, state) + ";\">"
|
||||||
|
+ el.icon + "</i>"
|
||||||
|
|
||||||
const Markers = (props) => R.values(R.mapObjIndexed((el,key) => (
|
const Markers = (props) => R.values(R.mapObjIndexed((el,key) => (
|
||||||
<Marker position={c(el.position)} key={el.name}
|
<Marker position={c(el.position)} key={el.name}
|
||||||
icon={Leaflet.divIcon(
|
icon={Leaflet.divIcon(
|
||||||
{
|
{
|
||||||
html: "<i class=\"material-icons\">" + el.icon + "</i>",
|
html: iconHtml(el, props.state),
|
||||||
iconSize: Leaflet.point(32,32)
|
iconSize: Leaflet.point(32,32)
|
||||||
})}>
|
})}>
|
||||||
<Popup onOpen={() => props.store.dispatch({type: "uiopen", ui: key})}
|
<Popup onOpen={() => props.store.dispatch({type: "uiopen", ui: key})}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ declare type Control = {
|
||||||
name: string,
|
name: string,
|
||||||
position: Array<number>,
|
position: Array<number>,
|
||||||
icon: string,
|
icon: string,
|
||||||
|
iconColor?: (state: Map<string,any>) => string,
|
||||||
ui: Array<ControlUI>
|
ui: Array<ControlUI>
|
||||||
};
|
};
|
||||||
declare type Controls = Map<string,Control>;
|
declare type Controls = Map<string,Control>;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue