Skip to content

Commit 3cf2c10

Browse files
Default to local freebox API URL
1 parent 6e1e526 commit 3cf2c10

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

extensions/freebox/freebox.lua

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ local function listLanHosts(client, sessionToken)
8686
return httpRequest(client, 'GET', '/api/v4/lan/browser/'..interface.name..'/', sessionHeaders):next(processResponse)
8787
end))
8888
end):next(function(results)
89-
logger:finer('freebox interfaces are %t', results)
89+
logger:finest('freebox interfaces are %t', results)
9090
local lanHosts = {}
9191
for _, lanHost in pairs(results) do
9292
List.concat(lanHosts, lanHost)
@@ -98,6 +98,10 @@ end
9898

9999
local configuration = extension:getConfiguration()
100100

101+
extension:subscribeEvent('startup', function()
102+
logger:fine('Using freebox API URL is %s', configuration.apiUrl)
103+
end)
104+
101105
extension:subscribeEvent('poll', function()
102106
if not(configuration.apiUrl and configuration.appToken) then
103107
return
@@ -136,14 +140,6 @@ extension:subscribeEvent('poll', function()
136140
end)
137141
end)
138142

139-
function extension:discoverFreebox()
140-
return httpRequest('http://mafreebox.freebox.fr/api_version', 'GET'):next(utils.rejectIfNotOk):next(utils.getJson):next(function(api)
141-
logger:finer('freebox API is %T', api)
142-
configuration.apiUrl = string.format('https://%s:%s%s', api.api_domain, api.https_port, api.api_base_url)
143-
return 'OK'
144-
end)
145-
end
146-
147143
function extension:generateToken(exchange)
148144
if not configuration.apiUrl then
149145
return Promise.reject('The API URL is missing')

extensions/freebox/manifest.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"apiUrl": {
1010
"title": "API URL",
1111
"type": "string",
12-
"pattern": "^https?://.+$"
12+
"pattern": "^https?://.+$",
13+
"default": "https://mafreebox.freebox.fr/"
1314
},
1415
"appToken": {
1516
"title": "Token",
@@ -21,13 +22,8 @@
2122
},
2223
"actions": [
2324
{
24-
"name": "Discover Freebox",
25-
"description": "Look for the Freebox API on the network",
26-
"method": "discoverFreebox",
27-
"active": false
28-
}, {
2925
"name": "Generate Token",
30-
"description": "Generate an application token",
26+
"description": "Generate an application token, need validation on the box",
3127
"method": "generateToken",
3228
"active": false
3329
}

extensions/freebox/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This extension allows to use the Freebox APIs.
44

55
## Setup
66

7-
You need to discover the Freebox API URL and get a token.
7+
You need to generate an application token, start the action in the extension then validate the application on your freebox device.
88

99
## Usage
1010

0 commit comments

Comments
 (0)