Thickness1

otgw.coffee

Sep 30th, 2017
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module.exports = (env) ->
  2.  
  3. Promise = env.require 'bluebird'
  4. assert = env.require 'cassert'
  5. _ = env.require 'lodash'
  6. OTGWConnection = require 'OTGW-Control'
  7. Promise.promisifyAll(OTGWConnection.prototype)
  8. M = env.matcher
  9. settled = (promise) -> Promise.settle([promise])
  10.  
  11. class OTGWThermostatPlugin extends env.plugins.Plugin
  12.  
  13. init: (app, @framework, @config) =>
  14.  
  15. # Promise that is resolved when the connection is established
  16. @_lastAction = new Promise( (resolve, reject) =>
  17. @otgw = new OTGWConnection(@config.host, @config.port)
  18. @otgw.once("connected", resolve)
  19. @otgw.once('error', reject)
  20. return
  21. ).timeout(60000).catch( (error) ->
  22. env.logger.error "Error on connecting to OTGW relay: #{error.message}"
  23. env.logger.debug error.stack
  24. return
  25. )
  26.  
  27. @otgw.on('error', (error) =>
  28. env.logger.error "connection error: #{error}"
  29. env.logger.debug error.stack
  30. )
  31. #ID=0
  32. @otgw.on("A_flame_status" , (data) =>
  33. env.logger.debug "A_flame status: ", data
  34. )
  35. @otgw.on("B_flame_status" , (data) =>
  36. env.logger.debug "B_flame status: ", data
  37. )
  38. #ID=1
  39. @otgw.on("T_control_setpoint", (data) =>
  40. env.logger.debug "got T_control_setpoint: ", data
  41. )
  42. @otgw.on("R_control_setpoint", (data) =>
  43. env.logger.debug "got R_control_setpoint: ", data
  44. )
  45. #ID=2
  46. @otgw.on("master_config_flags/master_member_id", (data) =>
  47. env.logger.debug "got master_config_flags/master_member_id: ", data
  48. )
  49. #ID=3
  50. @otgw.on("slave_config_flags/slave_member_id", (data) =>
  51. env.logger.debug "got slave_config_flags/slave_member_id: ", data
  52. )
  53. #ID=4
  54. @otgw.on("remote_command", (data) =>
  55. env.logger.debug "got remote_command: ", data
  56. )
  57. #ID=5
  58. @otgw.on("B_application-specific_fault_flag/OEM_fault_code", (data) =>
  59. env.logger.debug "got B_application-specific_fault_flag/OEM_fault_code: ", data
  60. )
  61. #ID=6
  62. @otgw.on("remote_boiler_parameter_transfer-enable/read_write_flags", (data) =>
  63. env.logger.debug "got remote_boiler_parameter_transfer-enable/read_write_flags: ", data
  64. )
  65. #ID=7
  66. @otgw.on("cooling_control_signal", (data) =>
  67. env.logger.debug "got cooling_control_signal: ", data
  68. )
  69. #ID=8
  70. @otgw.on("T_control_setpoint_2nd_circuit", (data) =>
  71. env.logger.debug "got T_control_setpoint_2nd_circuit: ", data
  72. )
  73. #ID=9
  74. @otgw.on("remote_override_setpoint", (data) =>
  75. env.logger.debug "got remote_override_setpoint: ", data
  76. )
  77. #ID=10
  78. @otgw.on("number_transparent_slave_parameters_supported_slave", (data) =>
  79. env.logger.debug "got number_transparent_slave_parameters_supported_slave: ", data
  80. )
  81. #ID=11
  82. @otgw.on("index_number/value_referred_to_transparent_slave_parameter", (data) =>
  83. env.logger.debug "got index_number/value_referred_to_transparent_slave_parameter: ", data
  84. )
  85. #ID=12
  86. @otgw.on("size_of_fault_history_buffer_slave", (data) =>
  87. env.logger.debug "got size_of_fault_history_buffer_slave: ", data
  88. )
  89. #ID=13
  90. @otgw.on("index_number/value_referred_to_fault_history_buffer", (data) =>
  91. env.logger.debug "got index_number/value_referred_to_fault_history_buffer: ", data
  92. )
  93. #ID=14
  94. @otgw.on("T_max_relative_modulation", (data) =>
  95. env.logger.debug "got T_max_relative_modulation_level: ", data
  96.  
  97. )
  98. #ID=15
  99. @otgw.on("max_boiler_capacity/minimum_boiler_modulation", (data) =>
  100. env.logger.debug "got max_boiler_capacity/minimum_boiler_modulation: ", data
  101.  
  102. )
  103. #ID=16
  104. @otgw.on("T_room_setpoint", (data) =>
  105. env.logger.debug "got T_room_setpoint: ", data
  106.  
  107. )
  108. #ID=17
  109. @otgw.on("relative_modulation", (data) =>
  110. env.logger.debug "got relative_modulation_level: ", data
  111.  
  112. )
  113. #ID=18
  114. @otgw.on("B_ch_water_pressure", (data) =>
  115. env.logger.debug "got B_ch_water_pressure: ", data
  116. )
  117. #ID=19
  118. @otgw.on("B_flow_dhw", (data) =>
  119. env.logger.debug "got B_flow_dhw: ", data
  120. )
  121. #ID=20
  122. @otgw.on("day_of_week/time_of_day", (data) =>
  123. env.logger.debug "got day_of_week/time_of_day: ", data
  124. )
  125. #ID=21
  126. @otgw.on("calender_date", (data) =>
  127. env.logger.debug "got calender_date: ", data
  128. )
  129. #ID=22
  130. @otgw.on("calender_year", (data) =>
  131. env.logger.debug "got calender_year: ", data
  132. )
  133. #ID=23
  134. @otgw.on("room_setpoint_2nd_circuit", (data) =>
  135. env.logger.debug "got room_setpoint_2nd_circuit: ", data
  136. )
  137. #ID=24
  138. @otgw.on("T_room_temperature", (data) =>
  139. env.logger.debug "got T_room_temperature: ", data
  140. )
  141. #ID=25
  142. @otgw.on("B_boiler_water_temperature", (data) =>
  143. env.logger.debug "got B_boiler_water_temperature: ", data
  144. )
  145. #ID=26
  146. @otgw.on("B_dhw_temperature", (data) =>
  147. env.logger.debug "got B_dhw_temperature: ", data
  148.  
  149. )
  150. #ID=27
  151. @otgw.on("B_outside_temperature", (data) =>
  152. env.logger.debug "got B_outside_temperature: ", data
  153.  
  154. )
  155. #ID=28
  156. @otgw.on("B_return_water_temperature", (data) =>
  157. env.logger.debug "got B_return_water_temperature: ", data
  158.  
  159. )
  160. #ID=29
  161. @otgw.on("solar_storage_temperature", (data) =>
  162. env.logger.debug "got solar_storage_temperature: ", data
  163.  
  164. )
  165. #ID=30
  166. @otgw.on("solar_collector_temperature", (data) =>
  167. env.logger.debug "got solar_collector_temperature: ", data
  168.  
  169. )
  170. #ID=31
  171. @otgw.on("flow_water_temperature_2nd_circuit", (data) =>
  172. env.logger.debug "got flow_water_temperature_2nd_circuit: ", data
  173.  
  174. )
  175. #ID=32
  176. @otgw.on("dhw_temperature_2", (data) =>
  177. env.logger.debug "got dhw_temperature_2: ", data
  178.  
  179. )
  180. #ID=33
  181. @otgw.on("boiler_exhaust_temperature", (data) =>
  182. env.logger.debug "got boiler_exhaust_temperature: ", data
  183.  
  184. )
  185. #ID=48
  186. @otgw.on("dhw_upper_bound/dhw_lower_bound", (data) =>
  187. env.logger.debug "got dhw_upper_bound/dhw_lower_bound: ", data
  188. )
  189. #ID=49
  190. @otgw.on("max_ch_setpoint_upper_bound/lower_bound", (data) =>
  191. env.logger.debug "got max_ch_setpoint_upper_bound/lower_bound: ", data
  192. )
  193. #ID=50
  194. @otgw.on("otc_curve_upper_bound/lower_bound", (data) =>
  195. env.logger.debug "got otc_curve_upper_bound/lower_bound: ", data
  196. )
  197. #ID=56
  198. @otgw.on("A_dhw_setpoint", (data) =>
  199. env.logger.debug "got A dhw_setpoint: ", data
  200.  
  201. )
  202. #ID=57
  203. @otgw.on("A_max_ch_setpoint", (data) =>
  204. env.logger.debug "got A max_ch_water_setpoint: ", data
  205.  
  206. )
  207. #ID=58
  208. @otgw.on("otc_curve_ratio", (data) =>
  209. env.logger.debug "got otc_curve_ratio: ", data
  210.  
  211. )
  212. #ID=100
  213. @otgw.on("A_remote_override_setpoint", (data) =>
  214. env.logger.debug "got A remote_override_setpoint: ", data
  215. )
  216.  
  217. #ID=115
  218. @otgw.on("B_OEM_diagnostic_code" , (data) =>
  219. env.logger.debug "B_OEM_diagnostic_code: ", data
  220. )
  221. #ID=116
  222. @otgw.on("B_burner_starts" , (data) =>
  223. env.logger.debug "B_burner_starts: ", data
  224. )
  225. #ID=117
  226. @otgw.on("B_ch_pump_starts" , (data) =>
  227. env.logger.debug "B_ch_pump_starts: ", data
  228. )
  229. #ID=118
  230. @otgw.on("B_dhw_pump_starts" , (data) =>
  231. env.logger.debug "B_dhw_pump_starts: ", data
  232. )
  233. #ID=119
  234. @otgw.on("B_dhw_burner_starts" , (data) =>
  235. env.logger.debug "B_dhw_burner_starts: ", data
  236. )
  237. #ID=120
  238. @otgw.on("B_burner_operation_hours" , (data) =>
  239. env.logger.debug "B_burner_operation_hours: ", data
  240. )
  241. #ID=121
  242. @otgw.on("B_ch_pump_operation_hours" , (data) =>
  243. env.logger.debug "B_ch_pump_operation_hours: ", data
  244. )
  245. #ID=122
  246. @otgw.on("B_dhw_pump_operation_hours" , (data) =>
  247. env.logger.debug "B_dhw_pump_operation_hours: ", data
  248. )
  249. #ID=123
  250. @otgw.on("B_dhw_burner_operation_hours" , (data) =>
  251. env.logger.debug "B_dhw_burner_operation_hours: ", data
  252. )
  253. #ID=124
  254. @otgw.on("opentherm_version_master" , (data) =>
  255. env.logger.debug "opentherm_version_master: ", data
  256. )
  257. #ID=125
  258. @otgw.on("opentherm_version_slave" , (data) =>
  259. env.logger.debug "opentherm_version_slave: ", data
  260. )
  261. #ID=126
  262. @otgw.on("master_version" , (data) =>
  263. env.logger.debug "master_version: ", data
  264. )
  265. #ID=127
  266. @otgw.on("slave_version" , (data) =>
  267. env.logger.debug "slave_version: ", data
  268. )
  269.  
  270. deviceConfigDef = require("./device-config-schema")
  271. @framework.deviceManager.registerDeviceClass("OTGWHeatingThermostat", {
  272. configDef: deviceConfigDef.OTGWHeatingThermostat,
  273. createCallback: (config, lastState) -> new OTGWHeatingThermostat(config, lastState)
  274. })
  275.  
  276. @framework.deviceManager.registerDeviceClass("OTGWMainThermostat", {
  277. configDef: deviceConfigDef.OTGWMainThermostat,
  278. createCallback: (config, lastState) -> new OTGWMainThermostat(config, lastState)
  279. })
  280.  
  281. @framework.deviceManager.registerDeviceClass("OTGWMainThermostat1", {
  282. configDef: deviceConfigDef.OTGWMainThermostat1,
  283. createCallback: (config, lastState) -> new OTGWMainThermostat1(config, lastState)
  284. })
  285.  
  286. @framework.deviceManager.registerDeviceClass("OTGWMainThermostat2", {
  287. configDef: deviceConfigDef.OTGWMainThermostat2,
  288. createCallback: (config, lastState) -> new OTGWMainThermostat2(config, lastState)
  289. })
  290.  
  291. @framework.deviceManager.registerDeviceClass("OTGWFlamePresenceSensor", {
  292. configDef: deviceConfigDef.OTGWFlamePresenceSensor,
  293. createCallback: (config) -> new OTGWFlamePresenceSensor(config)
  294. })
  295.  
  296. @framework.deviceManager.registerDeviceClass("OTGWDomesticHotWater", {
  297. configDef: deviceConfigDef.OTGWDomesticHotWater,
  298. createCallback: (config) -> new OTGWDomesticHotWater(config)
  299. })
  300.  
  301. @framework.deviceManager.registerDeviceClass("OTGWCentralHeating", {
  302. configDef: deviceConfigDef.OTGWCentralHeating,
  303. createCallback: (config) -> new OTGWCentralHeating(config)
  304. })
  305.  
  306. @framework.deviceManager.registerDeviceClass("OTGWThermostat", {
  307. configDef: deviceConfigDef.OTGWThermostat,
  308. createCallback: (config) -> new OTGWThermostat(config)
  309. })
  310.  
  311. # @framework.deviceManager.registerDeviceClass("MaxContactSensor", {
  312. # configDef: deviceConfigDef.MaxContactSensor,
  313. # createCallback: (config, lastState) -> new MaxContactSensor(config, lastState)
  314. # })
  315.  
  316. # @framework.deviceManager.registerDeviceClass("MaxCube", {
  317. # configDef: deviceConfigDef.MaxCube,
  318. # createCallback: (config, lastState) -> new MaxCube(config, lastState)
  319. # })
  320.  
  321. #setTemperatureSetpoint: (rfAddress, mode, value) ->
  322. # setTemperatureSetpoint(mode,value)
  323. setTemperatureSetpoint: (mode, value) ->
  324. @_lastAction = settled(@_lastAction).then( =>
  325. @otgw.setTemperatureAsync(mode, value)
  326. )
  327. return @_lastAction
  328.  
  329.  
  330. plugin = new OTGWThermostatPlugin
  331.  
  332. class OTGWThermostat extends env.devices.Device
  333. _fault = false
  334. _chmode = false
  335. _dhwmode = false
  336. _flame = false
  337. _coolingstatus = false
  338. _ch2mode = false
  339. _diag = false
  340. _chenable = false
  341. _dhwenable = false
  342. _coolingenable = false
  343. _otcstate = false
  344. _ch2enable = false;
  345.  
  346. attributes:
  347. Flame:
  348. description: "Flame status"
  349. type: "boolean"
  350. labels: ["aan", "uit"]
  351. acronym: 'Vlam status'
  352. CentralHeatingMode:
  353. description: "Central Heating Mode"
  354. type: "boolean"
  355. labels: ["aan", "uit"]
  356. acronym: 'Centrale Verwarming Modus'
  357. Fault:
  358. description: "Fault indication"
  359. type: "boolean"
  360. labels: ["aan", "uit"]
  361. acronym: 'Fout indicatie'
  362. DomesticHotWaterMode:
  363. description: "Domestic Hot Water Mode"
  364. type: "boolean"
  365. labels: ["aan", "uit"]
  366. acronym: 'Warm water'
  367. CoolingStatus:
  368. description: "Cooling Status"
  369. type: "boolean"
  370. labels: ["aan", "uit"]
  371. acronym: 'Afkoeling status'
  372. CentralHeating2Mode:
  373. description: "Central Heating 2 Mode"
  374. type: "boolean"
  375. labels: ["aan", "uit"]
  376. acronym: 'Centrale verwarming II'
  377. Diagnostics:
  378. description: "Diagnostics"
  379. type: "boolean"
  380. labels: ["aan", "uit"]
  381. acronym: 'Diagnose'
  382. CentralHeatingEnable:
  383. description: "Central Heating Enable"
  384. type: "boolean"
  385. labels: ["aan", "uit"]
  386. acronym: 'Centrale verwarming aan'
  387. DomesticHotWaterEnable:
  388. description: "Domestic Hot Water Enable"
  389. type: "boolean"
  390. labels: ["aan", "uit"]
  391. acronym: 'Warm water aan'
  392. CoolingEnable:
  393. description: "Cooling Enable"
  394. type: "boolean"
  395. labels: ["aan", "uit"]
  396. acronym: 'Afkoeling aan'
  397. OTCState:
  398. description: "OTC State"
  399. type: "boolean"
  400. labels: ["aan", "uit"]
  401. acronym: 'OTC status'
  402. CentralHeating2Enable:
  403. description: "Central Heating 2 Enable"
  404. type: "boolean"
  405. labels: ["aan", "uit"]
  406. acronym: 'Centrale verwarming II aan'
  407.  
  408. constructor: (@config) ->
  409. @id = @config.id
  410. @name = @config.name
  411.  
  412. plugin.otgw.on("B_flame_status" , (data) =>
  413. if data.length = 16
  414. @_setFault(@_bitToBool(data.slice(15,16)))
  415. @_setCHMode(@_bitToBool(data.slice(14,15)))
  416. @_setDHWMode(@_bitToBool(data.slice(13,14)))
  417. @_setFlame(@_bitToBool(data.slice(12,13)))
  418. @_setCoolingStatus(@_bitToBool(data.slice(11,12)))
  419. @_setCH2Mode(@_bitToBool(data.slice(10,11)))
  420. @_setDiagnostics(@_bitToBool(data.slice(9,10)))
  421. #@_setCHEnable(@_bitToBool(data.slice(8,9)))
  422. @_setCHEnable(@_bitToBool(data.slice(7,8)))
  423. #@_setDHWEnable(@_bitToBool(data.slice(7,8)))
  424. @_setDHWEnable(@_bitToBool(data.slice(6,7)))
  425. #@_setCoolingEnable(@_bitToBool(data.slice(6,7)))
  426. @_setCoolingEnable(@_bitToBool(data.slice(5,6)))
  427. #@_setOTCState(@_bitToBool(data.slice(5,6)))
  428. @_setOTCState(@_bitToBool(data.slice(4,5)))
  429. #@_setCH2Enable(@_bitToBool(data.slice(4,5)))
  430. @_setCH2Enable(@_bitToBool(data.slice(3,4)))
  431. )
  432.  
  433. super()
  434.  
  435. #Getters
  436. getFlame: () -> return Promise.resolve @_flame
  437. getCentralHeatingMode: () -> return Promise.resolve @_chmode
  438. getFault: () -> return Promise.resolve @_fault
  439. getDomesticHotWaterMode: () -> return Promise.resolve @_dhwmode
  440. getCoolingStatus: () -> return Promise.resolve @_coolingstatus
  441. getCentralHeating2Mode: () -> return Promise.resolve @_ch2mode
  442. getDiagnostics: () -> return Promise.resolve @_diag
  443. getCentralHeatingEnable: () -> return Promise.resolve @_chenable
  444. getDomesticHotWaterEnable: () -> return Promise.resolve @_dhwenable
  445. getCoolingEnable: () -> return Promise.resolve @_coolingenable
  446. getOTCState: () -> return Promise.resolve @_otcstate
  447. getCentralHeating2Enable: () -> return Promise.resolve @_ch2enable
  448.  
  449. #Setters
  450. _setFlame: (state) ->
  451. if @_flame isnt state
  452. @_flame = state
  453. @emit 'Flame', state
  454. _setCHMode: (state) ->
  455. if @_chmode isnt state
  456. @_chmode = state
  457. @emit 'CentralHeatingMode', state
  458. _setFault: (state) ->
  459. if @_fault isnt state
  460. @_fault = state
  461. @emit 'Fault', state
  462. _setDHWMode: (state) ->
  463. if @_dhwmode isnt state
  464. @_dhwmode = state
  465. @emit 'DomesticHotWaterMode', state
  466. _setCoolingStatus: (state) ->
  467. if @_coolingstatus isnt state
  468. @_coolingstatus = state
  469. @emit 'CoolingStatus', state
  470. _setCH2Mode: (state) ->
  471. if @_ch2mode isnt state
  472. @_ch2mode = state
  473. @emit 'CentralHeating2Mode', state
  474. _setDiagnostics: (state) ->
  475. if @_diag isnt state
  476. @_diag = state
  477. @emit 'Diagnostics', state
  478. _setCHEnable: (state) ->
  479. if @_chenable isnt state
  480. @_chenable = state
  481. @emit 'CentralHeatingEnable', state
  482. _setDHWEnable: (state) ->
  483. if @_dhwenable isnt state
  484. @_dhwenable = state
  485. @emit 'DomesticHotWaterEnable', state
  486. _setCoolingEnable: (state) ->
  487. if @_coolingenable isnt state
  488. @_coolingenable = state
  489. @emit 'CoolingEnable', state
  490. _setOTCState: (state) ->
  491. if @_otcstate isnt state
  492. @_otcstate = state
  493. @emit 'OTCState', state
  494. _setCH2Enable: (state) ->
  495. if @_ch2enable isnt state
  496. @_ch2enable = state
  497. @emit 'CentralHeating2Enable', state
  498.  
  499. #Functions
  500. _bitToBool: (value) ->
  501. return (value is "1")
  502.  
  503. destroy: () ->
  504. super()
  505.  
  506. class OTGWHeatingThermostat extends env.devices.HeatingThermostat
  507.  
  508. constructor: (@config, lastState) ->
  509. @id = @config.id
  510. @name = @config.name
  511. @_temperatureSetpoint = lastState?.temperatureSetpoint?.value
  512. @_mode = lastState?.mode?.value or "auto"
  513. @_battery = lastState?.battery?.value or "ok"
  514. @_lastSendTime = 0
  515.  
  516. plugin.otgw.on("T_room_setpoint", (data) =>
  517. if data?
  518. data = Number(data)
  519. now = new Date().getTime()
  520. ###
  521. Give the gateway some time to handle the changes. If we send new values to the cube
  522. we set _lastSendTime to the current time. We consider the values as succesfull set, when
  523. the command was not rejected.
  524.  
  525. In the case that the gateway did not react to our the send commands, the values will be
  526. overwritten with the internal state (old ones) of the gateway after 30 seconds.
  527. ###
  528. if @_mode is "auto"
  529. @_setSetpoint(data) #override from gateway
  530. @_setSynced(true)
  531.  
  532. ###
  533. if now - @_lastSendTime < 30*1000
  534. # only if values match, we are synced
  535. if data is @_temperatureSetpoint
  536. @_setSynced(true)
  537. else
  538. # more then 30 seconds passed, set the values anyway
  539. @_setSetpoint(data) #override from gateway
  540.  
  541. @_setSynced(true)
  542. ###
  543.  
  544. return
  545. )
  546. plugin.otgw.on("T_remote_override_setpoint", (data) =>
  547. if data?
  548. data = Number(data)
  549. now = new Date().getTime()
  550. ###
  551. Give the gateway some time to handle the changes. If we send new values to the cube
  552. we set _lastSendTime to the current time. We consider the values as succesfull set, when
  553. the command was not rejected.
  554.  
  555. In the case that the gateway did not react to our the send commands, the values will be
  556. overwritten with the internal state (old ones) of the gateway after 30 seconds.
  557. ###
  558.  
  559.  
  560. if @_mode is "manu"
  561. if data < 1
  562. env.logger.debug "setting to auto"
  563. @_setMode("auto")
  564. else
  565. if now - @_lastSendTime < 30*1000
  566. # only if values match, we are synced
  567. if data is @_temperatureSetpoint
  568. @_setSynced(true)
  569. else
  570. # more then 30 seconds passed, set the values anyway
  571. @_setSetpoint(data)
  572. @_setSynced(true)
  573. if @_mode is "auto" and data > 0.00
  574. @_setMode("manu")
  575.  
  576. return
  577. )
  578. super()
  579.  
  580. changeModeTo: (mode) ->
  581. temp = @_temperatureSetpoint
  582. if mode is "auto"
  583. temp = null
  584. return plugin.setTemperatureSetpoint(mode, temp).then( =>
  585. @_lastSendTime = new Date().getTime()
  586. @_setSynced(false)
  587. @_setMode(mode)
  588. )
  589.  
  590. changeTemperatureTo: (temperatureSetpoint) ->
  591. if @temperatureSetpoint is temperatureSetpoint then return
  592. return plugin.setTemperatureSetpoint(@_mode, temperatureSetpoint).then( =>
  593. @_lastSendTime = new Date().getTime()
  594. @_setSynced(false)
  595. @_setSetpoint(temperatureSetpoint)
  596. )
  597. destroy: () ->
  598. super()
  599.  
  600. class OTGWMainThermostat extends env.devices.TemperatureSensor
  601. _temperature: null
  602.  
  603. constructor: (@config, lastState) ->
  604. @id = @config.id
  605. @name = @config.name
  606. @_temperature = lastState?.temperature?.value
  607. super()
  608.  
  609. plugin.otgw.on("T_room_temperature", (data) =>
  610. if data?
  611. @_temperature = Number(data)
  612. @emit 'temperature', @_temperature
  613. )
  614.  
  615. getTemperature: -> Promise.resolve(@_temperature)
  616.  
  617. destroy: () ->
  618. super()
  619.  
  620. class OTGWMainThermostat1 extends env.devices.Device
  621. temperature: null
  622. temperature01: null
  623. temperature1: null
  624. temperature2: null
  625. temperature3: null
  626. temperature4: null
  627. temperature5: null
  628. temperature6: null
  629. temperature7: null
  630. temperature8: null
  631. temperature9: null
  632. temperature10: null
  633. temperature11: null
  634. temperature12: null
  635.  
  636. attributes:
  637. control_setpoint_T:
  638. description: "Control Setpoint T"
  639. type: "number"
  640. unit: '°C'
  641. acronym: 'Control Setpoint T'
  642. control_setpoint_R:
  643. description: "Control Setpoint R"
  644. type: "number"
  645. unit: '°C'
  646. acronym: 'Control Setpoint R'
  647. remote_override_setpoint:
  648. description: "Remote override Setpoint"
  649. type: "number"
  650. unit: '°C'
  651. acronym: 'Remote Override Setpoint'
  652. max_rel_modulation:
  653. description: "Max Relative Modulation Level"
  654. type: "number"
  655. unit: '%'
  656. acronym: 'Max Relative Modulation Level'
  657. room_setpoint:
  658. description: "Room Setpoint"
  659. type: "number"
  660. unit: '°C'
  661. acronym: 'Room Setpoint'
  662. rel_modulation:
  663. description: "Relative Modulation Level"
  664. type: "number"
  665. unit: '%'
  666. acronym: 'Relative Modulation Level'
  667. water_pressure:
  668. description: "Water Pressure"
  669. type: "number"
  670. unit: 'Bar'
  671. acronym: 'Water Pressure'
  672. room_temperature:
  673. description: "Room Temperature"
  674. type: "number"
  675. unit: '°C'
  676. acronym: 'Room Temperature'
  677. boiler_water_temperature:
  678. description: "Boiler Water Temperature"
  679. type: "number"
  680. unit: '°C'
  681. acronym: 'Boiler Water Temperature'
  682. dhw_temperature:
  683. description: "DHW Temperature"
  684. type: "number"
  685. unit: '°C'
  686. acronym: 'DHW Temperature'
  687. outside_temperature:
  688. description: "Outside Temperature"
  689. type: "number"
  690. unit: '°C'
  691. acronym: 'Outside Temperature'
  692. return_water_temperature:
  693. description: "'Return Water Temperature"
  694. type: "number"
  695. unit: '°C'
  696. acronym: 'Return Water Temperature'
  697. dhw_setpoint:
  698. description: "DWH Setpoint"
  699. type: "number"
  700. unit: '°C'
  701. acronym: 'DWH Setpoint'
  702. max_ch_setpoint:
  703. description: "Max CH Water Setpoint"
  704. type: "number"
  705. unit: '°C'
  706. acronym: 'Max CH Water Setpoint'
  707.  
  708. constructor: (@config, lastState) ->
  709. @id = @config.id
  710. @name = @config.name
  711. @temperature = lastState?.temperature?.value
  712. @temperature1 = lastState?.temperature1?.value
  713. @temperature01 = lastState?.temperature01?.value
  714. @temperature2 = lastState?.temperature2?.value
  715. @temperature3 = lastState?.temperature3?.value
  716. @temperature4 = lastState?.temperature4?.value
  717. @temperature5 = lastState?.temperature5?.value
  718. @temperature6 = lastState?.temperature6?.value
  719. @temperature7 = lastState?.temperature7?.value
  720. @temperature8 = lastState?.temperature8?.value
  721. @temperature9 = lastState?.temperature9?.value
  722. @temperature10 = lastState?.temperature10?.value
  723. @temperature11 = lastState?.temperature11?.value
  724. @temperature12 = lastState?.temperature12?.value
  725. super()
  726.  
  727. console.log('Naam: ');
  728. console.log(String(@config.name));
  729. console.log('Id: ');
  730. console.log(String(@config.id));
  731. console.log('title: ');
  732. console.log(String(@config.title));
  733.  
  734. plugin.otgw.on("T_control_setpoint", (data) =>
  735. if data?
  736. @temperature = Number(data)
  737. @emit 'control_setpoint_T', @temperature
  738. )
  739. plugin.otgw.on("R_control_setpoint", (data) =>
  740. if data?
  741. @temperature01 = Number(data)
  742. @emit 'control_setpoint_R', @temperature01
  743. )
  744. plugin.otgw.on("A_remote_override_setpoint", (data) =>
  745. if data?
  746. @temperature1 = Number(data)
  747. @emit 'remote_override_setpoint', @temperature1
  748. )
  749. plugin.otgw.on("T_max_relative_modulation", (data) =>
  750. if data?
  751. @temperature2 = Number(data)
  752. @emit 'max_rel_modulation', @temperature2
  753. )
  754. plugin.otgw.on("T_room_setpoint", (data) =>
  755. if data?
  756. @temperature3 = Number(data)
  757. @emit 'room_setpoint', @temperature3
  758. )
  759. plugin.otgw.on("B_relative_modulation", (data) =>
  760. if data?
  761. @temperature4 = Number(data)
  762. @emit 'rel_modulation', @temperature4
  763. )
  764. plugin.otgw.on("B_ch_water_pressure", (data) =>
  765. if data?
  766. @temperature5 = Number(data)
  767. @emit 'water_pressure', @temperature5
  768. )
  769. plugin.otgw.on("T_room_temperature", (data) =>
  770. if data?
  771. @temperature6 = Number(data)
  772. @emit 'room_temperature', @temperature6
  773. )
  774. plugin.otgw.on("B_boiler_water_temperature", (data) =>
  775. if data?
  776. @temperature7 = Number(data)
  777. @emit 'boiler_water_temperature', @temperature7
  778. )
  779. plugin.otgw.on("B_dhw_temperature", (data) =>
  780. if data?
  781. @temperature8 = Number(data)
  782. @emit 'dhw_temperature', @temperature8
  783. )
  784. plugin.otgw.on("B_outside_temperature", (data) =>
  785. if data?
  786. @temperature9 = Number(data)
  787. @emit 'outside_temperature', @temperature9
  788. )
  789. plugin.otgw.on("B_return_water_temperature", (data) =>
  790. if data?
  791. @temperature10 = Number(data)
  792. @emit 'return_water_temperature', @temperature10
  793. )
  794. plugin.otgw.on("A_dhw_setpoint", (data) =>
  795. if data?
  796. @temperature11 = Number(data)
  797. @emit 'dhw_setpoint', @temperature11
  798. )
  799. plugin.otgw.on("A_max_ch_setpoint", (data) =>
  800. if data?
  801. @temperature12 = Number(data)
  802. @emit 'max_ch_setpoint', @temperature12
  803. )
  804.  
  805. getControl_setpoint_T: -> Promise.resolve(@temperature)
  806. getControl_setpoint_R: -> Promise.resolve(@temperature01)
  807. getRemote_override_setpoint: -> Promise.resolve(@temperature1)
  808. getMax_rel_modulation: -> Promise.resolve(@temperature2)
  809. getRoom_setpoint: -> Promise.resolve(@temperature3)
  810. getRel_modulation: -> Promise.resolve(@temperature4)
  811. getWater_pressure: -> Promise.resolve(@temperature5)
  812. getRoom_temperature: -> Promise.resolve(@temperature6)
  813. getBoiler_water_temperature: -> Promise.resolve(@temperature7)
  814. getDhw_temperature: -> Promise.resolve(@temperature8)
  815. getOutside_temperature: -> Promise.resolve(@temperature9)
  816. getReturn_water_temperature: -> Promise.resolve(@temperature10)
  817. getDhw_setpoint: -> Promise.resolve(@temperature11)
  818. getMax_ch_setpoint: -> Promise.resolve(@temperature12)
  819.  
  820. destroy: () ->
  821. super()
  822.  
  823. class OTGWDomesticHotWater extends env.devices.Device
  824.  
  825. temperature: null
  826. temperature1: null
  827. temperature2: null
  828. temperature3: null
  829.  
  830. attributes:
  831. #temperature:
  832. #description: "Temperature"
  833. #type: "number"
  834. #acronym: 'Pump Starts'
  835. #temperature1:
  836. #description: "Temperature1"
  837. #type: "number"
  838. #unit: 'H'
  839. #acronym: 'Pump Hours'
  840. #temperature2:
  841. #description: "Temperature2"
  842. #type: "number"
  843. #acronym: 'Burner Starts'
  844. dhwburnerhours:
  845. description: "Burner Hours"
  846. type: "number"
  847. unit: 'H'
  848. acronym: 'Burner Hours'
  849.  
  850. constructor: (@config, lastState) ->
  851. @id = @config.id
  852. @name = @config.name
  853. @temperature = lastState?.temperature?.value
  854. @temperature1 = lastState?.temperature1?.value
  855. @temperature2 = lastState?.temperature2?.value
  856. @temperature3 = lastState?.temperature3?.value
  857. super()
  858.  
  859. plugin.otgw.on("B_dhw_pump_starts", (data) =>
  860. if data?
  861. @temperature = Number(data)
  862. @emit 'temperature', @temperature
  863. )
  864. plugin.otgw.on("B_dhw_pump_operation_hours", (data) =>
  865. if data?
  866. @temperature1 = Number(data)
  867. @emit 'temperature1', @temperature1
  868. )
  869. plugin.otgw.on("B_dhw_burner_starts", (data) =>
  870. if data?
  871. @temperature2 = Number(data)
  872. @emit 'temperature2', @temperature2
  873. )
  874. plugin.otgw.on("B_dhw_burner_operation_hours", (data) =>
  875. if data?
  876. @temperature3 = Number(data)
  877. @emit 'dhwburnerhours', @temperature3
  878. )
  879.  
  880. getTemperature: -> Promise.resolve(@temperature)
  881. getTemperature1: -> Promise.resolve(@temperature1)
  882. getTemperature2: -> Promise.resolve(@temperature2)
  883. getDhwburnerhours: -> Promise.resolve(@temperature3)
  884.  
  885. destroy: () ->
  886. super()
  887.  
  888. class OTGWCentralHeating extends env.devices.Device
  889.  
  890. temperature: null
  891. temperature1: null
  892. temperature2: null
  893. temperature3: null
  894.  
  895. attributes:
  896. #temperature:
  897. #description: "Temperature"
  898. #type: "number"
  899. #acronym: 'Pump Starts'
  900. #temperature1:
  901. #description: "Temperature1"
  902. #type: "number"
  903. #unit: 'H'
  904. #acronym: 'Pump Hours'
  905. ch_burner_starts:
  906. description: "CH Burner Starts"
  907. type: "number"
  908. acronym: 'CH Burner Starts'
  909. ch_burner_hours:
  910. description: "CH Burner Hours"
  911. type: "number"
  912. unit: 'H'
  913. acronym: 'CH Burner Hours'
  914.  
  915. constructor: (@config, lastState) ->
  916. @id = @config.id
  917. @name = @config.name
  918. @temperature = lastState?.temperature?.value
  919. @temperature1 = lastState?.temperature1?.value
  920. @temperature2 = lastState?.temperature2?.value
  921. @temperature3 = lastState?.temperature3?.value
  922. super()
  923.  
  924. plugin.otgw.on("B_ch_pump_starts", (data) =>
  925. if data?
  926. @temperature = Number(data)
  927. @emit 'temperature', @temperature
  928. )
  929. plugin.otgw.on("B_ch_pump_operation_hours", (data) =>
  930. if data?
  931. @temperature1 = Number(data)
  932. @emit 'temperature1', @temperature1
  933. )
  934. plugin.otgw.on("B_burner_starts", (data) =>
  935. if data?
  936. @temperature2 = Number(data)
  937. @emit 'ch_burner_starts', @temperature2
  938. )
  939. plugin.otgw.on("B_burner_operation_hours", (data) =>
  940. if data?
  941. @temperature3 = Number(data)
  942. @emit 'ch_burner_hours', @temperature3
  943. )
  944.  
  945. getTemperature: -> Promise.resolve(@temperature)
  946. getTemperature1: -> Promise.resolve(@temperature1)
  947. getCh_burner_starts: -> Promise.resolve(@temperature2)
  948. getCh_burner_hours: -> Promise.resolve(@temperature3)
  949.  
  950. destroy: () ->
  951. super()
  952.  
  953. class OTGWFlamePresenceSensor extends env.devices.PresenceSensor
  954.  
  955. @_presence = false
  956.  
  957. constructor: (@config) ->
  958. @id = @config.id
  959. @name = @config.name
  960.  
  961. plugin.otgw.on("B_flame_status" , (data) =>
  962. if data.length = 16
  963. @_setPresence(@_bitToBool(data.slice(12,13)))
  964. )
  965. super()
  966.  
  967. #Getters
  968. getPresence: () -> return Promise.resolve @_flame
  969.  
  970. #No need for setter, _setPresence() is implemented by super class
  971.  
  972. #Functions
  973. _bitToBool: (value) ->
  974. return (value is "1")
  975. destroy: () ->
  976. super()
  977.  
  978.  
  979. class OTGWMainThermostat2 extends env.devices.Device
  980.  
  981. attributeTemplates =
  982. ch_pump_starts:
  983. description: "Temperature"
  984. type: "number"
  985. acronym: 'Pump Starts'
  986. ch_pump_operation_hours:
  987. description: "Temperature1"
  988. type: "number"
  989. unit: 'H'
  990. acronym: 'Pump Hours'
  991. dhw_burner_starts:
  992. description: "Temperature2"
  993. type: "number"
  994. acronym: 'Burner Starts'
  995. dhw_burner_operation_hours:
  996. description: "Temperature3"
  997. type: "number"
  998. unit: 'H'
  999. acronym: 'Burner Hours'
  1000.  
  1001. constructor: (@config, @plugin, lastState) ->
  1002. @debug = @plugin.config.debug ? false
  1003. @base = commons.base @, @config.class unless @base?
  1004. @attributeValues = new AttributeContainer()
  1005. @attributes = _.cloneDeep(@attributes)
  1006.  
  1007. for attributeName in @config.attributes
  1008. do (attributeName) =>
  1009. if attributeTemplates.hasOwnProperty attributeName
  1010. properties = attributeTemplates[attributeName]
  1011. @attributes[attributeName] =
  1012. description: properties.description || attributeName.replace /(^[a-z])|([A-Z])/g, ((match, p1, p2, offset) =>
  1013. (if offset>0 then " " else "") + match.toUpperCase())
  1014. type: properties.type
  1015. unit: properties.unit if properties.unit?
  1016. acronym: properties.acronym if properties.acronym?
  1017.  
  1018. @attributeValues.values[attributeName] = 0
  1019.  
  1020. @attributeValues.on properties.key, ((value) =>
  1021. @base.debug "Received update for", properties.key, value
  1022. if value.value? and @attributeValues.values[attributeName] isnt value.value
  1023. @attributeValues.values[attributeName] = value.value
  1024. @emit attributeName, value.value
  1025. )
  1026.  
  1027. @_createGetter(attributeName, =>
  1028. return Promise.resolve @attributeValues[attributeName]
  1029. )
  1030. else
  1031. @base.error "Configuration Error. No such attribute: #{attributeName} - skipping."
  1032.  
  1033. super(@config, @plugin, "GetComponentsData")
  1034.  
  1035. @on 'data', ((error, values) =>
  1036. if error or not values
  1037. if error
  1038. @base.error error
  1039. else
  1040. data = values.Body.Data
  1041. for key,value of data
  1042. @attributeValues.emit key, value if value?
  1043. )
  1044.  
  1045. destroy: () ->
  1046. super()
  1047.  
  1048. return plugin
RAW Paste Data