From 2728e082bd7a6e2fdf4c543ba114406740721fca Mon Sep 17 00:00:00 2001 From: Ranlvor Date: Sat, 4 Aug 2018 16:27:26 +0200 Subject: [PATCH] RZL: show online-state of tasmota-devices in icon color --- config/rzl/index.js | 6 +++--- config/rzl/utils.js | 13 +++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/config/rzl/index.js b/config/rzl/index.js index c73aab7..c823d6c 100644 --- a/config/rzl/index.js +++ b/config/rzl/index.js @@ -254,7 +254,7 @@ const config: Config = { name: "Snackbar", position: [510, 500], icon: mdi("fridge"), - iconColor: ({snackbar}) => snackbar == "on" ? hex("#E20074") : hex("#000000"), + iconColor: tasmota.icon_color("snackbar", hex("#E20074")), ui: [ { type: "toggle", @@ -338,7 +338,7 @@ const config: Config = { name: "Drucker", position: [335, 90], icon: mdi("printer"), - iconColor: ({olymp_printer}) => olymp_printer == "on" ? hex("#00FF00") : hex("#000000"), + iconColor: tasmota.icon_color("olymp_printer"), ui: [ { type: "toggle", @@ -470,7 +470,7 @@ const config: Config = { name: "Infoscreen", position: [255, 495], icon: mdi("television-guide flip-v"), - iconColor: ({infoscreen}) => infoscreen == "on" ? hex("#4444FF") : hex("#000000"), + iconColor: tasmota.icon_color("infoscreen", hex("#4444FF")), ui: [ { type: "toggle", diff --git a/config/rzl/utils.js b/config/rzl/utils.js index 9fc926a..ad27129 100644 --- a/config/rzl/utils.js +++ b/config/rzl/utils.js @@ -1,6 +1,7 @@ // @flow import type { ControlUI } from "config/flowtypes"; import { mdi } from "config/icon"; +import { hex } from "config/colors"; import * as types from "config/types"; export const esper_topics = (chip_id: string, name: string) => ({ @@ -54,8 +55,16 @@ export const tasmota = { type: types.option({ on: "ON", off: "OFF" }) }, defaultValue: "off" - } - }) + }, + [`${name}_online`]: { + state: { + name: `tele/sonoff${id}/LWT`, + type: types.option({ online: "online", offline: "offline" }) + }, + defaultValue: "offline" + }, + }), + icon_color: (name: string, on_color: Color = hex("#00FF00")) => (state) => state[`${name}_online`] == "offline" ? hex("#888888") : (state[name] == "on" ? on_color : hex("#000000")) } export const floalt = { color: (light_id: string) => `floalt_${light_id}_color`,