Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Allow for multiple AVRs on the same network #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
14 changes: 0 additions & 14 deletions denon-avr-config-schema.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,4 @@ module.exports = {
description: "Debug mode. Writes debug messages to the pimatic log, if set to true."
type: "boolean"
default: false
host:
description: "Hostname or IP address of the AVR"
type: "string"
protocol:
description: "The control protocol to be used (HTTP may not work with older receiver models)"
enum: ["TELNET", "HTTP"]
default: "TELNET"
port:
description: """
AVR control port (inly required for testing). Defaults to port 23
for TELNET protocol and port 80 for HTTP protocol
"""
type: "number"
required: false
}
11 changes: 9 additions & 2 deletions denon-avr.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ module.exports = (env) ->
init: (app, @framework, @config) =>
@debug = @config.debug || false
@base = commons.base @, 'Plugin'
###
if @config.protocol is 'HTTP'
@protocolHandler = new HttpAppProtocol @config
else
@protocolHandler = new TelnetAppProtocol @config

###
# register devices
deviceConfigDef = require("./device-config-schema")
for device in deviceConfigTemplates
Expand Down Expand Up @@ -84,7 +85,13 @@ module.exports = (env) ->
if not matched
process.nextTick @_discoveryCallbackHandler('pimatic-denon-avr', device.name, device)
)


getProtocolHandler: (config) ->
if config.protocol is 'HTTP'
return new HttpAppProtocol(config)
else
return new TelnetAppProtocol(config)

_discoveryCallbackHandler: (pluginName, deviceName, deviceConfig) ->
return () =>
@framework.deviceManager.discoveredDevice pluginName, deviceName, deviceConfig
Expand Down
133 changes: 133 additions & 0 deletions device-config-schema.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ module.exports = {
type: "object"
extensions: ["xLink", "xPresentLabel", "xAbsentLabel", "xAttributeOptions"]
properties:
debug:
type: "boolean"
description: "Debug mode. Writes debug messages to the pimatic log, if set to true."
default: false
protocol:
description: "The control protocol to be used (HTTP may not work with older receiver models)"
enum: ["TELNET", "HTTP"]
default: "TELNET"
host:
description: "Hostname or IP address of the AVR"
type: "string"
required: true
port:
description: """
AVR control port (inly required for testing). Defaults to port 23
for TELNET protocol and port 80 for HTTP protocol
"""
type: "number"
required: false
interval:
description: """
The time interval in seconds (minimum 2) at which the presence state of the
Expand All @@ -28,6 +47,25 @@ module.exports = {
type: "object"
extensions: ["xLink", "xPresentLabel", "xAbsentLabel", "xAttributeOptions"]
properties:
debug:
type: "boolean"
description: "Debug mode. Writes debug messages to the pimatic log, if set to true."
default: false
protocol:
description: "The control protocol to be used (HTTP may not work with older receiver models)"
enum: ["TELNET", "HTTP"]
default: "TELNET"
host:
description: "Hostname or IP address of the AVR"
type: "string"
required: true
port:
description: """
AVR control port (inly required for testing). Defaults to port 23
for TELNET protocol and port 80 for HTTP protocol
"""
type: "number"
required: false
interval:
description: """
The time interval in seconds (minimum 2) at which the volume state of the
Expand Down Expand Up @@ -63,6 +101,25 @@ module.exports = {
type: "object"
extensions: ["xLink", "xPresentLabel", "xAbsentLabel", "xAttributeOptions"]
properties:
debug:
type: "boolean"
description: "Debug mode. Writes debug messages to the pimatic log, if set to true."
default: false
protocol:
description: "The control protocol to be used (HTTP may not work with older receiver models)"
enum: ["TELNET", "HTTP"]
default: "TELNET"
host:
description: "Hostname or IP address of the AVR"
type: "string"
required: true
port:
description: """
AVR control port (inly required for testing). Defaults to port 23
for TELNET protocol and port 80 for HTTP protocol
"""
type: "number"
required: false
zone:
description: """
The zone for which volume shall be controlled. If set to MAIN it is
Expand Down Expand Up @@ -105,6 +162,25 @@ module.exports = {
type: "object"
extensions: ["xLink", "xOnLabel", "xOffLabel"]
properties:
debug:
type: "boolean"
description: "Debug mode. Writes debug messages to the pimatic log, if set to true."
default: false
protocol:
description: "The control protocol to be used (HTTP may not work with older receiver models)"
enum: ["TELNET", "HTTP"]
default: "TELNET"
host:
description: "Hostname or IP address of the AVR"
type: "string"
required: true
port:
description: """
AVR control port (inly required for testing). Defaults to port 23
for TELNET protocol and port 80 for HTTP protocol
"""
type: "number"
required: false
interval:
description: """
The time interval in seconds (minimum 2) at which the power state
Expand All @@ -120,6 +196,25 @@ module.exports = {
type: "object"
extensions: ["xLink", "xOnLabel", "xOffLabel"]
properties:
debug:
type: "boolean"
description: "Debug mode. Writes debug messages to the pimatic log, if set to true."
default: false
protocol:
description: "The control protocol to be used (HTTP may not work with older receiver models)"
enum: ["TELNET", "HTTP"]
default: "TELNET"
host:
description: "Hostname or IP address of the AVR"
type: "string"
required: true
port:
description: """
AVR control port (inly required for testing). Defaults to port 23
for TELNET protocol and port 80 for HTTP protocol
"""
type: "number"
required: false
zone:
description: "The zone to be controlled"
enum: ["MAIN", "ZONE2", "ZONE3"]
Expand All @@ -139,6 +234,25 @@ module.exports = {
type: "object"
extensions: ["xLink", "xOnLabel", "xOffLabel"]
properties:
debug:
type: "boolean"
description: "Debug mode. Writes debug messages to the pimatic log, if set to true."
default: false
protocol:
description: "The control protocol to be used (HTTP may not work with older receiver models)"
enum: ["TELNET", "HTTP"]
default: "TELNET"
host:
description: "Hostname or IP address of the AVR"
type: "string"
required: true
port:
description: """
AVR control port (inly required for testing). Defaults to port 23
for TELNET protocol and port 80 for HTTP protocol
"""
type: "number"
required: false
zone:
description: "The zone to be controlled"
enum: ["MAIN", "ZONE2", "ZONE3"]
Expand All @@ -158,6 +272,25 @@ module.exports = {
type: "object"
extensions: ["xLink", "xOnLabel", "xOffLabel"]
properties:
debug:
type: "boolean"
description: "Debug mode. Writes debug messages to the pimatic log, if set to true."
default: false
protocol:
description: "The control protocol to be used (HTTP may not work with older receiver models)"
enum: ["TELNET", "HTTP"]
default: "TELNET"
host:
description: "Hostname or IP address of the AVR"
type: "string"
required: true
port:
description: """
AVR control port (inly required for testing). Defaults to port 23
for TELNET protocol and port 80 for HTTP protocol
"""
type: "number"
required: false
zone:
description: "The zone to be controlled"
enum: ["MAIN", "ZONE2", "ZONE3"]
Expand Down
11 changes: 7 additions & 4 deletions devices/denon-avr-input-selector.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@ module.exports = (env) ->
@debug = @plugin.debug || false
for b in @config.buttons
b.text = b.id unless b.text?

@protocolHandler = @plugin.getProtocolHandler(@config)

@responseHandler = @_createResponseHandler()
@plugin.protocolHandler.on 'response', @responseHandler
@protocolHandler.on 'response', @responseHandler
super(@config)
process.nextTick () =>
@_requestUpdate true

destroy: () ->
@_base.cancelUpdate()
@plugin.protocolHandler.removeListener 'response', @responseHandler
@protocolHandler.removeListener 'response', @responseHandler
super()

_requestUpdate: (immediate=false) ->
@_base.cancelUpdate()
@_base.debug "Requesting update"
@plugin.protocolHandler.sendRequest @zoneCmd, '?', immediate
@protocolHandler.sendRequest @zoneCmd, '?', immediate
.catch (error) =>
@_base.error "Error:", error
.finally () =>
Expand All @@ -60,7 +63,7 @@ module.exports = (env) ->
if b.id is buttonId
@_lastPressedButton = b.id
@emit 'button', b.id
return @plugin.protocolHandler.sendRequest(@zoneCmd, b.id).then =>
return @protocolHandler.sendRequest(@zoneCmd, b.id).then =>
@_requestUpdate()
.catch (err) =>
@_base.rejectWithErrorString Promise.reject, err
Expand Down
11 changes: 7 additions & 4 deletions devices/denon-avr-master-volume.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ module.exports = (env) ->
@volumeLimit = @_base.normalize @config.volumeLimit, 0, 99
@maxAbsoluteVolume = @_base.normalize @config.maxAbsoluteVolume, 0, 99
@debug = @plugin.debug || false

@protocolHandler = @plugin.getProtocolHandler(@config)

@responseHandler = @_createResponseHandler()
@plugin.protocolHandler.on 'response', @responseHandler
@protocolHandler.on 'response', @responseHandler
@attributes = _.cloneDeep(@attributes)
@attributes.volume = {
description: "Volume"
Expand All @@ -38,13 +41,13 @@ module.exports = (env) ->

destroy: () ->
@_base.cancelUpdate()
@plugin.protocolHandler.removeListener 'response', @responseHandler
@protocolHandler.removeListener 'response', @responseHandler
super()

_requestUpdate: (immediate=false) ->
@_base.cancelUpdate()
@_base.debug "Requesting update"
@plugin.protocolHandler.sendRequest 'MV', '?', immediate
@protocolHandler.sendRequest 'MV', '?', immediate
.catch (error) =>
@_base.error "Error:", error
.finally () =>
Expand Down Expand Up @@ -88,7 +91,7 @@ module.exports = (env) ->
if @volumeLimit > 0 and newLevel > @volumeLimit
newLevel = @volumeLimit

@plugin.protocolHandler.sendRequest('MV', @_levelToVolumeParam(newLevel)).then =>
@protocolHandler.sendRequest('MV', @_levelToVolumeParam(newLevel)).then =>
@_setDimlevel newLevel
@_requestUpdate()
resolve()
Expand Down
11 changes: 7 additions & 4 deletions devices/denon-avr-mute-switch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,25 @@ module.exports = (env) ->
@lastPowerState=null
@interval = @_base.normalize @config.interval, 2
@debug = @plugin.debug || false

@protocolHandler = @plugin.getProtocolHandler(@config)

@responseHandler = @_createResponseHandler()
@plugin.protocolHandler.on 'response', @responseHandler
@protocolHandler.on 'response', @responseHandler
super()
@_state = false
process.nextTick () =>
@_requestUpdate true

destroy: () ->
@_base.cancelUpdate()
@plugin.protocolHandler.removeListener 'response', @responseHandler
@protocolHandler.removeListener 'response', @responseHandler
super()

_requestUpdate: (immediate=false) ->
@_base.cancelUpdate()
@_base.debug "Requesting update"
@plugin.protocolHandler.sendRequest @zoneCmd, '?', immediate
@protocolHandler.sendRequest @zoneCmd, '?', immediate
.catch (error) =>
@_base.error "Error:", error
.finally () =>
Expand All @@ -63,7 +66,7 @@ module.exports = (env) ->

changeStateTo: (newState) ->
return new Promise (resolve, reject) =>
@plugin.protocolHandler.sendRequest(@zoneCmd, if newState then 'ON' else 'OFF').then =>
@protocolHandler.sendRequest(@zoneCmd, if newState then 'ON' else 'OFF').then =>
@_setState newState
@_requestUpdate()
resolve()
Expand Down
11 changes: 7 additions & 4 deletions devices/denon-avr-power-switch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ module.exports = (env) ->
@name = @config.name
@interval = @_base.normalize @config.interval, 2
@debug = @plugin.debug || false

@protocolHandler = @plugin.getProtocolHandler(@config)

@responseHandler = @_createResponseHandler()
@plugin.protocolHandler.on 'response', @responseHandler
@protocolHandler.on 'response', @responseHandler
@_state = false
super()
process.nextTick () =>
@_requestUpdate true

destroy: () ->
@_base.cancelUpdate()
@plugin.protocolHandler.removeListener 'response', @responseHandler
@protocolHandler.removeListener 'response', @responseHandler
super()

_requestUpdate: (immediate=false) ->
@_base.cancelUpdate()
@_base.debug "Requesting update"
@plugin.protocolHandler.sendRequest 'PW', '?', immediate
@protocolHandler.sendRequest 'PW', '?', immediate
.catch (error) =>
@_base.error "Error:", error
.finally () =>
Expand All @@ -46,7 +49,7 @@ module.exports = (env) ->

changeStateTo: (newState) ->
return new Promise (resolve, reject) =>
@plugin.protocolHandler.sendRequest('PW', if newState then 'ON' else 'STANDBY').then =>
@protocolHandler.sendRequest('PW', if newState then 'ON' else 'STANDBY').then =>
@_setState newState
@_requestUpdate()
resolve()
Expand Down
Loading