milight-v6 0.1.0 → 0.1.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: 3af0d2759af9191fdeec66af91c2d183637470f5
4
- data.tar.gz: 7a959f4f8018887a71a187c47321146f61909531
3
+ metadata.gz: 5e7c03ca492bd7f803408e17d36df53b078bd9ac
4
+ data.tar.gz: d0e7adb41c0bc5ff1c649ca93c69849addd86e8d
5
5
  SHA512:
6
- metadata.gz: ab7573061d49cde08b90954fb8329c44358b3bbb58b8f8a2d9a3718d7236aac8ffcf9371abcd14f9790cc20998646af7e0a70de0dc7a8b2ea2f818ec1888e300
7
- data.tar.gz: 45a69a1f9f34846cba4d0f96d71eaa716ee8db322c62e71504ee9bd13def67fcb601df81d5b7bf037b3931e606d2cde2428fca1af0686e3dabdc4d7c507cedb2
6
+ metadata.gz: f2480b71b8e1e6c31d7d41dd14052d856d5dfbe8f473e2250fdd533b2a404b096831e86601f6e9d520b69dc805e3fd73c2b93b80b83a5362fca6588efd135ad9
7
+ data.tar.gz: aa7c8814f18470f8623358b9d5366770159564a982c8f58e9ca2a0d14c558f87cc6e90e9c210d9f1b8979212cfa1d7d9f005c5e884b29ec4f4879df920391f20
data/.gitignore CHANGED
@@ -9,3 +9,6 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ .ruby-version
14
+ .ruby-gemset
@@ -4,6 +4,7 @@ AllCops:
4
4
  DisplayStyleGuide: true
5
5
  Exclude:
6
6
  - 'lib/milight/v6/api/version.rb'
7
+ - 'vendor/**/*'
7
8
 
8
9
  Metrics/BlockLength:
9
10
  Exclude:
@@ -1,5 +1,10 @@
1
- sudo: false
2
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ before_install:
5
+ - gem update --system
6
+ - gem install bundler
3
7
  rvm:
4
- - 2.3.5
5
- before_install: gem install bundler -v 1.16.1
8
+ - 2.3.8
9
+ - 2.4.5
10
+ - 2.5.3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- milight-v6 (0.1.0)
4
+ milight-v6 (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Milight Wifi Bridge v6 Ruby API
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/milight-v6.svg)](https://badge.fury.io/rb/milight-v6)
4
+ [![Build Status](https://travis-ci.org/ppostma/milight-v6-api.svg?branch=master)](https://travis-ci.org/ppostma/milight-v6-api)
5
+ [![Code Climate](https://codeclimate.com/github/ppostma/milight-v6-api/badges/gpa.svg)](https://codeclimate.com/github/ppostma/milight-v6-api)
6
+
3
7
  This gem provides a Ruby API for the Milight Wifi Bridge (or Wifi iBOX controller) version 6.
4
8
 
5
9
  ## Installation
@@ -26,9 +30,9 @@ require "milight/v6"
26
30
  controller = Milight::V6::Controller.new("192.168.178.33")
27
31
  controller.zone(1).on
28
32
 
29
- controller.zone(2).on.brightness(70).warm_light
33
+ controller.zone(2).warm_light.brightness(70).on
30
34
 
31
- controller.zone(3).on.saturation(80).hue(Milight::V6::Color::BLUE)
35
+ controller.zone(3).hue(Milight::V6::Color::BLUE).saturation(10).on
32
36
 
33
37
  controller.all.off
34
38
  ```
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "milight/v6/exception"
3
4
  require "milight/v6/socket"
4
5
 
5
6
  module Milight
6
7
  module V6
7
- # see http://www.limitlessled.com/dev/
8
+ # see https://github.com/Fantasmos/LimitlessLED-DevAPI
8
9
  class Command
9
10
  def initialize(host, port = 5987)
10
11
  @socket = Milight::V6::Socket.new(host, port)
@@ -83,6 +84,8 @@ module Milight
83
84
  @socket.send_bytes(request)
84
85
  response = @socket.receive_bytes
85
86
 
87
+ raise Exception, "Could not establish session with Wifi bridge." unless response
88
+
86
89
  @session_id1 = response[19]
87
90
  @session_id2 = response[20]
88
91
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milight
4
+ module V6
5
+ class Exception < StandardError
6
+ end
7
+ end
8
+ end
@@ -6,10 +6,11 @@ require "socket"
6
6
  module Milight
7
7
  module V6
8
8
  class Socket
9
+ READ_TIMEOUT = 5
10
+
9
11
  def initialize(host, port)
10
- @host = host
11
- @port = port
12
12
  @socket = UDPSocket.new
13
+ @socket.connect(host, port)
13
14
 
14
15
  @logger = Logger.new(STDOUT)
15
16
  @logger.level = Logger::INFO if ENV["MILIGHT_DEBUG"] != "1"
@@ -18,16 +19,21 @@ module Milight
18
19
  def send_bytes(bytes)
19
20
  @logger.debug("Sending: #{format_bytes_as_hex(bytes)}")
20
21
 
21
- @socket.send bytes.pack('C*'), 0, @host, @port
22
+ @socket.send(bytes.pack('C*'), 0)
22
23
  end
23
24
 
24
25
  def receive_bytes
25
- response = @socket.recvfrom(128).first
26
+ response = @socket.recvfrom_nonblock(128).first
26
27
  bytes = response.unpack('C*')
27
28
 
28
29
  @logger.debug("Received: #{format_bytes_as_hex(bytes)}")
29
30
 
30
31
  bytes
32
+ rescue IO::WaitReadable
33
+ ready = IO.select([@socket], nil, nil, READ_TIMEOUT)
34
+ retry if ready
35
+
36
+ return false
31
37
  end
32
38
 
33
39
  private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Milight
4
4
  module V6
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milight-v6
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
  - Peter Postma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-04 00:00:00.000000000 Z
11
+ date: 2019-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,8 +64,6 @@ files:
64
64
  - ".gitignore"
65
65
  - ".rspec"
66
66
  - ".rubocop.yml"
67
- - ".ruby-gemset"
68
- - ".ruby-version"
69
67
  - ".travis.yml"
70
68
  - Gemfile
71
69
  - Gemfile.lock
@@ -80,6 +78,7 @@ files:
80
78
  - lib/milight/v6/color.rb
81
79
  - lib/milight/v6/command.rb
82
80
  - lib/milight/v6/controller.rb
81
+ - lib/milight/v6/exception.rb
83
82
  - lib/milight/v6/socket.rb
84
83
  - lib/milight/v6/version.rb
85
84
  - lib/milight/v6/zone.rb
@@ -1 +0,0 @@
1
- milight
@@ -1 +0,0 @@
1
- 2.3.5