message: [feat] Make devices work with all devices types
diff: @@ -593,13 +593,23 @@ Gateway.prototype.discoverDevice = function (node, hassDevice) {
  payload.current_temperature_topic = this.mqtt.getTopic(this.valueTopic(node, currTemp))
  payload.temperature_state_topic = this.mqtt.getTopic(this.valueTopic(node, setpoint))
  payload.temperature_command_topic = payload.temperature_state_topic + '/set'
  - } else if (hassDevice.type === 'fan') {
  + } else {
  payload = hassDevice.discovery_payload
  - var fan = node.values[payload.state_topic]
  - payload.state_topic = this.mqtt.getTopic(this.valueTopic(node, fan))
  - payload.command_topic = payload.state_topic + '/set'
  - payload.speed_command_topic = payload.command_topic
  - payload.speed_state_topic = payload.state_topic
  +
  + var topics = {}
  +
  + // popolate topics object with valueId: valueTopic
  + for (let i = 0; i < hassDevice.values.length; i++) {
  + const v = hassDevice.values[i] // the value id
  + topics[v] = node.values[v] ? this.mqtt.getTopic(this.valueTopic(node, node.values[v])) : null
  + }
  +
  + // set the correct command/state topics
  + for (const key in payload) {
  + if (key.indexOf('topic') >= 0 && topics[payload[key]]) {
  + payload[key] = topics[payload[key]] + (key.indexOf('command') >= 0 ? '/set' : '')
  + }
  + }
  }
  if (payload) {
  