49 lines
1.4 KiB
Lua
49 lines
1.4 KiB
Lua
SERVICE_NAME = "LGTV & Denon AVR input merge"
|
|
SERVICE_VERSION = "1.0.0"
|
|
|
|
TOPIC_TV_INPUT = "wohnzimmer/tv/input";
|
|
TOPIC_SOURCE = "wohnzimmer/tv/input/set";
|
|
|
|
TOPIC_LGTV_INPUT = "wohnzimmer/lgtv/input";
|
|
TOPIC_AVR_INPUT = "wohnzimmer/avr/input";
|
|
TOPIC_LGTV_INPUT_SET = "wohnzimmer/lgtv/input/set";
|
|
TOPIC_AVR_INPUT_SET = "wohnzimmer/avr/input/set";
|
|
|
|
AVR_INPUT_ON_TV = "hdmi3"
|
|
AVR_INPUTS = {"playstation", "xbox", "nintendo", "appletv", "wiiu"}
|
|
|
|
function thrawn_on_start()
|
|
thrawn_register_service(SERVICE_NAME)
|
|
|
|
thrawn_log("Starting LUA Service " .. SERVICE_NAME)
|
|
|
|
|
|
thrawn_subscribe(TOPIC_SOURCE)
|
|
end
|
|
|
|
function is_avr_input(input)
|
|
for _, avr_input in ipairs(AVR_INPUTS) do
|
|
if input == avr_input then
|
|
return true
|
|
end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
function thrawn_on_update(state)
|
|
thrawn_log("RECV: " .. state.value .. " ON TOPIC " .. state.topic)
|
|
|
|
if state.topic == TOPIC_SOURCE then
|
|
if is_avr_input(state.value) then
|
|
thrawn_publish(thrawn_create_topic_state(TOPIC_LGTV_INPUT_SET, AVR_INPUT_ON_TV))
|
|
thrawn_publish(thrawn_create_topic_state(TOPIC_AVR_INPUT_SET, state.value))
|
|
end
|
|
elseif state.topic == TOPIC_LGTV_INPUT or TOPIC_AVR_INPUT then
|
|
if TOPIC_LGTV_INPUT == AVR_INPUT_ON_TV then
|
|
thrawn_publish(thrawn_create_topic_state(TOPIC_TV_INPUT, thrawn_cached_topic(TOPIC_AVR_INPUT)))
|
|
else
|
|
thrawn_publish(thrawn_create_topic_state(TOPIC_TV_INPUT, thrawn_cached_topic(TOPIC_LGTV_INPUT)))
|
|
end
|
|
end
|
|
end |