From da7105c90b2398c8d9e2dd95fc22b30d402ad468 Mon Sep 17 00:00:00 2001 From: uwap Date: Sun, 14 Jan 2018 01:20:30 +0100 Subject: [PATCH] Add basic esper status info support --- config/rzl.js | 11 ++++++----- config/utils.js | 25 +++++++++++++++++++++++++ src/components/UiItemList/UiItem.js | 9 +++++++++ src/components/UiItemList/index.js | 7 ++++++- types/types.js | 5 +++++ 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/config/rzl.js b/config/rzl.js index bfd4bbf..7179ae1 100644 --- a/config/rzl.js +++ b/config/rzl.js @@ -7,7 +7,7 @@ const config : Config = { color: "orange", mqtt: "ws://map.rzl:1884" }, - topics: { + topics: Object.assign({}, { led_stahltraeger: { state: "/service/openhab/out/pca301_ledstrips/state", command: "/service/openhab/in/pca301_ledstrips/command", @@ -116,8 +116,9 @@ const config : Config = { command: "/service/openhab/in/pca301_infoscreen/command", defaultValue: "OFF", values: { on: "ON", off: "OFF" } - } - }, + }}, + utils.esper_topics("afba40") + ), controls: { led_stahltrager: { name: "LED Stahlträger", @@ -220,14 +221,14 @@ const config : Config = { position: [450, 590], icon: "fire", iconColor: ({flyfry}) => flyfry == "on" ? "#6666FF" : "#000000", - ui: [ + ui: utils.esper_statistics("afba40", [ { type: "toggle", text: "Fliegenbratgerät", topic: "flyfry", icon: "power" } - ] + ]) }, artnet: { name: "Artnet", diff --git a/config/utils.js b/config/utils.js index 35503de..f778bb9 100644 --- a/config/utils.js +++ b/config/utils.js @@ -2,3 +2,28 @@ export const rainbow = "rgba(200,120,120,0.5);" + "--before-background: linear-gradient(40deg, #FF0000 0%, #00FF00 50%, #0000FF 70%, #FFFF00 100%);"; + +export const esper_topics = (chip_id: string) => ({ + [ `esper_${chip_id}_version` ]: { + state: `/service/esper/${chip_id}/info`, + command: "", + defaultValue: "UNKNOWN", + values: {}, + parseState: msg => JSON.parse(msg.toString()).version.esper + } +}); + +export const esper_statistics = (chip_id: string, + prev_ui: Array = []) => ( + prev_ui.concat([ + { + type: "section", + text: "Funkdose" + }, + { + type: "text", + text: "Version", + topic: `esper_${chip_id}_version` + } + ]) + ); diff --git a/src/components/UiItemList/UiItem.js b/src/components/UiItemList/UiItem.js index b58b8ab..8cb7d01 100644 --- a/src/components/UiItemList/UiItem.js +++ b/src/components/UiItemList/UiItem.js @@ -172,3 +172,12 @@ export class Section extends UiItem { ); } } + +export class Text extends UiItem { + render() { + return [ + , + + ]; + } +} diff --git a/src/components/UiItemList/index.js b/src/components/UiItemList/index.js index bba000d..d6e3d8f 100644 --- a/src/components/UiItemList/index.js +++ b/src/components/UiItemList/index.js @@ -20,7 +20,7 @@ import Button from "material-ui/Button"; import Slider from "material-ui-old/Slider"; import MuiThemeProvider from "material-ui-old/styles/MuiThemeProvider"; -import { Toggle, DropDown, Link, Section } from "./UiItem"; +import { Toggle, DropDown, Link, Section, Text } from "./UiItem"; export type UiItemListProps = { controls: Array, @@ -78,6 +78,11 @@ export default class UiItemList extends React.Component { case "slider": { return this.renderSlider(control); } + case "text": { + return ; + } default: { throw new Error( `Unknown UI type "${control.type}" for "${control.text}" component` diff --git a/types/types.js b/types/types.js index f08b1aa..caf4ea3 100644 --- a/types/types.js +++ b/types/types.js @@ -50,12 +50,17 @@ declare type UILink = { link: string } & UIBase; +declare type UIText = { + type: "text" +} & UIBase; + declare type ControlUI = UIToggle | UIDropDown | UISlider | UISection | UILink + | UIText declare type Control = { name: string,