evok-to-mqtt 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58769f3fe86f38a1962500db4462407dd29f3b904cbc22cdc90fbf325b7b6038
4
- data.tar.gz: 5859defffc657b7cbff987b23608e83cea6b3c39ac5cc2b2113a380fcaf1211a
3
+ metadata.gz: a29afd3b938b2f10b9588d592a29ef3b462bcead45759de1a1663b092822911c
4
+ data.tar.gz: c904ca471f6a893be74cf1b93bf543f44485b8dfb1d55c8c84d98e288977aa07
5
5
  SHA512:
6
- metadata.gz: b69315edff6a40f7a93f5f3eaa2f3e1ec564dc7c8e17bd878e3db980cb723a527ece2545b261bdcf9bd895dda436833c1177073e7a93909b8990e3771a2b534c
7
- data.tar.gz: 38d197cf9882273a929f403052be8b5638448c7a7015ea8deaf627b880f3c702a9a89e77be8de82be794c7f50ea9544379cf1319619c69295790f41040229b05
6
+ metadata.gz: e4ada73da78156bd43da4cc4170cc92b0f3f30672c3c7d94798a54d362a7a72dfadb7d837254e649883d44e301879dfa55377887aa573b8b2c05ee723fcb4134
7
+ data.tar.gz: 9bf89733add87da5bff9a34d0c9623ad54fbbe97a28da5445bc471a12d8c9f027bc69bf83e056d3f5b54597e1838ff71d02a41338d9645d57588cf2949145616
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- evok-to-mqtt (0.3.1)
4
+ evok-to-mqtt (0.3.3)
5
5
  em-mqtt (~> 0.0.5)
6
6
  jsonrpc-client (~> 0.1.3)
7
7
  websocket-eventmachine-client (~> 1.2)
@@ -2,7 +2,7 @@ module EvokToMqtt
2
2
  module Mappers
3
3
  class ToHaab
4
4
  def initialize(mapping)
5
- @mapping = mapping
5
+ @mapping_config = mapping
6
6
  @statuses = {}
7
7
  end
8
8
 
@@ -36,11 +36,18 @@ module EvokToMqtt
36
36
  puts
37
37
  end
38
38
 
39
+ def circuit_reverse_lookup(full_topic)
40
+ dev, topic = full_topic.split("/", 2)
41
+ @mapping_config[dev].each{|pin, a_topic| return pin if a_topic == topic}
42
+ puts "Warning: #{topic} pin was not found."
43
+ nil
44
+ end
45
+
39
46
  private
40
47
 
41
48
  def get_topic(dev, circuit)
42
49
  begin
43
- return @mapping[dev][circuit] || "evok/#{dev}/#{circuit}" # missing circuit
50
+ return @mapping_config[dev][circuit] || @mapping_config[dev]['click'][circuit] || @mapping_config[dev]['toggle'][circuit] || "evok/#{dev}/#{circuit}" # missing circuit
44
51
  rescue => ex
45
52
  puts "Warning: #{ex}, using raw topic"
46
53
  return "evok/#{dev}/#{circuit}" # missing section (dev)
@@ -1,3 +1,3 @@
1
1
  module EvokToMqtt
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -1,8 +1,9 @@
1
+ require 'em/mqtt'
1
2
  require 'eventmachine'
2
- require 'websocket-eventmachine-client'
3
3
  require 'json'
4
- require 'em/mqtt'
4
+ require 'jsonrpc-client'
5
5
  require 'net/http'
6
+ require 'websocket-eventmachine-client'
6
7
 
7
8
  module EvokToMqtt
8
9
  class Worker
@@ -14,11 +15,11 @@ module EvokToMqtt
14
15
 
15
16
  def run
16
17
  EM.run do
17
- @evok = WebSocket::EventMachine::Client.connect(:uri => "ws://#{@evok_host}:8080/ws")
18
- @mqtt = EventMachine::MQTT::ClientConnection.connect(@mqtt_host)
19
- #@evok_rpc = JSONRPC::Client.new(evok_host)
18
+ @evok_ws = WebSocket::EventMachine::Client.connect(:uri => "ws://#{@evok_host}:8080/ws")
19
+ @evok_rpc = JSONRPC::Client.new("http://#{@evok_host}/rpc")
20
+ @mqtt = EventMachine::MQTT::ClientConnection.connect(@mqtt_host)
20
21
 
21
- @evok.onmessage do |msg|
22
+ @evok_ws.onmessage do |msg|
22
23
  data = JSON.parse(msg)
23
24
  data = [data] if data.is_a? Hash # temp is not in array in evok messages, but in hash..
24
25
  data.each do |event|
@@ -28,13 +29,12 @@ module EvokToMqtt
28
29
  end
29
30
  end
30
31
 
31
- @mqtt.subscribe('neuron/relay/#')
32
+ @mqtt.subscribe('relay/#')
32
33
  @mqtt.receive_callback do |msg|
33
- # WS set did not work, using REST for now
34
34
  data = JSON.parse(msg.payload)
35
- puts "Sending command #{msg.topic} => #{data['value']}"
36
- uri = URI("http://#{@evok_host}/rest/#{data['dev']}/#{data['circuit']}")
37
- Net::HTTP.post_form(uri, 'value' => data['value'])
35
+ circuit = data['circuit'] || @mapper.circuit_reverse_lookup(msg.topic)
36
+ puts "Sending command #{msg.topic}: #{circuit} => #{data['value']}"
37
+ @evok_rpc.relay_set(circuit, data['value'])
38
38
  end
39
39
  end
40
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evok-to-mqtt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Aufart