/
ziggo-api.coffee
36 lines (30 loc) · 961 Bytes
/
ziggo-api.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module.exports = (env) ->
Promise = env.require 'bluebird'
box = require('ziggo-mediabox')
boxButtons = require('ziggo-mediabox/buttons.json')
commons = require('pimatic-plugin-commons')(env)
class ZiggoApi
constructor: (@config) ->
@_base = commons.base @, "ZiggoApi"
_connect: () =>
if @box && @box.isConnected()
return new Promise (resolve, reject) =>
resolve()
else
if !@box
@box = new box @config.ip
return @box.connect()
disconnect: () =>
if @box && @box.isConnected()
return @xbox.disconnect()
return new Promise (resolve, reject) =>
resolve()
sendRequest: (command) =>
return new Promise (resolve, reject) =>
@_connect().then =>
@box.pressButton command
resolve()
.catch (error) =>
reject(error)
getAvailableButtons: () =>
return boxButtons.map (button) => button.name