milight-v6 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 +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +8 -3
- data/Gemfile.lock +1 -1
- data/README.md +6 -2
- data/lib/milight/v6/command.rb +4 -1
- data/lib/milight/v6/exception.rb +8 -0
- data/lib/milight/v6/socket.rb +10 -4
- data/lib/milight/v6/version.rb +1 -1
- metadata +3 -4
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e7c03ca492bd7f803408e17d36df53b078bd9ac
|
4
|
+
data.tar.gz: d0e7adb41c0bc5ff1c649ca93c69849addd86e8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2480b71b8e1e6c31d7d41dd14052d856d5dfbe8f473e2250fdd533b2a404b096831e86601f6e9d520b69dc805e3fd73c2b93b80b83a5362fca6588efd135ad9
|
7
|
+
data.tar.gz: aa7c8814f18470f8623358b9d5366770159564a982c8f58e9ca2a0d14c558f87cc6e90e9c210d9f1b8979212cfa1d7d9f005c5e884b29ec4f4879df920391f20
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Milight Wifi Bridge v6 Ruby API
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/milight-v6)
|
4
|
+
[](https://travis-ci.org/ppostma/milight-v6-api)
|
5
|
+
[](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).
|
33
|
+
controller.zone(2).warm_light.brightness(70).on
|
30
34
|
|
31
|
-
controller.zone(3).
|
35
|
+
controller.zone(3).hue(Milight::V6::Color::BLUE).saturation(10).on
|
32
36
|
|
33
37
|
controller.all.off
|
34
38
|
```
|
data/lib/milight/v6/command.rb
CHANGED
@@ -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
|
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
|
data/lib/milight/v6/socket.rb
CHANGED
@@ -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
|
22
|
+
@socket.send(bytes.pack('C*'), 0)
|
22
23
|
end
|
23
24
|
|
24
25
|
def receive_bytes
|
25
|
-
response = @socket.
|
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
|
data/lib/milight/v6/version.rb
CHANGED
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.
|
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:
|
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
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
milight
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.3.5
|