Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,24 @@ Here's an example.
"var2":" val2"
}
},
{
"name": "Start Party Time from anywhere",
"address": "d8:02:dc:98:63:49",
"interface": "en0",
"timeout": "60000",
"url": "https://home.example.com/api/services/scene/turn_on",
"insecure": true,
"method": "POST",
"headers": {"x-ha-access": "your_password"},
"json": true,
"body": {"entity_id": "scene.party_time"}
},
{
"name": "Start Cooking Playlist",
"address": "66:a0:dc:98:d2:63",
"url": "http://192.168.1.55:8181/playlists/cooking/play",
"method": "PUT"
},
}
]}
```

Expand All @@ -67,6 +79,7 @@ Buttons take up to 7 options.
* `interface` - Optionally listen for the button on a specific network interface. (`enX` on OS X and `ethX` on Linux)
* `timeout` - Optionally set the time required between button press detections (if multiple pressese are detected) in milliseconds
* `url` - The URL that will be requested.
* `insecure` - Optionally skip SSL certificate verification. Default is `false`.
* `method` - The HTTP method of the request.
* `headers` - Optional headers to use in the request.
* `json` - Optionally declare the content body as being JSON in the request.
Expand Down
12 changes: 12 additions & 0 deletions config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
"json": true,
"body": {"entity_id": "scene.party_time"}
},
{
"name": "Start Party Time from anywhere",
"address": "d8:02:dc:98:63:49",
"interface": "en0",
"timeout": "60000",
"url": "https://home.example.com/api/services/scene/turn_on",
"insecure": true,
"method": "POST",
"headers": {"x-ha-access": "your_password"},
"json": true,
"body": {"entity_id": "scene.party_time"}
},
{
"name": "Start Cooking Playlist",
"address": "66:a0:dc:98:d2:63",
Expand Down
40 changes: 31 additions & 9 deletions lib/dasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ function doLog(message) {
}

function DasherButton(button) {
var options = {headers: button.headers, body: button.body, json: button.json, formData: button.formData}
var options = {
headers: button.headers,
body: button.body,
json: button.json,
insecure: button.insecure,
formData: button.formData
}

this.dashButton = dashButton(button.address, button.interface, button.timeout)

Expand All @@ -24,15 +30,31 @@ function doRequest(requestUrl, method, options, callback) {
options.query = options.query || {}
options.json = options.json || false
options.headers = options.headers || {}
options.insecure = options.insecure || false

var reqOpts = {
url: url.parse(requestUrl),
method: method || 'GET',
qs: options.query,
body: options.body,
json: options.json,
headers: options.headers,
formData: options.formData
if (options.insecure) {
var reqOpts = {
url: url.parse(requestUrl),
method: method || 'GET',
qs: options.query,
body: options.body,
json: options.json,
headers: options.headers,
formData: options.formData,
rejectUnauthorized: false,
requestCert: true,
agent: false
}
} else {
var reqOpts = {
url: url.parse(requestUrl),
method: method || 'GET',
qs: options.query,
body: options.body,
json: options.json,
headers: options.headers,
formData: options.formData,
}
}

request(reqOpts, function onResponse(error, response, body) {
Expand Down