evok-to-mqtt 0.1.0 → 0.1.1

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: 3db1b32b0c22c3c9bffb59f9ca9fc80eb83cf6a7d9e17c88755a7c0fa1aad8f1
4
- data.tar.gz: 3786dd14185c93a5085f8bbe6380f49a68e7b98ea32f0230188bd1f42edba046
3
+ metadata.gz: 3b8a025e0a49655d2600d98163bb1038e0cdba9a4a4131012940efb8e17b8b63
4
+ data.tar.gz: d564c74d4024df8ecbee13394ffe70163ce0eb2cd96dc7e16abbe6f99ea4e8ae
5
5
  SHA512:
6
- metadata.gz: 190ea00c248819ea318ef416870f1add390223862f5c7d90a3e84a79bab20a5623629a11d9747bbacf537fac1b5f32152a1acda30f6f76afc677b7f0dd86a121
7
- data.tar.gz: 4fd52972c8c6a0c4eec569c7da0462ee038f23e885f624dc57f37485d157ade43ee6ed1d7e8641e3466f7afb957e5d28d501f475b30bfdb9899b6846801d89ce
6
+ metadata.gz: 91d6da3ddae3de197b740bb0b8504a0b8000cf4af0068748b625bf0659825e01982595e6c8a359a5aac7c9c111a7349b32baf93e550d13b4e2fdf6e847a3e591
7
+ data.tar.gz: 9723748c9e94304aa33c72a43c5154c896231663d0f8f69d450ff0c693aa7f154002e7dee9a15fee7546554359aae23f8123fddc6d7320749d9a361d5360cb6e
@@ -2,8 +2,8 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  evok-to-mqtt (0.1.0)
5
- em-mqtt
6
- websocket-eventmachine-client
5
+ em-mqtt (~> 0.0.5)
6
+ websocket-eventmachine-client (~> 1.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -4,19 +4,7 @@ A bridge between Unipi's EVOK and MQTT message bus. It uses websockets to connec
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'evok-to-mqtt'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install evok-to-mqtt
7
+ $ gem install evok-to-mqtt
20
8
 
21
9
  ## Usage
22
10
 
@@ -32,7 +20,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
20
 
33
21
  ## Contributing
34
22
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/evok-to-mqtt.
23
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aufi/evok-to-mqtt.
36
24
 
37
25
  ## License
38
26
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  module EvokToMqtt
6
6
  def self.run(evok_host, mqtt_host)
7
- app = EvokToMqtt::Worker.new(evok_host, mqtt_host)
7
+ app = EvokToMqtt::Worker.new(evok_host, mqtt_host, EvokToMqtt::Mappers::ToHaab.new)
8
8
  app.run
9
9
  end
10
10
  end
@@ -0,0 +1,33 @@
1
+ module EvokToMqtt
2
+ module Mappers
3
+ class ToHaab
4
+ def initialize
5
+ @statuses = {}
6
+ end
7
+
8
+ def process(mqtt, evok_event)
9
+ # puts "Statuses"
10
+ # p @statuses
11
+ id = evok_event["circuit"]
12
+ now = Time.now
13
+ payload = evok_event
14
+
15
+ # Neuron input is assumed for now
16
+ if @statuses[id]
17
+ if @statuses[id][:value] == 0 && evok_event['value'] == 1
18
+ mqtt.publish id, {action: 'down', data: payload}
19
+ elsif @statuses[id][:value] == 1 && evok_event['value'] == 0
20
+ mqtt.publish id, {action: 'up', data: payload}
21
+ mqtt.publish id, {action: 'click', data: payload} if now - @statuses[id][:changed_at] < 2 # seconds
22
+ # ignore events not changing value
23
+ end
24
+ @statuses[id][:value] = evok_event['value']
25
+ @statuses[id][:changed_at] = now
26
+ else
27
+ @statuses[id] = {value: evok_event['value'], changed_at: now}
28
+ mqtt.publish id, {action: 'down', data: payload}
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module EvokToMqtt
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -5,11 +5,10 @@ require 'em/mqtt'
5
5
 
6
6
  module EvokToMqtt
7
7
  class Worker
8
- def initialize(evok_host, mqtt_host)
9
- #@evok = ::Faye::WebSocket::Client.new("ws://#{evok_host}:8080/ws")
8
+ def initialize(evok_host, mqtt_host, mapper)
10
9
  @evok_host = evok_host
11
- #@mqtt = ::MQTT::Client.connect(mqtt_host)
12
10
  @mqtt_host = mqtt_host
11
+ @mapper = mapper
13
12
  end
14
13
 
15
14
  def run
@@ -18,10 +17,9 @@ module EvokToMqtt
18
17
  @mqtt = ::EventMachine::MQTT::ClientConnection.connect(@mqtt_host)
19
18
 
20
19
  @evok.onmessage do |msg|
21
- # puts "Recieved message: #{msg}"
20
+ puts "Recieved message: #{msg}"
22
21
  JSON.parse(msg).each do |event|
23
- puts event
24
- @mqtt.publish event["circuit"], event
22
+ @mapper.process(@mqtt, event)
25
23
  end
26
24
  end
27
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evok-to-mqtt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Aufart
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-28 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-eventmachine-client
@@ -100,7 +100,7 @@ files:
100
100
  - bin/setup
101
101
  - evok-to-mqtt.gemspec
102
102
  - lib/evok-to-mqtt.rb
103
- - lib/evok-to-mqtt/mappers/evok_to_haab.rb
103
+ - lib/evok-to-mqtt/mappers/to_haab.rb
104
104
  - lib/evok-to-mqtt/version.rb
105
105
  - lib/evok-to-mqtt/worker.rb
106
106
  homepage: https://github.com/aufi/evok-to-mqtt
@@ -1,7 +0,0 @@
1
- module EvokToMqtt
2
- module Mappers
3
- class EvokToHaab
4
-
5
- end
6
- end
7
- end