domotics-core 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a8ed63671e10315d7088954915555a65e06f584
4
- data.tar.gz: 0236feacef77fb06929960aef64ffe8ad76f420d
3
+ metadata.gz: d31d71816c9455bade9c824b113015a28910e2d6
4
+ data.tar.gz: 05587d42ffd80c7c24a82397293e9f47a9971715
5
5
  SHA512:
6
- metadata.gz: c2bba5ade068a12ef7dab4397f98179034629fbd4f4f6941a9855ccd7ccca3d7b34ae9be38ea7d19010a1a6048b0308625a5ab9531e860d3085a1672357c191f
7
- data.tar.gz: e803b482603d93d6b0a37f410165f6dbd36ba241d980c0dc9588cc70a2b52c14c64b236db118a0b7ed643c63bf7f5af6f462a5f4ef1789bb6621e8fd7d9ef032
6
+ metadata.gz: 79d8973f4ea95522a1398e06532642858a7379abf44181a7819aae2988b4b8ed9feb0ca3af9336fb8470d59b545722dde781008bffbc0a85fa2e11929b96a153
7
+ data.tar.gz: e210292eb529442ab3d7de20dc706e2fd320207064c0b25fdcbdb951b0cf1542e42599519989f22c01c0a833d46993c668823a00b41472fdbc66f5796205d180
@@ -17,6 +17,10 @@ module Domotics::Core
17
17
  super
18
18
  end
19
19
 
20
+ def state
21
+ st = super
22
+ st.is_a?(Integer) ? st : 0
23
+ end
20
24
  def set_state(value = DEFAULT_LEVEL, opt = {})
21
25
  unless opt[:kill_fader] == :no
22
26
  @fade_lock.synchronize do
@@ -25,9 +25,11 @@ module Domotics::Core
25
25
  end
26
26
 
27
27
  def off
28
- kill_crazy
29
- @strips.values.each { |strip| strip.off } if on?
30
- set_state :off
28
+ if on?
29
+ kill_crazy
30
+ @strips.values.each { |strip| strip.off }
31
+ set_state :off
32
+ end
31
33
  end
32
34
 
33
35
  def color
@@ -7,7 +7,7 @@ Thread.class_eval do
7
7
  block.call
8
8
  rescue Exception => e
9
9
  Domotics::Core::Setup.logger.error { e.message }
10
- Domotics::Core::Setup.logger.debug { e }
10
+ Domotics::Core::Setup.logger.debug { e.inspect }
11
11
  nil
12
12
  end
13
13
  end
@@ -58,6 +58,7 @@ module Domotics::Core
58
58
  def event_handler(msg = {})
59
59
  event, element = msg[:event], msg[:element]
60
60
  @logger.info { "Event message :#{event} from #{element} with state [#{element.state}]" }
61
+ Domotics::Core::WsServer.publish "#{element.room.name}/#{element.name}"
61
62
  end
62
63
 
63
64
  def destroy
@@ -2,6 +2,8 @@ module Domotics::Core
2
2
  class Server
3
3
  def initialize(args = {})
4
4
  @logger = Domotics::Core::Setup.logger || Logger.new(STDERR)
5
+ @args = {}
6
+ @args[:Host], @args[:Port] = args[:host], args[:port]
5
7
  end
6
8
  def call(env)
7
9
  # [object]/[action]/[params]
@@ -22,7 +24,7 @@ module Domotics::Core
22
24
  result = object.public_send(action, *request.map { |param| param.to_isym })
23
25
  rescue Exception => e
24
26
  @logger.error { e.message }
25
- @logger.debug { e }
27
+ @logger.debug { e.backtrace.join $/ }
26
28
  return invalid 'request'
27
29
  end
28
30
  case form
@@ -36,6 +38,10 @@ module Domotics::Core
36
38
  end
37
39
  end
38
40
 
41
+ def run
42
+ Rack::Handler::Thin.run Rack::Builder.new{ run Domotics::Core::Server.new }, @args
43
+ end
44
+
39
45
  private
40
46
 
41
47
  def invalid(param)
@@ -1,6 +1,6 @@
1
1
  module Domotics
2
2
  module Core
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
6
6
 
@@ -1,21 +1,28 @@
1
1
  module Domotics::Core
2
2
  class WsServer
3
+ @@channel = EM::Channel.new
3
4
  def initialize(args = {})
5
+ @logger = Domotics::Core::Setup.logger || Logger.new(STDERR)
4
6
  @args = args
5
- @channel = EM::Channel.new
6
7
  end
7
8
  def run
8
- EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws|
9
- ws.onopen do
10
- sid = @channel.subscribe { |msg| ws.send msg }
11
- ws.onmessage do |msg|
12
-
13
- end
14
- ws.onclose do
15
- @channel.unsubscribe(sid)
9
+ Thread.new do
10
+ @logger.info { "Starting WebSocet Server on #{@args[:host]}:#{@args[:port]}" }
11
+ EventMachine::WebSocket.start(@args) do |ws|
12
+ ws.onopen do
13
+ sid = @@channel.subscribe { |msg| ws.send msg }
14
+ ws.onmessage do |msg|
15
+ @logger.info { "WebSocket message [#{msg}] from client [#{sid}]" }
16
+ end
17
+ ws.onclose do
18
+ @@channel.unsubscribe(sid)
19
+ end
16
20
  end
17
21
  end
18
22
  end
19
23
  end
24
+ def self.publish(msg)
25
+ @@channel.push msg
26
+ end
20
27
  end
21
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domotics-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - goredar