Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = (env) ->
- Promise = env.require 'bluebird'
- assert = env.require 'cassert'
- _ = env.require 'lodash'
- OTGWConnection = require 'OTGW-Control'
- Promise.promisifyAll(OTGWConnection.prototype)
- M = env.matcher
- settled = (promise) -> Promise.settle([promise])
- class OTGWThermostatPlugin extends env.plugins.Plugin
- init: (app, @framework, @config) =>
- # Promise that is resolved when the connection is established
- @_lastAction = new Promise( (resolve, reject) =>
- @otgw = new OTGWConnection(@config.host, @config.port)
- @otgw.once("connected", resolve)
- @otgw.once('error', reject)
- return
- ).timeout(60000).catch( (error) ->
- env.logger.error "Error on connecting to OTGW relay: #{error.message}"
- env.logger.debug error.stack
- return
- )
- @otgw.on('error', (error) =>
- env.logger.error "connection error: #{error}"
- env.logger.debug error.stack
- )
- @otgw.on("control_setpoint", (data) =>
- env.logger.debug "got control_setpoint: ", data
- )
- @otgw.on("max_relative_modulation_level", (data) =>
- env.logger.debug "got max_relative_modulation_level: ", data
- )
- @otgw.on("room_setpoint", (data) =>
- env.logger.debug "got room_setpoint: ", data
- )
- @otgw.on("relative_modulation_level", (data) =>
- env.logger.debug "got relative_modulation_level: ", data
- )
- @otgw.on("ch_water_pressure", (data) =>
- env.logger.debug "got ch_water_pressure: ", data
- )
- @otgw.on("room_temperature", (data) =>
- env.logger.debug "got room_temperature: ", data
- )
- @otgw.on("boiler_water_temperature", (data) =>
- env.logger.debug "got boiler_water_temperature: ", data
- )
- @otgw.on("dhw_temperature", (data) =>
- env.logger.debug "got dhw_temperature: ", data
- )
- @otgw.on("outside_temperature", (data) =>
- env.logger.debug "got outside_temperature: ", data
- )
- @otgw.on("return_water_temperature", (data) =>
- env.logger.debug "got return_water_temperature: ", data
- )
- @otgw.on("dhw_setpoint", (data) =>
- env.logger.debug "got dhw_setpoint: ", data
- )
- @otgw.on("max_ch_water_setpoint", (data) =>
- env.logger.debug "got max_ch_water_setpoint: ", data
- )
- @otgw.on("remote_override_setpoint", (data) =>
- env.logger.debug "got remote_override_setpoint: ", data
- )
- @otgw.on("flame_status" , (data) =>
- env.logger.debug "Flame status: ", data
- )
- @otgw.on("burner_starts" , (data) =>
- env.logger.debug "burner_starts: ", data
- )
- @otgw.on("ch_pump_starts" , (data) =>
- env.logger.debug "ch_pump_starts: ", data
- )
- @otgw.on("dhw_pump_starts" , (data) =>
- env.logger.debug "dhw_pump_starts: ", data
- )
- @otgw.on("dhw_burner_starts" , (data) =>
- env.logger.debug "dhw_burner_starts: ", data
- )
- @otgw.on("burner_operation_hours" , (data) =>
- env.logger.debug "burner_operation_hours: ", data
- )
- @otgw.on("ch_pump_operation_hours" , (data) =>
- env.logger.debug "ch_pump_operation_hours: ", data
- )
- @otgw.on("dhw_pump_operation_hours" , (data) =>
- env.logger.debug "dhw_pump_operation_hours: ", data
- )
- @otgw.on("dhw_burner_operation_hours" , (data) =>
- env.logger.debug "dhw_burner_operation_hours: ", data
- )
- deviceConfigDef = require("./device-config-schema")
- @framework.deviceManager.registerDeviceClass("OTGWHeatingThermostat", {
- configDef: deviceConfigDef.OTGWHeatingThermostat,
- createCallback: (config, lastState) -> new OTGWHeatingThermostat(config, lastState)
- })
- @framework.deviceManager.registerDeviceClass("OTGWMainThermostat", {
- configDef: deviceConfigDef.OTGWMainThermostat,
- createCallback: (config, lastState) -> new OTGWMainThermostat(config, lastState)
- })
- @framework.deviceManager.registerDeviceClass("OTGWMainThermostat1", {
- configDef: deviceConfigDef.OTGWMainThermostat1,
- createCallback: (config, lastState) -> new OTGWMainThermostat1(config, lastState)
- })
- @framework.deviceManager.registerDeviceClass("OTGWMainThermostat2", {
- configDef: deviceConfigDef.OTGWMainThermostat2,
- createCallback: (config, lastState) -> new OTGWMainThermostat2(config, lastState)
- })
- @framework.deviceManager.registerDeviceClass("OTGWFlamePresenceSensor", {
- configDef: deviceConfigDef.OTGWFlamePresenceSensor,
- createCallback: (config) -> new OTGWFlamePresenceSensor(config)
- })
- @framework.deviceManager.registerDeviceClass("OTGWDomesticHotWater", {
- configDef: deviceConfigDef.OTGWDomesticHotWater,
- createCallback: (config) -> new OTGWDomesticHotWater(config)
- })
- @framework.deviceManager.registerDeviceClass("OTGWCentralHeating", {
- configDef: deviceConfigDef.OTGWCentralHeating,
- createCallback: (config) -> new OTGWCentralHeating(config)
- })
- @framework.deviceManager.registerDeviceClass("OTGWThermostat", {
- configDef: deviceConfigDef.OTGWThermostat,
- createCallback: (config) -> new OTGWThermostat(config)
- })
- # @framework.deviceManager.registerDeviceClass("MaxContactSensor", {
- # configDef: deviceConfigDef.MaxContactSensor,
- # createCallback: (config, lastState) -> new MaxContactSensor(config, lastState)
- # })
- # @framework.deviceManager.registerDeviceClass("MaxCube", {
- # configDef: deviceConfigDef.MaxCube,
- # createCallback: (config, lastState) -> new MaxCube(config, lastState)
- # })
- #setTemperatureSetpoint: (rfAddress, mode, value) ->
- # setTemperatureSetpoint(mode,value)
- setTemperatureSetpoint: (mode, value) ->
- @_lastAction = settled(@_lastAction).then( =>
- @otgw.setTemperatureAsync(mode, value)
- )
- return @_lastAction
- plugin = new OTGWThermostatPlugin
- class OTGWThermostat extends env.devices.Device
- _fault = false
- _chmode = false
- _dhwmode = false
- _flame = false
- _coolingstatus = false
- _ch2mode = false
- _diag = false
- _chenable = false
- _dhwenable = false
- _coolingenable = false
- _otcstate = false
- _ch2enable = false;
- attributes:
- Flame:
- description: "Flame status"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'Vlam status'
- CentralHeatingMode:
- description: "Central Heating Mode"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'Centrale Verwarming Modus'
- Fault:
- description: "Fault indication"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'Fout indicatie'
- DomesticHotWaterMode:
- description: "Domestic Hot Water Mode"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'Warm water'
- CoolingStatus:
- description: "Cooling Status"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'Afkoeling status'
- CentralHeating2Mode:
- description: "Central Heating 2 Mode"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'Centrale verwarming II'
- Diagnostics:
- description: "Diagnostics"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'Diagnose'
- CentralHeatingEnable:
- description: "Central Heating Enable"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'Centrale verwarming aan'
- DomesticHotWaterEnable:
- description: "Domestic Hot Water Enable"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'Warm water aan'
- CoolingEnable:
- description: "Cooling Enable"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'Afkoeling aan'
- OTCState:
- description: "OTC State"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'OTC status'
- CentralHeating2Enable:
- description: "Central Heating 2 Enable"
- type: "boolean"
- labels: ["aan", "uit"]
- acronym: 'Centrale verwarming II aan'
- constructor: (@config) ->
- @id = @config.id
- @name = @config.name
- plugin.otgw.on("flame_status" , (data) =>
- if data.length = 16
- @_setFault(@_bitToBool(data.slice(15,16)))
- @_setCHMode(@_bitToBool(data.slice(14,15)))
- @_setDHWMode(@_bitToBool(data.slice(13,14)))
- @_setFlame(@_bitToBool(data.slice(12,13)))
- @_setCoolingStatus(@_bitToBool(data.slice(11,12)))
- @_setCH2Mode(@_bitToBool(data.slice(10,11)))
- @_setDiagnostics(@_bitToBool(data.slice(9,10)))
- @_setCHEnable(@_bitToBool(data.slice(8,9)))
- @_setDHWEnable(@_bitToBool(data.slice(7,8)))
- @_setCoolingEnable(@_bitToBool(data.slice(6,7)))
- @_setOTCState(@_bitToBool(data.slice(5,6)))
- @_setCH2Enable(@_bitToBool(data.slice(4,5)))
- )
- super()
- #Getters
- getFlame: () -> return Promise.resolve @_flame
- getCentralHeatingMode: () -> return Promise.resolve @_chmode
- getFault: () -> return Promise.resolve @_fault
- getDomesticHotWaterMode: () -> return Promise.resolve @_dhwmode
- getCoolingStatus: () -> return Promise.resolve @_coolingstatus
- getCentralHeating2Mode: () -> return Promise.resolve @_ch2mode
- getDiagnostics: () -> return Promise.resolve @_diag
- getCentralHeatingEnable: () -> return Promise.resolve @_chenable
- getDomesticHotWaterEnable: () -> return Promise.resolve @_dhwenable
- getCoolingEnable: () -> return Promise.resolve @_coolingenable
- getOTCState: () -> return Promise.resolve @_otcstate
- getCentralHeating2Enable: () -> return Promise.resolve @_ch2enable
- #Setters
- _setFlame: (state) ->
- if @_flame isnt state
- @_flame = state
- @emit 'Flame', state
- _setCHMode: (state) ->
- if @_chmode isnt state
- @_chmode = state
- @emit 'CentralHeatingMode', state
- _setFault: (state) ->
- if @_fault isnt state
- @_fault = state
- @emit 'Fault', state
- _setDHWMode: (state) ->
- if @_dhwmode isnt state
- @_dhwmode = state
- @emit 'DomesticHotWaterMode', state
- _setCoolingStatus: (state) ->
- if @_coolingstatus isnt state
- @_coolingstatus = state
- @emit 'CoolingStatus', state
- _setCH2Mode: (state) ->
- if @_ch2mode isnt state
- @_ch2mode = state
- @emit 'CentralHeating2Mode', state
- _setDiagnostics: (state) ->
- if @_diag isnt state
- @_diag = state
- @emit 'Diagnostics', state
- _setCHEnable: (state) ->
- if @_chenable isnt state
- @_chenable = state
- @emit 'CentralHeatingEnable', state
- _setDHWEnable: (state) ->
- if @_dhwenable isnt state
- @_dhwenable = state
- @emit 'DomesticHotWaterEnable', state
- _setCoolingEnable: (state) ->
- if @_coolingenable isnt state
- @_coolingenable = state
- @emit 'CoolingEnable', state
- _setOTCState: (state) ->
- if @_otcstate isnt state
- @_otcstate = state
- @emit 'OTCState', state
- _setCH2Enable: (state) ->
- if @_ch2enable isnt state
- @_ch2enable = state
- @emit 'CentralHeating2Enable', state
- #Functions
- _bitToBool: (value) ->
- return (value is "1")
- class OTGWHeatingThermostat extends env.devices.HeatingThermostat
- constructor: (@config, lastState) ->
- @id = @config.id
- @name = @config.name
- @_temperatureSetpoint = lastState?.temperatureSetpoint?.value
- @_mode = lastState?.mode?.value or "auto"
- @_battery = lastState?.battery?.value or "ok"
- @_lastSendTime = 0
- plugin.otgw.on("room_setpoint", (data) =>
- if data?
- data = Number(data)
- now = new Date().getTime()
- ###
- Give the gateway some time to handle the changes. If we send new values to the cube
- we set _lastSendTime to the current time. We consider the values as succesfull set, when
- the command was not rejected.
- In the case that the gateway did not react to our the send commands, the values will be
- overwritten with the internal state (old ones) of the gateway after 30 seconds.
- ###
- if @_mode is "auto"
- @_setSetpoint(data) #override from gateway
- @_setSynced(true)
- ###
- if now - @_lastSendTime < 30*1000
- # only if values match, we are synced
- if data is @_temperatureSetpoint
- @_setSynced(true)
- else
- # more then 30 seconds passed, set the values anyway
- @_setSetpoint(data) #override from gateway
- @_setSynced(true)
- ###
- return
- )
- plugin.otgw.on("remote_override_setpoint", (data) =>
- if data?
- data = Number(data)
- now = new Date().getTime()
- ###
- Give the gateway some time to handle the changes. If we send new values to the cube
- we set _lastSendTime to the current time. We consider the values as succesfull set, when
- the command was not rejected.
- In the case that the gateway did not react to our the send commands, the values will be
- overwritten with the internal state (old ones) of the gateway after 30 seconds.
- ###
- if @_mode is "manu"
- if data < 1
- env.logger.debug "setting to auto"
- @_setMode("auto")
- else
- if now - @_lastSendTime < 30*1000
- # only if values match, we are synced
- if data is @_temperatureSetpoint
- @_setSynced(true)
- else
- # more then 30 seconds passed, set the values anyway
- @_setSetpoint(data)
- @_setSynced(true)
- if @_mode is "auto" and data > 0.00
- @_setMode("manu")
- return
- )
- super()
- changeModeTo: (mode) ->
- temp = @_temperatureSetpoint
- if mode is "auto"
- temp = null
- return plugin.setTemperatureSetpoint(mode, temp).then( =>
- @_lastSendTime = new Date().getTime()
- @_setSynced(false)
- @_setMode(mode)
- )
- changeTemperatureTo: (temperatureSetpoint) ->
- if @temperatureSetpoint is temperatureSetpoint then return
- return plugin.setTemperatureSetpoint(@_mode, temperatureSetpoint).then( =>
- @_lastSendTime = new Date().getTime()
- @_setSynced(false)
- @_setSetpoint(temperatureSetpoint)
- )
- class OTGWMainThermostat extends env.devices.TemperatureSensor
- _temperature: null
- constructor: (@config, lastState) ->
- @id = @config.id
- @name = @config.name
- @_temperature = lastState?.temperature?.value
- super()
- plugin.otgw.on("room_temperature", (data) =>
- if data?
- @_temperature = Number(data)
- @emit 'temperature', @_temperature
- )
- getTemperature: -> Promise.resolve(@_temperature)
- class OTGWMainThermostat1 extends env.devices.Device
- temperature: null
- temperature1: null
- temperature2: null
- temperature3: null
- temperature4: null
- temperature5: null
- temperature6: null
- temperature7: null
- temperature8: null
- temperature9: null
- temperature10: null
- temperature11: null
- temperature12: null
- attributes:
- temperature:
- description: "Temperature"
- type: "number"
- unit: '°C'
- acronym: 'Control Setpoint'
- temperature1:
- description: "Temperature1"
- type: "number"
- unit: '°C'
- acronym: 'Remote Override Setpoint'
- temperature2:
- description: "Temperature2"
- type: "number"
- unit: '%'
- acronym: 'Max Relative Modulation Level'
- temperature3:
- description: "Temperature3"
- type: "number"
- unit: '°C'
- acronym: 'Room Setpoint'
- temperature4:
- description: "Temperature4"
- type: "number"
- unit: '%'
- acronym: 'Relative Modulation Level'
- temperature5:
- description: "Temperature5"
- type: "number"
- unit: 'Bar'
- acronym: 'Water Pressure'
- temperature6:
- description: "Temperature6"
- type: "number"
- unit: '°C'
- acronym: 'Room Temperature'
- temperature7:
- description: "Temperature7"
- type: "number"
- unit: '°C'
- acronym: 'Boiler Water Temperature'
- temperature8:
- description: "Temperature8"
- type: "number"
- unit: '°C'
- acronym: 'DWH Temperature'
- temperature9:
- description: "Temperature9"
- type: "number"
- unit: '°C'
- acronym: 'Outside Temperature'
- temperature10:
- description: "Temperature10"
- type: "number"
- unit: '°C'
- acronym: 'Return Water Temperature'
- temperature11:
- description: "Temperature11"
- type: "number"
- unit: '°C'
- acronym: 'DWH Setpoint'
- temperature12:
- description: "Temperature12"
- type: "number"
- unit: '°C'
- acronym: 'Max CH Water Setpoint'
- constructor: (@config, lastState) ->
- @id = @config.id
- @name = @config.name
- @temperature = lastState?.temperature?.value
- @temperature1 = lastState?.temperature1?.value
- @temperature2 = lastState?.temperature2?.value
- @temperature3 = lastState?.temperature3?.value
- @temperature4 = lastState?.temperature4?.value
- @temperature5 = lastState?.temperature5?.value
- @temperature6 = lastState?.temperature6?.value
- @temperature7 = lastState?.temperature7?.value
- @temperature8 = lastState?.temperature8?.value
- @temperature9 = lastState?.temperature9?.value
- @temperature10 = lastState?.temperature10?.value
- @temperature11 = lastState?.temperature11?.value
- @temperature12 = lastState?.temperature12?.value
- super()
- plugin.otgw.on("control_setpoint", (data) =>
- if data?
- @temperature = Number(data)
- @emit 'temperature', @temperature
- )
- plugin.otgw.on("remote_override_setpoint", (data) =>
- if data?
- @temperature1 = Number(data)
- @emit 'temperature1', @temperature1
- )
- plugin.otgw.on("max_relative_modulation_level", (data) =>
- if data?
- @temperature2 = Number(data)
- @emit 'temperature2', @temperature2
- )
- plugin.otgw.on("room_setpoint", (data) =>
- if data?
- @temperature3 = Number(data)
- @emit 'temperature3', @temperature3
- )
- plugin.otgw.on("relative_modulation_level", (data) =>
- if data?
- @temperature4 = Number(data)
- @emit 'temperature4', @temperature4
- )
- plugin.otgw.on("ch_water_pressure", (data) =>
- if data?
- @temperature5 = Number(data)
- @emit 'temperature5', @temperature5
- )
- plugin.otgw.on("room_temperature", (data) =>
- if data?
- @temperature6 = Number(data)
- @emit 'temperature6', @temperature6
- )
- plugin.otgw.on("boiler_water_temperature", (data) =>
- if data?
- @temperature7 = Number(data)
- @emit 'temperature7', @temperature7
- )
- plugin.otgw.on("dhw_temperature", (data) =>
- if data?
- @temperature8 = Number(data)
- @emit 'temperature8', @temperature8
- )
- plugin.otgw.on("outside_temperature", (data) =>
- if data?
- @temperature9 = Number(data)
- @emit 'temperature9', @temperature9
- )
- plugin.otgw.on("return_water_temperature", (data) =>
- if data?
- @temperature10 = Number(data)
- @emit 'temperature10', @temperature10
- )
- plugin.otgw.on("dhw_setpoint", (data) =>
- if data?
- @temperature11 = Number(data)
- @emit 'temperature11', @temperature11
- )
- plugin.otgw.on("max_ch_water_setpoint", (data) =>
- if data?
- @temperature12 = Number(data)
- @emit 'temperature12', @temperature12
- )
- getTemperature: -> Promise.resolve(@temperature)
- getTemperature1: -> Promise.resolve(@temperature1)
- getTemperature2: -> Promise.resolve(@temperature2)
- getTemperature3: -> Promise.resolve(@temperature3)
- getTemperature4: -> Promise.resolve(@temperature4)
- getTemperature5: -> Promise.resolve(@temperature5)
- getTemperature6: -> Promise.resolve(@temperature6)
- getTemperature7: -> Promise.resolve(@temperature7)
- getTemperature8: -> Promise.resolve(@temperature8)
- getTemperature9: -> Promise.resolve(@temperature9)
- getTemperature10: -> Promise.resolve(@temperature10)
- getTemperature11: -> Promise.resolve(@temperature11)
- getTemperature12: -> Promise.resolve(@temperature12)
- class OTGWDomesticHotWater extends env.devices.Device
- temperature: null
- temperature1: null
- temperature2: null
- temperature3: null
- attributes:
- temperature:
- description: "Temperature"
- type: "number"
- acronym: 'Pump Starts'
- temperature1:
- description: "Temperature1"
- type: "number"
- unit: 'H'
- acronym: 'Pump Hours'
- temperature2:
- description: "Temperature2"
- type: "number"
- acronym: 'Burner Starts'
- temperature3:
- description: "Temperature3"
- type: "number"
- unit: 'H'
- acronym: 'Burner Hours'
- constructor: (@config, lastState) ->
- @id = @config.id
- @name = @config.name
- @temperature = lastState?.temperature?.value
- @temperature1 = lastState?.temperature1?.value
- @temperature2 = lastState?.temperature2?.value
- @temperature3 = lastState?.temperature3?.value
- super()
- plugin.otgw.on("dhw_pump_starts", (data) =>
- if data?
- @temperature = Number(data)
- @emit 'temperature', @temperature
- )
- plugin.otgw.on("dhw_pump_operation_hours", (data) =>
- if data?
- @temperature1 = Number(data)
- @emit 'temperature1', @temperature1
- )
- plugin.otgw.on("dhw_burner_starts", (data) =>
- if data?
- @temperature2 = Number(data)
- @emit 'temperature2', @temperature2
- )
- plugin.otgw.on("dhw_burner_operation_hours", (data) =>
- if data?
- @temperature3 = Number(data)
- @emit 'temperature3', @temperature3
- )
- getTemperature: -> Promise.resolve(@temperature)
- getTemperature1: -> Promise.resolve(@temperature1)
- getTemperature2: -> Promise.resolve(@temperature2)
- getTemperature3: -> Promise.resolve(@temperature3)
- class OTGWCentralHeating extends env.devices.Device
- temperature: null
- temperature1: null
- temperature2: null
- temperature3: null
- attributes:
- temperature:
- description: "Temperature"
- type: "number"
- acronym: 'Pump Starts'
- temperature1:
- description: "Temperature1"
- type: "number"
- unit: 'H'
- acronym: 'Pump Hours'
- temperature2:
- description: "Temperature2"
- type: "number"
- acronym: 'Burner Starts'
- temperature3:
- description: "Temperature3"
- type: "number"
- unit: 'H'
- acronym: 'Burner Hours'
- constructor: (@config, lastState) ->
- @id = @config.id
- @name = @config.name
- @temperature = lastState?.temperature?.value
- @temperature1 = lastState?.temperature1?.value
- @temperature2 = lastState?.temperature2?.value
- @temperature3 = lastState?.temperature3?.value
- super()
- plugin.otgw.on("ch_pump_starts", (data) =>
- if data?
- @temperature = Number(data)
- @emit 'temperature', @temperature
- )
- plugin.otgw.on("ch_pump_operation_hours", (data) =>
- if data?
- @temperature1 = Number(data)
- @emit 'temperature1', @temperature1
- )
- plugin.otgw.on("burner_starts", (data) =>
- if data?
- @temperature2 = Number(data)
- @emit 'temperature2', @temperature2
- )
- plugin.otgw.on("burner_operation_hours", (data) =>
- if data?
- @temperature3 = Number(data)
- @emit 'temperature3', @temperature3
- )
- getTemperature: -> Promise.resolve(@temperature)
- getTemperature1: -> Promise.resolve(@temperature1)
- getTemperature2: -> Promise.resolve(@temperature2)
- getTemperature3: -> Promise.resolve(@temperature3)
- class OTGWFlamePresenceSensor extends env.devices.PresenceSensor
- @_presence = false
- constructor: (@config) ->
- @id = @config.id
- @name = @config.name
- plugin.otgw.on("flame_status" , (data) =>
- if data.length = 16
- @_setPresence(@_bitToBool(data.slice(12,13)))
- )
- super()
- #Getters
- getPresence: () -> return Promise.resolve @_flame
- #No need for setter, _setPresence() is implemented by super class
- #Functions
- _bitToBool: (value) ->
- return (value is "1")
- class OTGWMainThermostat2 extends env.devices.Device
- attributeTemplates =
- ch_pump_starts:
- description: "Temperature"
- type: "number"
- acronym: 'Pump Starts'
- ch_pump_operation_hours:
- description: "Temperature1"
- type: "number"
- unit: 'H'
- acronym: 'Pump Hours'
- dhw_burner_starts:
- description: "Temperature2"
- type: "number"
- acronym: 'Burner Starts'
- dhw_burner_operation_hours:
- description: "Temperature3"
- type: "number"
- unit: 'H'
- acronym: 'Burner Hours'
- constructor: (@config, @plugin, lastState) ->
- @debug = @plugin.config.debug ? false
- @base = commons.base @, @config.class unless @base?
- @attributeValues = new AttributeContainer()
- @attributes = _.cloneDeep(@attributes)
- for attributeName in @config.attributes
- do (attributeName) =>
- if attributeTemplates.hasOwnProperty attributeName
- properties = attributeTemplates[attributeName]
- @attributes[attributeName] =
- description: properties.description || attributeName.replace /(^[a-z])|([A-Z])/g, ((match, p1, p2, offset) =>
- (if offset>0 then " " else "") + match.toUpperCase())
- type: properties.type
- unit: properties.unit if properties.unit?
- acronym: properties.acronym if properties.acronym?
- @attributeValues.values[attributeName] = 0
- @attributeValues.on properties.key, ((value) =>
- @base.debug "Received update for", properties.key, value
- if value.value? and @attributeValues.values[attributeName] isnt value.value
- @attributeValues.values[attributeName] = value.value
- @emit attributeName, value.value
- )
- @_createGetter(attributeName, =>
- return Promise.resolve @attributeValues[attributeName]
- )
- else
- @base.error "Configuration Error. No such attribute: #{attributeName} - skipping."
- super(@config, @plugin, "GetComponentsData")
- @on 'data', ((error, values) =>
- if error or not values
- if error
- @base.error error
- else
- data = values.Body.Data
- for key,value of data
- @attributeValues.emit key, value if value?
- )
- destroy: () ->
- super()
- return plugin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement