Refactor topics: more template-functions, less spaghetti code
This commit is contained in:
parent
95a07d3e4b
commit
ab87278612
1 changed files with 60 additions and 160 deletions
|
|
@ -4,7 +4,7 @@ import * as types from "config/types";
|
||||||
import { mdi, rawMdi } from "config/icon";
|
import { mdi, rawMdi } from "config/icon";
|
||||||
import { hex } from "config/colors";
|
import { hex } from "config/colors";
|
||||||
|
|
||||||
const topicBulb = (bulb: string, argument: string) => ({
|
const topicBulbHomeRust = (bulb: string, argument: string) => ({
|
||||||
[`${bulb}${argument}`]: {
|
[`${bulb}${argument}`]: {
|
||||||
state: {
|
state: {
|
||||||
name: `home-rust/bulb/${bulb}/${argument}`,
|
name: `home-rust/bulb/${bulb}/${argument}`,
|
||||||
|
|
@ -18,6 +18,37 @@ const topicBulb = (bulb: string, argument: string) => ({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const topicBulbState = (bulb: string) => ({
|
||||||
|
[`${bulb}State`]: {
|
||||||
|
state: {
|
||||||
|
name: `zigbee2mqtt/bulb_${bulb}/state`,
|
||||||
|
type: types.option({
|
||||||
|
OFF: "off",
|
||||||
|
ON: "on"
|
||||||
|
})
|
||||||
|
},
|
||||||
|
command: {
|
||||||
|
name: `zigbee2mqtt/bulb_${bulb}/set/state`,
|
||||||
|
type: types.string
|
||||||
|
},
|
||||||
|
defaultValue: "OFF"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const topicBulbNumber = (bulb: string, parameter: string) => ({
|
||||||
|
[`${bulb}${parameter}`]: {
|
||||||
|
state: {
|
||||||
|
name: `zigbee2mqtt/bulb_${bulb}/${parameter}`,
|
||||||
|
type: types.string
|
||||||
|
},
|
||||||
|
command: {
|
||||||
|
name: `zigbee2mqtt/bulb_${bulb}/set/${parameter}`,
|
||||||
|
type: types.string
|
||||||
|
},
|
||||||
|
defaultValue: "0"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const topicHomeBoolean = (name: string, topic: string) => ({
|
const topicHomeBoolean = (name: string, topic: string) => ({
|
||||||
[`${name}`]: {
|
[`${name}`]: {
|
||||||
state: {
|
state: {
|
||||||
|
|
@ -103,48 +134,18 @@ const config: Config = {
|
||||||
},
|
},
|
||||||
topics: [
|
topics: [
|
||||||
{
|
{
|
||||||
|
...topicBulbHomeRust("livingroom", "r"),
|
||||||
/*
|
...topicBulbHomeRust("livingroom", "g"),
|
||||||
*zigbee2mqtt/bulb_livingroom
|
...topicBulbHomeRust("livingroom", "b"),
|
||||||
*zigbee2mqtt/bulb_hallway
|
...topicBulbHomeRust("livingroom", "h"),
|
||||||
*zigbee2mqtt/bulb_bedroom
|
...topicBulbHomeRust("livingroom", "s"),
|
||||||
*/
|
...topicBulbHomeRust("livingroom", "v"),
|
||||||
|
...topicBulbHomeRust("livingroom", "x"),
|
||||||
...topicBulb("livingroom", "r"),
|
...topicBulbHomeRust("livingroom", "y"),
|
||||||
...topicBulb("livingroom", "g"),
|
...topicBulbHomeRust("livingroom", "animation-speed"),
|
||||||
...topicBulb("livingroom", "b"),
|
...topicBulbHomeRust("livingroom", "mode"),
|
||||||
...topicBulb("livingroom", "h"),
|
...topicBulbNumber("livingroom", "brightness"),
|
||||||
...topicBulb("livingroom", "s"),
|
...topicBulbState("livingroom"),
|
||||||
...topicBulb("livingroom", "v"),
|
|
||||||
...topicBulb("livingroom", "x"),
|
|
||||||
...topicBulb("livingroom", "y"),
|
|
||||||
...topicBulb("livingroom", "animation-speed"),
|
|
||||||
...topicBulb("livingroom", "mode"),
|
|
||||||
livingroomBrightness: {
|
|
||||||
state: {
|
|
||||||
name: "zigbee2mqtt/bulb_livingroom/brightness",
|
|
||||||
type: types.string
|
|
||||||
},
|
|
||||||
command: {
|
|
||||||
name: "zigbee2mqtt/bulb_livingroom/set",
|
|
||||||
type: (value) => JSON.stringify({ brightness: value.toString() })
|
|
||||||
},
|
|
||||||
defaultValue: "0"
|
|
||||||
},
|
|
||||||
livingroomState: {
|
|
||||||
state: {
|
|
||||||
name: "zigbee2mqtt/bulb_livingroom/state",
|
|
||||||
type: types.option({
|
|
||||||
OFF: "off",
|
|
||||||
ON: "on"
|
|
||||||
})
|
|
||||||
},
|
|
||||||
command: {
|
|
||||||
name: "zigbee2mqtt/bulb_livingroom/set",
|
|
||||||
type: (value) => JSON.stringify({ state: value.toString() })
|
|
||||||
},
|
|
||||||
defaultValue: "OFF"
|
|
||||||
},
|
|
||||||
nasPower: {
|
nasPower: {
|
||||||
state: {
|
state: {
|
||||||
name: "nas/online",
|
name: "nas/online",
|
||||||
|
|
@ -175,42 +176,10 @@ const config: Config = {
|
||||||
...topicHomeBoolean("livingroomKodiControlled",
|
...topicHomeBoolean("livingroomKodiControlled",
|
||||||
"bulb/livingroom/kodi-controlled"),
|
"bulb/livingroom/kodi-controlled"),
|
||||||
...topicHomeBoolean("bedroomWakeup", "wakeup"),
|
...topicHomeBoolean("bedroomWakeup", "wakeup"),
|
||||||
bedroomBrightness: {
|
...topicBulbNumber("bedroom", "brightness"),
|
||||||
state: {
|
...topicBulbNumber("bedroom", "color_temp"),
|
||||||
name: "zigbee2mqtt/bulb_bedroom/brightness",
|
...topicBulbNumber("hallway", "brightness"),
|
||||||
type: types.string
|
...topicBulbState("bedroom"),
|
||||||
},
|
|
||||||
command: {
|
|
||||||
name: "zigbee2mqtt/bulb_bedroom/set",
|
|
||||||
type: (value) => JSON.stringify({ brightness: value.toString() })
|
|
||||||
},
|
|
||||||
defaultValue: "0"
|
|
||||||
},
|
|
||||||
bedroomColorTemp: {
|
|
||||||
state: {
|
|
||||||
name: "zigbee2mqtt/bulb_bedroom/color_temp",
|
|
||||||
type: types.string
|
|
||||||
},
|
|
||||||
command: {
|
|
||||||
name: "zigbee2mqtt/bulb_bedroom/set",
|
|
||||||
type: (value) => JSON.stringify({ "color_temp": value.toString() })
|
|
||||||
},
|
|
||||||
defaultValue: "0"
|
|
||||||
},
|
|
||||||
bedroomState: {
|
|
||||||
state: {
|
|
||||||
name: "zigbee2mqtt/bulb_bedroom/state",
|
|
||||||
type: types.option({
|
|
||||||
OFF: "off",
|
|
||||||
ON: "on"
|
|
||||||
})
|
|
||||||
},
|
|
||||||
command: {
|
|
||||||
name: "zigbee2mqtt/bulb_bedroom/set",
|
|
||||||
type: (value) => JSON.stringify({ state: value.toString() })
|
|
||||||
},
|
|
||||||
defaultValue: "OFF"
|
|
||||||
},
|
|
||||||
...topicTasmota("fanBedroom", "sonoff-bedroom-fan"),
|
...topicTasmota("fanBedroom", "sonoff-bedroom-fan"),
|
||||||
...topicHomeBoolean("fanBedroomAuto", "temperature-control/bedroom"),
|
...topicHomeBoolean("fanBedroomAuto", "temperature-control/bedroom"),
|
||||||
...topicHomeNumber("fanBedroomTarget",
|
...topicHomeNumber("fanBedroomTarget",
|
||||||
|
|
@ -220,81 +189,12 @@ const config: Config = {
|
||||||
...topicHomeBoolean("lueftenHint", "lueften"),
|
...topicHomeBoolean("lueftenHint", "lueften"),
|
||||||
...topicHomeNumber("fanOfficeTarget",
|
...topicHomeNumber("fanOfficeTarget",
|
||||||
"temperature-control/office/target"),
|
"temperature-control/office/target"),
|
||||||
hallwayBrightness: {
|
...topicBulbNumber("hallway", "brightness"),
|
||||||
state: {
|
...topicBulbState("hallway"),
|
||||||
name: "zigbee2mqtt/bulb_hallway/brightness",
|
...topicBulbNumber("hallway2", "brightness"),
|
||||||
type: types.string
|
...topicBulbState("hallway2"),
|
||||||
},
|
...topicBulbState("office"),
|
||||||
command: {
|
...topicBulbNumber("office", "brightness"),
|
||||||
name: "zigbee2mqtt/bulb_hallway/set",
|
|
||||||
type: (value) => JSON.stringify({ brightness: value.toString() })
|
|
||||||
},
|
|
||||||
defaultValue: "0"
|
|
||||||
},
|
|
||||||
hallwayState: {
|
|
||||||
state: {
|
|
||||||
name: "zigbee2mqtt/bulb_hallway/state",
|
|
||||||
type: types.option({
|
|
||||||
OFF: "off",
|
|
||||||
ON: "on"
|
|
||||||
})
|
|
||||||
},
|
|
||||||
command: {
|
|
||||||
name: "zigbee2mqtt/bulb_hallway/set",
|
|
||||||
type: (value) => JSON.stringify({ state: value.toString() })
|
|
||||||
},
|
|
||||||
defaultValue: "OFF"
|
|
||||||
},
|
|
||||||
hallway2Brightness: {
|
|
||||||
state: {
|
|
||||||
name: "zigbee2mqtt/bulb_hallway2/brightness",
|
|
||||||
type: types.string
|
|
||||||
},
|
|
||||||
command: {
|
|
||||||
name: "zigbee2mqtt/bulb_hallway2/set",
|
|
||||||
type: (value) => JSON.stringify({ brightness: value.toString() })
|
|
||||||
},
|
|
||||||
defaultValue: "0"
|
|
||||||
},
|
|
||||||
hallway2State: {
|
|
||||||
state: {
|
|
||||||
name: "zigbee2mqtt/bulb_hallway2/state",
|
|
||||||
type: types.option({
|
|
||||||
OFF: "off",
|
|
||||||
ON: "on"
|
|
||||||
})
|
|
||||||
},
|
|
||||||
command: {
|
|
||||||
name: "zigbee2mqtt/bulb_hallway2/set",
|
|
||||||
type: (value) => JSON.stringify({ state: value.toString() })
|
|
||||||
},
|
|
||||||
defaultValue: "OFF"
|
|
||||||
},
|
|
||||||
officeBrightness: {
|
|
||||||
state: {
|
|
||||||
name: "zigbee2mqtt/bulb_office/brightness",
|
|
||||||
type: types.string
|
|
||||||
},
|
|
||||||
command: {
|
|
||||||
name: "zigbee2mqtt/bulb_office/set",
|
|
||||||
type: (value) => JSON.stringify({ brightness: value.toString() })
|
|
||||||
},
|
|
||||||
defaultValue: "0"
|
|
||||||
},
|
|
||||||
officeState: {
|
|
||||||
state: {
|
|
||||||
name: "zigbee2mqtt/bulb_office/state",
|
|
||||||
type: types.option({
|
|
||||||
OFF: "off",
|
|
||||||
ON: "on"
|
|
||||||
})
|
|
||||||
},
|
|
||||||
command: {
|
|
||||||
name: "zigbee2mqtt/bulb_office/set",
|
|
||||||
type: (value) => JSON.stringify({ state: value.toString() })
|
|
||||||
},
|
|
||||||
defaultValue: "OFF"
|
|
||||||
},
|
|
||||||
...topicTasmota("speakerOffice", "sonoff-office-speaker")
|
...topicTasmota("speakerOffice", "sonoff-office-speaker")
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
@ -318,7 +218,7 @@ const config: Config = {
|
||||||
max: 255,
|
max: 255,
|
||||||
text: "Helligkeit",
|
text: "Helligkeit",
|
||||||
icon: mdi("brightness-7"),
|
icon: mdi("brightness-7"),
|
||||||
topic: "bedroomBrightness"
|
topic: "bedroombrightness"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "toggle",
|
type: "toggle",
|
||||||
|
|
@ -332,7 +232,7 @@ const config: Config = {
|
||||||
max: 454,
|
max: 454,
|
||||||
text: "Farbtemperatur",
|
text: "Farbtemperatur",
|
||||||
icon: mdi("weather-sunset-down"),
|
icon: mdi("weather-sunset-down"),
|
||||||
topic: "bedroomColorTemp"
|
topic: "bedroomcolor_temp"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -471,7 +371,7 @@ const config: Config = {
|
||||||
max: 255,
|
max: 255,
|
||||||
text: "Helligkeit",
|
text: "Helligkeit",
|
||||||
icon: mdi("brightness-7"),
|
icon: mdi("brightness-7"),
|
||||||
topic: "officeBrightness"
|
topic: "officebrightness"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -494,7 +394,7 @@ const config: Config = {
|
||||||
max: 255,
|
max: 255,
|
||||||
text: "Helligkeit",
|
text: "Helligkeit",
|
||||||
icon: mdi("brightness-7"),
|
icon: mdi("brightness-7"),
|
||||||
topic: "hallwayBrightness"
|
topic: "hallwaybrightness"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -517,7 +417,7 @@ const config: Config = {
|
||||||
max: 255,
|
max: 255,
|
||||||
text: "Helligkeit",
|
text: "Helligkeit",
|
||||||
icon: mdi("brightness-7"),
|
icon: mdi("brightness-7"),
|
||||||
topic: "hallway2Brightness"
|
topic: "hallway2brightness"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -574,7 +474,7 @@ const config: Config = {
|
||||||
max: 255,
|
max: 255,
|
||||||
text: "Helligkeit",
|
text: "Helligkeit",
|
||||||
icon: mdi("brightness-7"),
|
icon: mdi("brightness-7"),
|
||||||
topic: "livingroomBrightness"
|
topic: "livingroombrightness"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "slider",
|
type: "slider",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue