This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Home Connect
#5
I've gotten a bit further here. The HC API requires me to log in to my account and accept the API connection. I have made that part of the script, but the question is how to get this part of the script only to run once when needed. The return is a device_code and a url for logging in to HC account. If the function is run every cycle, the verification url changes, and the device_code also.
Documentation: https://api-docs.home-connect.com/author...evice-flow

Code:
function GetDeviceCode()
  local request_code_url = "https://api.home-connect.com/security/oauth/device_authorization"
  local response_body = {}
  local export_data = {}
 
  local request_body = "client_id=" .. client_id .. "&scope=" .. scope

  local body, code, hdrs, stat = https.request
  {
    url = request_code_url;
    method = "POST";
    headers =
    {
      ["Content-Type"] = "application/x-www-form-urlencoded";
      ["Content-Length"] = #request_body;
    };
    source = ltn12.source.string(request_body);
    sink = ltn12.sink.table(response_body);
  }
  log(code)
   if code == 200 then
    response_decode = json.decode(table.concat(response_body))
    log(response_decode)
    sleep = response_decode["interval"]
    return response_decode["device_code"]
 end
end



response_decode:



Code:
* table:
["expires_in"]
  * number: 600
["verification_uri_complete"]
  * string: https://api.home-connect.com/security/oauth/device_verify?user_code=xxxx-xxxx
["verification_uri"]
  * string: https://api.home-connect.com/security/oauth/device_verify
["user_code"]
  * string: xxxx-xxxx
["device_code"]
  * string: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
["interval"]
  * number: 5
Reply


Messages In This Thread
Home Connect - by tomnord - 24.11.2020, 21:00
RE: Home Connect - by Erwin van der Zwart - 25.11.2020, 22:15
Home Connect - by tomnord - 11.02.2021, 21:17
RE: Home Connect - by admin - 12.02.2021, 12:17
RE: Home Connect - by tomnord - 08.03.2021, 20:03
RE: Home Connect - by admin - 09.03.2021, 06:54
RE: Home Connect - by tomnord - 09.03.2021, 15:32
RE: Home Connect - by Daniel - 09.03.2021, 15:44

Forum Jump: