xilight 0.1.2 → 0.1.5

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: 8c3dc25e017b83233fc1bd1a00381a9caa30017d82ef30fb8faa1b939c180e08
4
- data.tar.gz: 312521fb62a439c0c7450dfafb85d8b2b8bdef79800d9a09a49122c768d8fb0b
3
+ metadata.gz: 44464a51e814edd4efc2df5a1fbf336f8081faa936cc1a3a1e228bcdc6777ae7
4
+ data.tar.gz: fd04dddea590e4f0fb860b57e5334bacf017f151245eb839e425fd1727d6ebe0
5
5
  SHA512:
6
- metadata.gz: 74b7b836df129bf26a10d7693537bed7c79ce7c1295739063965db489d51700412a19760d8ed30fea94c3e50c0b2961cbd837629da87e58380c76ea0251f94c0
7
- data.tar.gz: 6aca5cae5c1c4380fe4fc4a42e55e0891a7e920cf02d03b533e131a76935c4b02975a6868aad7fe98aff751898c43defc6f30c4d3b8151721e6f34f0031a2983
6
+ metadata.gz: d065ccb4e6aa4ff99984778525dd69f1b6fda9cf2d7f25e1de176d241b53fbcd846e8735588cb11634f8a9efb320d5374f280803a9c72ebdab27ca0928dfa07b
7
+ data.tar.gz: 538d5da718744d16bd2690728a496cfd799fbee712ed97ec1166be6bde5deabf4a7b00e40b91cfeff47d3141e96f90038894d4450ee936e490903c8c0fba94b3
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Yeelight
1
+ # Xilight
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/xilight`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Xilight provides a Ruby library and a CLI interface to control your Xiaomi Yeelight programmatically.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ **Note**: It requires your yeelight to be configured to [development mode](https://www.yeelight.com/en_US/developer).
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,7 +22,226 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ ### Library
26
+
27
+ Read the API docs [here](https://rubydoc.info/github/wouterken/xilight/master/Xilight/Yeelight).
28
+
29
+ ### CLI
30
+
31
+ #### Help
32
+
33
+ yee -h
34
+
35
+ #### Discovery
36
+ Command:
37
+ yee discover
38
+
39
+ Usage:
40
+ yee discover
41
+
42
+ Description:
43
+ Discover Yeelights and save to ~/.config/.yeelights
44
+
45
+ Options:
46
+ --help, -h # Print this help
47
+
48
+ Examples:
49
+ yee discover
50
+
51
+ #### List Lights
52
+
53
+ Command:
54
+ yee list
55
+
56
+ Usage:
57
+ yee list
58
+
59
+ Description:
60
+ List known Yeelights
61
+
62
+ Options:
63
+ --help, -h # Print this help
64
+
65
+ Examples:
66
+ yee list
67
+
68
+ #### Set Light Name
69
+
70
+ Command:
71
+ yee name
72
+
73
+ Usage:
74
+ yee name NAME
75
+
76
+ Description:
77
+ Set name for Yeelight
78
+
79
+ Arguments:
80
+ NAME # REQUIRED Name to set for light
81
+
82
+ Options:
83
+ --light=VALUE, -l VALUE # ID/index of Yeelight to target, default: "0"
84
+ --help, -h # Print this help
85
+
86
+ Examples:
87
+ yee name name -l 1 foo # Set the name for light#1 to "foo"
88
+
89
+
90
+ #### Set RGB
91
+
92
+ Command:
93
+ yee rgb
94
+
95
+ Usage:
96
+ yee rgb R G B
97
+
98
+ Description:
99
+ Set RGB for Yeelight
100
+
101
+ Arguments:
102
+ R # REQUIRED Red (0-255)
103
+ G # REQUIRED Green (0-255)
104
+ B # REQUIRED Blue (0-255)
105
+
106
+ Options:
107
+ --light=VALUE, -l VALUE # ID/index of Yeelight to target, default: "0"
108
+ --name=VALUE, -n VALUE # Name of Yeelight to target
109
+ --help, -h # Print this help
110
+
111
+ Examples:
112
+ yee rgb 255 0 0 # set light to red (red 255, green 0, blue 0)
113
+ yee rgb 0 0 180 -n foo# set light with name foo to blue (red 0, green 0, blue 180)
114
+ yee rgb 255 255 255 -l 3# set light #3 to white (red 255, green 255, blue 255)
115
+
116
+
117
+ #### Brightness
118
+
119
+ Command:
120
+ yee bright
121
+
122
+ Usage:
123
+ yee bright BRIGHTNESS
124
+
125
+ Description:
126
+ Set Brightness for Yeelight
127
+
128
+ Arguments:
129
+ BRIGHTNESS # REQUIRED Brightness (0-100)
130
+
131
+ Options:
132
+ --light=VALUE, -l VALUE # ID/index of Yeelight to target, default: "0"
133
+ --name=VALUE, -n VALUE # Name of Yeelight to target
134
+ --help, -h # Print this help
135
+
136
+ Examples:
137
+ yee bright 100 # full brightness
138
+ yee bright 50 -n foo # 50% brightness for light with name foo
139
+ yee bright 25 -l 3 # 25% brightness for light#3
140
+
141
+ #### Set HSV
142
+
143
+ Command:
144
+ yee hsv
145
+
146
+ Usage:
147
+ yee hsv H S
148
+
149
+ Description:
150
+ Set HSV for Yeelight
151
+
152
+ Arguments:
153
+ H # REQUIRED Hue (0-359)
154
+ S # REQUIRED Saturation (0-100)
155
+
156
+ Options:
157
+ --light=VALUE, -l VALUE # ID/index of Yeelight to target, default: "0"
158
+ --name=VALUE, -n VALUE # Name of Yeelight to target
159
+ --help, -h # Print this help
160
+
161
+ Examples:
162
+ yee hsv 180 40 # set hue to 180 and saturation to 40
163
+ yee hsv 200 20 -n foo# set light with name foo to hue: 200, saturation: 20
164
+ yee hsv 359 90 -l 3# set light #3 to hue: 359, saturation: 90
165
+
166
+ #### Turn Off
167
+
168
+ Command:
169
+ yee off
170
+
171
+ Usage:
172
+ yee off
173
+
174
+
175
+ Description:
176
+ Turn Off Yeelight
177
+
178
+ Options:
179
+ --light=VALUE, -l VALUE # ID/index of Yeelight to target, default: "0"
180
+ --name=VALUE, -n VALUE # Name of Yeelight to target
181
+ --help, -h # Print this help
182
+
183
+ Examples:
184
+ yee off # turn default/first light off
185
+ yee off -n kitchen # turn light with name 'kitchen' off
186
+ yee off -l 3 # turn light #3 off
187
+
188
+ #### Turn On
189
+ Command:
190
+ yee on
191
+
192
+ Usage:
193
+ yee on
194
+
195
+ Description:
196
+ Turn on Yeelight
197
+
198
+ Options:
199
+ --light=VALUE, -l VALUE # ID/index of Yeelight to target, default: "0"
200
+ --name=VALUE, -n VALUE # Name of Yeelight to target
201
+ --help, -h # Print this help
202
+
203
+ Examples:
204
+ yee on # turn default/first light on
205
+ yee on -n kitchen # turn light with name 'kitchen' on
206
+ yee on -l 3 # turn light #3 on
207
+
208
+ #### Toggle
209
+
210
+ Command:
211
+ yee toggle
212
+
213
+ Usage:
214
+ yee toggle
215
+
216
+ Description:
217
+ Toggle Yeelight
218
+
219
+ Options:
220
+ --light=VALUE, -l VALUE # ID/index of Yeelight to target, default: "0"
221
+ --name=VALUE, -n VALUE # Name of Yeelight to target
222
+ --help, -h # Print this help
223
+
224
+ Examples:
225
+ yee toggle # toggle default/first light
226
+ yee toggle -n kitchen # toggle light with name 'kitchen'
227
+ yee toggle -l 3 # toggle light #3
228
+
229
+ #### Version
230
+
231
+ Command:
232
+ yee version
233
+
234
+ Usage:
235
+ yee version
236
+
237
+ Description:
238
+ Print version
239
+
240
+ Options:
241
+ --help, -h # Print this help
242
+
243
+ Examples:
244
+ yee version
26
245
 
27
246
  ## Development
28
247
 
@@ -32,5 +251,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
251
 
33
252
  ## Contributing
34
253
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/xilight. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
254
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wouterken/xilight. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
255
 
data/exe/yee CHANGED
@@ -58,17 +58,11 @@ module Xilight
58
58
  ]
59
59
 
60
60
  def call(**)
61
- current_config = ::Xilight::CLI.config
62
- current_lights = current_config.fetch('yeelights', [])
63
- ::Xilight::Yeelight.discover.each do |light|
64
- current_lights.reject!{|l| l['id'] == light.id}
65
- current_lights << light.instance_variables.map{|v| [v.to_s[1..-1], light.instance_variable_get(v)] }.to_h
66
- end
67
- current_config['yeelights'] = current_lights
68
- current_lights.each_with_index do |light, index|
69
- puts "Light ##{index} => #{(light['name'] || light['id'])}@#{light['host']}"
70
- end
71
- ::Xilight::CLI.config = current_config
61
+ ::Xilight::CLI.config = {
62
+ 'yeelights' => ::Xilight::Yeelight.discover.each do |light|
63
+ light.instance_variables.map{|v| [v.to_s[1..-1], light.instance_variable_get(v)] }.to_h
64
+ end
65
+ }
72
66
  end
73
67
  end
74
68
 
@@ -236,7 +230,7 @@ module Xilight
236
230
  Object.const_set(class_name, Class.new(Dry::CLI::Command) do
237
231
  desc "Set yeelight to color #{color}"
238
232
  example [
239
- "#{color}"
233
+ ""
240
234
  ]
241
235
 
242
236
  option :light, desc: "ID/index of Yeelight to target", default: "0", aliases: ["-l"]
@@ -25,11 +25,17 @@ module Xilight
25
25
  end
26
26
 
27
27
  def request(cmd)
28
- s = TCPSocket.open(@host, @port)
29
- s.puts "#{JSON.generate(cmd)}\r\n"
30
- data = s.gets.chomp
31
- s.close
32
- JSON.parse(data)
28
+ begin
29
+ Timeout.timeout(0.5) do
30
+ s = TCPSocket.open(@host, @port)
31
+ s.puts "#{JSON.generate(cmd)}\r\n"
32
+ data = s.gets.chomp
33
+ s.close
34
+ JSON.parse(data)
35
+ end
36
+ rescue Timeout::Error
37
+ puts "Yeelight connection timed out. Yeelight not accessible"
38
+ end
33
39
  end
34
40
 
35
41
  # This method is used to retrieve current property of smart LED.
@@ -37,38 +43,44 @@ module Xilight
37
43
  request({id: 1,method: 'get_prop', params: values})
38
44
  end
39
45
 
40
- # This method is used to change the color temperature of a smart LED.
46
+ # This method is used to change the color temperature of the smart LED.
41
47
  def set_ct_abx(ct_value, effect='smooth', duration=200)
42
48
  request({id: 2,method: 'set_ct_abx', params: [ct_value,effect,duration]})
43
49
  end
44
50
 
51
+ # This method is used to change the color temperature of the smart LED.
45
52
  def ct_abx=ct_value
46
53
  set_ct_abx(ct_value)
47
54
  end
48
55
 
49
- # This method is used to change the color RGB of a smart LED.
56
+ # This method is used to change the color RGB of the smart LED.
57
+ # Expects an integer representing a hex triplet (e.g. 0xFFFFFF )
50
58
  def set_rgb(rgb_value, effect='smooth', duration=200)
51
59
  request({id: 3,method: 'set_rgb', params: [rgb_value,effect,duration]})
52
60
  end
53
61
 
62
+ # This method is used to change the color RGB of the smart LED.
63
+ # Expects an integer representing a hex triplet (e.g. 0xFFFFFF )
54
64
  def rgb=rgb_value
55
65
  set_rgb(rgb_value)
56
66
  end
57
67
 
58
- # This method is used to change the color HSV of a smart LED.
68
+ # This method is used to change the color HSV of the smart LED.
59
69
  def set_hsv(hue, sat, effect='smooth', duration=200)
60
70
  request({id: 4,method: 'set_hsv', params: [hue,sat,effect,duration]})
61
71
  end
62
72
 
73
+ # This method is used to change the color HSV of the smart LED.
63
74
  def hsv=hue
64
75
  set_hsv(hue)
65
76
  end
66
77
 
67
- # This method is used to change the brightness of a smart LED.
78
+ # This method is used to change the brightness of the smart LED.
68
79
  def set_bright(brightness, effect='smooth', duration=200)
69
80
  request({id: 5,method: 'set_bright', params: [brightness,effect,duration]})
70
81
  end
71
82
 
83
+ # This method is used to change the brightness of the smart LED.
72
84
  def bright=brightness
73
85
  set_bright(brightness)
74
86
  end
@@ -78,6 +90,7 @@ module Xilight
78
90
  request({id: 6,method: 'set_power', params: [power,effect,duration]})
79
91
  end
80
92
 
93
+ # This method is used to switch on or off the smart LED (software managed on/off).
81
94
  def power=power
82
95
  set_power(power)
83
96
  end
@@ -87,16 +100,15 @@ module Xilight
87
100
  request({id: 7,method: 'toggle', params: []})
88
101
  end
89
102
 
90
- # This method is used to save current state of smart LED in persistent memory.
91
- # So if user powers off and then powers on the smart LED again (hard power reset),
92
- # the smart LED will show last saved state.
93
- # Note: The "automatic state saving" must be turn off
103
+ # This method is used to save the current state of smart LED in persistent memory.
104
+ # If user powers off and then powers on the smart LED again (hard power reset),
105
+ # the smart LED will show last the saved state.
94
106
  def set_default
95
107
  request({id: 8,method: 'set_default', params: []})
96
108
  end
97
109
 
98
110
  # This method is used to start a color flow. Color flow is a series of smart
99
- # LED visible state changing. It can be brightness changing, color changing
111
+ # LED visible state changes. It can be either brightness changing, color changing
100
112
  # or color temperature changing
101
113
  def start_cf(count, action, flow_expression)
102
114
  request({id: 9,method: 'set_power', params: [count,action,flow_expression]})
@@ -108,8 +120,8 @@ module Xilight
108
120
  end
109
121
 
110
122
  # This method is used to set the smart LED directly to specified state. If
111
- # the smart LED is off, then it will turn on the smart LED firstly and then
112
- # apply the specified scommand.
123
+ # the smart LED is off, then it will first turn on the smartLED and then
124
+ # apply the specified command.
113
125
  def set_scene(classe, val1, val2)
114
126
  request({id: 11,method: 'set_scene', params: [classe,val1,val2]})
115
127
  end
@@ -131,14 +143,14 @@ module Xilight
131
143
  end
132
144
 
133
145
  # This method is used to change brightness, CT or color of a smart LED
134
- # without knowing the current value, it's main used by controllers.
146
+ # without knowing the current value, it's mainly used by controllers.
135
147
  def set_adjust(action, prop)
136
148
  request({id: 15,method: 'set_adjust', params: [action,prop]})
137
149
  end
138
150
 
139
151
  # This method is used to name the device. The name will be stored on the
140
- # device and reported in discovering response. User can also read the name
141
- # through “get_prop” method.
152
+ # device and reported in the discovery response. Users can also read the device name
153
+ # through the “get_prop” method.
142
154
  def set_name(name)
143
155
  request({id: 16,method: 'set_name', params: [name]})
144
156
  end
@@ -158,7 +170,7 @@ module Xilight
158
170
  end
159
171
 
160
172
 
161
- # This method is used to discover a smart LED in the network
173
+ # This method is used to discover a smart LED on the local network
162
174
  def self.discover
163
175
  host = "239.255.255.250"
164
176
  port = 1982
@@ -1,3 +1,3 @@
1
1
  module Xilight
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -11,6 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = "Ruby Xiaomi Yeelight gem"
13
13
  spec.description = "Ruby Xiaomi Yeelight gem"
14
+ spec.homepage = "https://github.com/wouterken/xilight"
14
15
 
15
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -29,7 +30,7 @@ Gem::Specification.new do |spec|
29
30
  spec.require_paths = ["lib"]
30
31
  spec.add_runtime_dependency "dry-cli"
31
32
  spec.add_development_dependency "bundler", "~> 1.13"
32
- spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rake", ">= 12.3.3"
33
34
  spec.add_development_dependency "pry"
34
35
  spec.add_development_dependency "pry-byebug"
35
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xilight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wouter Coppieters
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-26 00:00:00.000000000 Z
11
+ date: 2020-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: 12.3.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: 12.3.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -99,7 +99,7 @@ files:
99
99
  - lib/xilight.rb
100
100
  - lib/xilight/version.rb
101
101
  - xilight.gemspec
102
- homepage:
102
+ homepage: https://github.com/wouterken/xilight
103
103
  licenses: []
104
104
  metadata: {}
105
105
  post_install_message: