-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
323 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
'use strict' | ||
|
||
var path = require('path') | ||
var appRoot = path.dirname(require.main.filename) | ||
const http = require('http') | ||
const querystring = require('querystring') | ||
if (appRoot.endsWith('bin')) { appRoot = appRoot + '/../lib' } | ||
if (appRoot.endsWith('node_modules/daemonize2/lib')) { appRoot = path.join(appRoot, '..', '..', '..', 'node_modules', 'homematic-virtual-interface', 'lib') } | ||
appRoot = path.normalize(appRoot) | ||
|
||
var HomematicVirtualPlatform = require(appRoot + '/HomematicVirtualPlatform.js') | ||
|
||
const url = require('url') | ||
|
||
module.exports = class DenonAVRHTTP extends HomematicVirtualPlatform { | ||
init () { | ||
this.hm_layer = this.server.getBridge() | ||
var devfile = path.join(__dirname, 'HM-RC-19_Denon.json') | ||
this.server.publishHMDevice(this.getName(), 'HM-RC-19_Denon', devfile, 2) | ||
this.reinit() | ||
this.plugin.initialized = true | ||
this.log.info('initialization completed %s', this.plugin.initialized) | ||
} | ||
|
||
reinit () { | ||
let self = this | ||
this.hm_layer.deleteDevicesByOwner(this.name) | ||
this.remotes = [] | ||
this.configuration = this.server.configuration | ||
let numOfRemotes = parseInt(this.configuration.getValueForPluginWithDefault(this.name, 'numOfRemotes', 1)) | ||
for (var i = 0; i < numOfRemotes; i++) { | ||
let serial = 'HMD0000' + String(i) | ||
let hmDevice = this.bridge.initDevice(this.getName(), serial, 'HM-RC-19_Denon', serial) | ||
|
||
hmDevice.on('device_channel_value_change', function (parameter) { | ||
if (parameter.name === 'PRESS_SHORT') { | ||
let channel = hmDevice.getChannel(parameter.channel) | ||
let command = channel.getParamsetValueWithDefault('MASTER', 'CMD_PRESS_SHORT', undefined) | ||
if (command) { | ||
self.log.debug('PRESS_SHORT Command is %s', command) | ||
self.sendCommand(command) | ||
} | ||
} | ||
|
||
if (parameter.name === 'PRESS_LONG') { | ||
let channel = hmDevice.getChannel(parameter.channel) | ||
let command = channel.getParamsetValueWithDefault('MASTER', 'CMD_PRESS_LONG', undefined) | ||
if (command) { | ||
self.log.debug('PRESS_LONG Command is %s', command) | ||
self.sendCommand(command) | ||
} | ||
} | ||
|
||
if (parameter.name === 'TARGET_VOLUME') { | ||
let newVolume = parameter.newValue | ||
self.sendCommand('MV' + newVolume) | ||
} | ||
}) | ||
this.remotes.push(hmDevice) | ||
} | ||
setInterval(() => { | ||
self.getVolume() | ||
}, 10000) | ||
} | ||
|
||
getVolume () { | ||
let self = this | ||
let hmDevice = this.remotes[0] | ||
if (hmDevice) { | ||
let host = this.config.getValueForPlugin(this.name, 'host') | ||
this.log.info('Connecting to %s', host) | ||
let urlCommand = querystring.stringify('MV?') | ||
this.log.info('Command is %s', urlCommand) | ||
let responseData | ||
const options = { | ||
hostname: host, | ||
port: 8080, | ||
path: '/goform/formiPhoneAppDirect.xml?' + urlCommand, | ||
method: 'GET' | ||
} | ||
|
||
const req = http.request(options, res => { | ||
res.on('data', d => { | ||
responseData = responseData + d | ||
}) | ||
|
||
res.on('end', () => { | ||
// check on errors | ||
try { | ||
if (responseData) { | ||
let channel = hmDevice.getChannel(19) | ||
if (channel) { | ||
self.log.debug('Got volume set to %s', responseData) | ||
channel.updateValue('TARGET_VOLUME', responseData, true, true) | ||
} | ||
} | ||
} catch (e) {} | ||
}) | ||
}) | ||
|
||
req.end() | ||
} | ||
} | ||
|
||
sendCommand (command) { | ||
let self = this | ||
let host = this.config.getValueForPlugin(this.name, 'host') | ||
this.log.info('Connecting to %s', host) | ||
let urlCommand = querystring.stringify(command) | ||
this.log.info('Command is %s', urlCommand) | ||
const options = { | ||
hostname: host, | ||
port: 8080, | ||
path: '/goform/formiPhoneAppDirect.xml?' + urlCommand, | ||
method: 'GET' | ||
} | ||
|
||
const req = http.request(options, res => { | ||
self.log.debug('Request sent') | ||
}) | ||
|
||
req.end() | ||
} | ||
|
||
showSettings () { | ||
var result = [] | ||
|
||
let host = this.configuration.getValueForPlugin(this.name, 'host') | ||
let numOfRemotes = this.configuration.getValueForPlugin(this.name, 'numOfRemotes') | ||
|
||
result.push({'control': 'text', 'name': 'host', 'label': 'AVR Host -IP', 'value': host}) | ||
result.push({'control': 'text', 'name': 'numOfRemotes', 'label': 'Number of remotes', 'value': numOfRemotes}) | ||
return result | ||
} | ||
|
||
saveSettings (settings) { | ||
var host = settings.host | ||
var numOfRemotes = settings.numOfRemotes | ||
if (host) { | ||
this.configuration.setValueForPlugin(this.name, 'host', host) | ||
} | ||
if (numOfRemotes) { | ||
this.configuration.setValueForPlugin(this.name, 'numOfRemotes', numOfRemotes) | ||
} | ||
this.reinit() | ||
} | ||
|
||
handleConfigurationRequest (dispatchedRequest) { | ||
var template = 'index.html' | ||
var requesturl = dispatchedRequest.request.url | ||
var queryObject = url.parse(requesturl, true).query | ||
var deviceList = '' | ||
|
||
if (queryObject['do'] !== undefined) { | ||
switch (queryObject['do']) { | ||
case 'app.js': | ||
{ | ||
template = 'app.js' | ||
} | ||
break | ||
} | ||
} | ||
|
||
dispatchedRequest.dispatchFile(this.plugin.pluginPath, template, {'listDevices': deviceList}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
{ | ||
"channels": [ | ||
{ | ||
"flags": 3, | ||
"paramsets": [{ | ||
"name": "MASTER", | ||
"id": "maint_ch_master", | ||
"parameter": [] | ||
}, { | ||
"name": "VALUES", | ||
"id": "maint_ch_values", | ||
"parameter": [{ | ||
"flags": 9, | ||
"operations": 5, | ||
"name": "UNREACH", | ||
"type": "BOOL", | ||
"tab_order": 0 | ||
}, { | ||
"flags": 24, | ||
"operations": 7, | ||
"name": "STICKY_UNREACH", | ||
"type": "BOOL", | ||
"tab_order": 1 | ||
}, { | ||
"flags": 9, | ||
"operations": 5, | ||
"name": "CONFIG_PENDING", | ||
"type": "BOOL", | ||
"tab_order": 2 | ||
}, { | ||
"flags": 9, | ||
"operations": 5, | ||
"name": "LOWBAT", | ||
"type": "BOOL", | ||
"tab_order": 3 | ||
}, { | ||
"type": "INTEGER", | ||
"max": 127, | ||
"min": 0, | ||
"flags": 0, | ||
"tab_order": 4, | ||
"name": "AES_KEY", | ||
"operations": 1 | ||
}, { | ||
"flags": 1, | ||
"operations": 5, | ||
"name": "RSSI_DEVICE", | ||
"type": "INTEGER", | ||
"tab_order": 5 | ||
}, { | ||
"flags": 1, | ||
"operations": 5, | ||
"name": "RSSI_PEER", | ||
"type": "INTEGER", | ||
"tab_order": 6 | ||
}] | ||
}], | ||
"type": "MAINTENANCE", | ||
"adress": "0", | ||
"direction": 2 | ||
}, | ||
{ | ||
"adress": ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18"], | ||
"type": "KEY", | ||
"flags": 1, | ||
"direction" : 0, | ||
"paramsets": [ | ||
{ | ||
"name" : "MASTER", | ||
"id" : "", | ||
"parameter" : [{"name":"AES_ACTIVE","operations":3,"tab_order":2,"max":"","min":"","type":"BOOL","flags":3},{"name":"DBL_PRESS_TIME","operations":3,"tab_order":1,"unit":"s","max":1.5,"min":0,"type":"FLOAT","vdefault":0,"flags":1},{"name":"LONG_PRESS_TIME","operations":3,"tab_order":0,"unit":"s","max":1.8,"min":0.3,"type":"FLOAT","vdefault":0.4,"flags":1},{"name": "CMD_PRESS_SHORT","flags": 1,"vdefault":"","min":"","max":"","unit":"","operations": 3,"tab_order": 0,"type": "STRING"},{"name": "CMD_PRESS_LONG","flags": 1,"vdefault":"","min":"","max":"","unit":"","operations": 3,"tab_order": 0,"type": "STRING"}] | ||
}, | ||
{ | ||
"name" : "VALUES", | ||
"id" : "remote_ch_values", | ||
"parameter" : [{"name":"INSTALL_TEST","operations":4,"tab_order":2,"max":"","min":"","type":"ACTION","flags":3},{"name":"PRESS_CONT","operations":4,"tab_order":3,"max":"","min":"","type":"ACTION","flags":3},{"name":"PRESS_LONG","operations":6,"tab_order":1,"max":"","control":"BUTTON.LONG","min":"","type":"ACTION","flags":1},{"name":"PRESS_LONG_RELEASE","operations":4,"tab_order":4,"max":"","min":"","type":"ACTION","flags":3},{"name":"PRESS_SHORT","operations":6,"tab_order":0,"max":"","control":"BUTTON.SHORT","min":"","type":"ACTION","flags":1}] | ||
}, | ||
|
||
|
||
|
||
{ | ||
"name" : "LINK", | ||
"id" : "remote_ch_link", | ||
"parameter" : [{"name":"EXPECT_AES","operations":3,"tab_order":1,"max":"","min":"","type":"BOOL","flags":1},{"name":"PEER_NEEDS_BURST","operations":3,"tab_order":0,"max":"","min":"","type":"BOOL","flags":1}] | ||
} | ||
|
||
|
||
] | ||
}, | ||
{ | ||
"adress": "19", | ||
"type": "KEY", | ||
"flags": 1, | ||
"direction" : 0, | ||
"paramsets": [ | ||
|
||
{ | ||
"name" : "MASTER", | ||
"id" : "", | ||
"parameter" : [{"name":"AES_ACTIVE","operations":3,"tab_order":2,"max":"","min":"","type":"BOOL","flags":3}] | ||
}, | ||
|
||
{ | ||
"name" : "VALUES", | ||
"id" : "", | ||
"parameter" : [ | ||
{"name": "TARGET_VOLUME","vdefault": "","flags": 1,"max": "","min": "","operations": 7,"control":"NONE","unit":"","tab_order": 0,"type": "STRING"} | ||
] | ||
} | ||
] | ||
} | ||
|
||
], | ||
|
||
|
||
"type": "HM-RC-19", | ||
"version": 41, | ||
"paramsets": [] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var path = require('path') | ||
var DenonAVRHTTP = require(path.join(__dirname, '/DenonAVRHTTP')) | ||
|
||
module.exports = function (server, name, logger, instance) { | ||
this.name = name | ||
this.instance = instance | ||
this.initialized = false | ||
this.platform = new DenonAVRHTTP(this, name, server, logger, instance) | ||
this.platform.init() | ||
|
||
this.handleConfigurationRequest = function (dispatchedRequest) { | ||
this.platform.handleConfigurationRequest(dispatchedRequest) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "homematic-virtual-denonavrhttp", | ||
"version": "0.0.1", | ||
"description": "Virtual Plugin - DenonAVRHTTP", | ||
"license": "ISC", | ||
"keywords": [ | ||
"homematic-virtual-plugin" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/" | ||
}, | ||
"bugs": { | ||
"url": "http://" | ||
}, | ||
"engines": { | ||
"node": ">=4.5.0", | ||
"homematic-virtual-interface" : ">=0.0.4" | ||
}, | ||
|
||
"dependencies": { | ||
} | ||
} |