steps39 / dtgbot

Telegram Bot for Domoticz
19 stars 18 forks source link

dtgbot can't start if no domoticz variables defined #20

Closed anyremote closed 4 months ago

anyremote commented 4 months ago

/usr/bin/lua5.2 $BotHomePath"dtgbot.lua" 2024-02-08 21:11:53 : Starting dtgbot_version :0.9 20230723091 2024-02-08 21:11:53 : dtg_main_functions_version:0.9 20230723091

...

JSON request http://127.0.0.1:8080/json.htm?type=command&param=getuservariables 2024-02-08 21:11:53 : Domoticz returned getuservariables after 1 attempts 2024-02-08 21:11:53 :

Main process Failed:

Error-->/opt/dtgbot/dtg_domoticz.lua:111: attempt to get length of local 'result' (a nil value)stack traceback: /opt/dtgbot/dtgbot.lua:24: in function '__len' /opt/dtgbot/dtg_domoticz.lua:111: in function 'Domo_Variable_List_Names_IDXs' /opt/dtgbot/dtg_main_functions.lua:15: in function 'DtgBot_Initialise' /opt/dtgbot/dtgbot.lua:119: in function </opt/dtgbot/dtgbot.lua:113> [C]: in function 'xpcall' /opt/dtgbot/dtgbot.lua:112: in main chunk [C]: in ?

this happens because:

function Domo_Variable_List_Names_IDXs() local record, decoded_response, result decoded_response = Domo_Variable_List() result = decoded_response["result"] <--------------it is nil here local variables = {} for i = 1, #result do record = result[i] if type(record) == "table" then variables[record["Name"]] = record["idx"] end end return variables end

proposed fix is

-- returns idx of a user variable from name function Domo_Variable_List_Names_IDXs() local record, decoded_response, result decoded_response = Domo_Variable_List() result = decoded_response["result"] local variables = {} if result ~= nil then for i = 1, #result do record = result[i] if type(record) == "table" then variables[record["Name"]] = record["idx"] end end end return variables end

jvanderzande commented 4 months ago

Fixed in Stability-and-new-install.. Thanks!