lifx_api 0.1.1 → 0.1.2

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: d724c2ee6d1e686079cbcf9bda0f888547d8db20
4
- data.tar.gz: e5a883b787b636d093401004320b6d44cac66510
3
+ metadata.gz: 7063a23a72264177f1c0390f2f166c9786b89dde
4
+ data.tar.gz: 5612881962ec05bd1fa756162ada974d52812f05
5
5
  SHA512:
6
- metadata.gz: 186ec61411ed72701e4e72c98ab795c6c55f16ee026d0e10533579d831cbffd776a3d91027457e03abc743e610d346bb9716011d848df083b546a95696954ac8
7
- data.tar.gz: d9febdadb923782c658e73158557ad5c9970ef263868f90addd0435a970ce133c1fc484d91f1076bcad9f0269353a0ee7bf090bcbcdee81ee77cd135ed7f8a5f
6
+ metadata.gz: d0af62c3c50bf5b19da43f0315dabbd21b3dec47a116722463ef0378b6423d4eb7aedf5f3ea4011fd0a28a23393f89ad892502297ea7c28759d4c492bd5d4fb2
7
+ data.tar.gz: eb95de0ae02a7bbb1eb17235b904f347decc4ecb67ad5ed93354edb821881eb6ad567483f96f508a9c9c7d848ccf12dd8a5a0c17c3d6f4ec64dd9fa6f9c8e1ad
data/CHANGELOG ADDED
@@ -0,0 +1,15 @@
1
+ === 0.1.2
2
+
3
+ * Better validation of :selectors
4
+
5
+ * Unit tests for validators
6
+
7
+ * Fix some errors in the endpoints definition
8
+
9
+ === 0.1.1
10
+
11
+ * Added endpoint documentation
12
+
13
+ === 0.0.1
14
+
15
+ * Initial release
data/README.md CHANGED
@@ -48,7 +48,7 @@ See [LIFX HTTP API](https://api.developer.lifx.com/) for the official documentat
48
48
 
49
49
  Key | Type | Mandatory | Default | Description
50
50
  --- | --- | --- | --- | ---
51
- `:selector` | selector | | all |
51
+ `:selector` | selector | | all |
52
52
 
53
53
  ### set_state
54
54
 
@@ -56,7 +56,7 @@ Key | Type | Mandatory | Default | Description
56
56
 
57
57
  Key | Type | Mandatory | Default | Description
58
58
  --- | --- | --- | --- | ---
59
- `:selector` | selector | | all |
59
+ `:selector` | selector | | all |
60
60
  `:power` | string | | | The power state you want to set on the selector. on or off
61
61
  `:color` | string | | | The color to set the light to.
62
62
  `:brightness` | numeric | | | The brightness level from 0.0 to 1.0. Overrides any brightness set in color (if any).
@@ -69,8 +69,8 @@ Key | Type | Mandatory | Default | Description
69
69
 
70
70
  Key | Type | Mandatory | Default | Description
71
71
  --- | --- | --- | --- | ---
72
- `:states` | | ✔ | |
73
- `:defaults` | hash | | |
72
+ `:states` | | ✔ | |
73
+ `:defaults` | hash | | |
74
74
 
75
75
  ### stage_delta
76
76
 
@@ -78,7 +78,7 @@ Key | Type | Mandatory | Default | Description
78
78
 
79
79
  Key | Type | Mandatory | Default | Description
80
80
  --- | --- | --- | --- | ---
81
- `:selector` | selector | | all |
81
+ `:selector` | selector | | all |
82
82
  `:power` | on_off | | | The power state you want to set on the selector. on or off
83
83
  `:duration` | numeric | | 1.0 | How long in seconds you want the power action to take. Range: 0.0 - 3155760000.0 (100 years)
84
84
  `:infrared` | numeric | | | The maximum brightness of the infrared channel.
@@ -93,7 +93,7 @@ Key | Type | Mandatory | Default | Description
93
93
 
94
94
  Key | Type | Mandatory | Default | Description
95
95
  --- | --- | --- | --- | ---
96
- `:selector` | selector | | all |
96
+ `:selector` | selector | | all |
97
97
  `:duration` | numeric | | 1.0 | The time is seconds to spend perfoming the power toggle.
98
98
 
99
99
  ### breathe_effect
@@ -102,7 +102,7 @@ Key | Type | Mandatory | Default | Description
102
102
 
103
103
  Key | Type | Mandatory | Default | Description
104
104
  --- | --- | --- | --- | ---
105
- `:selector` | selector | | all |
105
+ `:selector` | selector | | all |
106
106
  `:color` | string | ✔ | | The color to use for the breathe effect.
107
107
  `:from_color` | string | | current bulb color | The color to start the effect from. If this parameter is omitted then the color the bulb is currently set to is used instead.
108
108
  `:period` | numeric | | 1.0 | The time in seconds for one cyles of the effect.
@@ -117,7 +117,7 @@ Key | Type | Mandatory | Default | Description
117
117
 
118
118
  Key | Type | Mandatory | Default | Description
119
119
  --- | --- | --- | --- | ---
120
- `:selector` | selector | | all |
120
+ `:selector` | selector | | all |
121
121
  `:color` | string | ✔ | | The color to use for the pulse effect.
122
122
  `:from_color` | string | | current bulb color | The color to start the effect from. If this parameter is omitted then the color the bulb is currently set to is used instead.
123
123
  `:period` | numeric | | 1.0 | The time in seconds for one cyles of the effect.
@@ -179,6 +179,11 @@ If there is an error, LifxApi will raise an exception. The exception message wil
179
179
 
180
180
  Run `rake test` to run the tests and `rake console` to start an interactive pry console.
181
181
 
182
+ ## TODO
183
+
184
+ * Validation of `:state' and ':array_of_states' is poor
185
+ * Validation of endpoints is non-existent
186
+
182
187
  ## Contributing
183
188
 
184
189
  Bug reports and pull requests are welcome on GitHub at https://github.com/cyclotron3k/lifx_api.
data/lib/lifx_api.rb CHANGED
@@ -49,21 +49,31 @@ class LifxApi
49
49
  def valid?(value, value_format)
50
50
  case value_format
51
51
  when :selector
52
- value =~ /^((label|id|(location|group)(_id)?|scene_id):.*|all)$/
53
- when :numeric
54
- value.is_a?(Numeric) or value =~ /^[\d\.]+$/
52
+ value.split(',').all? do |selector|
53
+ /^((label|id|(location|group)(_id)?|scene_id):.*|all)(:random|(\|[-\d]+)+)?$/ === selector
54
+ end
55
+ when :numeric, :brightness, :duration, :infrared
56
+ value.is_a?(Numeric) or /^[\d\.]+$/ === value
55
57
  when :boolean
56
58
  ['true', 'false', true, false].include? value
57
- when :on_off
59
+ when :on_off, :power
58
60
  ['on', 'off'].include? value
59
61
  when :hash
60
62
  value.is_a? Hash
61
- when :string
63
+ when :string, :color
62
64
  value.is_a? String
63
65
  when :uuid
64
- value.is_a?(String) and value =~ /^[\da-f]{4}([\da-f]{4}-){4}[\da-f]{12}$/
66
+ value.is_a?(String) and /^[\da-f]{4}([\da-f]{4}-){4}[\da-f]{12}$/ === value
67
+ when :ignore_array
68
+ value.is_a?(Array) and (value - ['power', 'infrared', 'duration', 'intensity', 'hue', 'saturation', 'brightness', 'kelvin']).empty?
69
+ when :direction
70
+ value.is_a?(String) and ['forward', 'backward'].include? value
71
+ when :array_of_states
72
+ value.is_a?(Array) and value.count <= 50 and value.all? { |state| valid? state, :state }
73
+ when :state
74
+ value.is_a?(Hash) and (value.keys - [:selector, :power, :color, :brightness, :duration, :infrared]).empty? and value.all? { |k, v| valid? v, k }
65
75
  else
66
- puts "Don't know how to validate #{value_format}" if DEBUG
76
+ raise ArgumentError, "Don't know how to validate #{value_format}"
67
77
  true
68
78
  end
69
79
  end
@@ -25,7 +25,7 @@ class LifxApi
25
25
  http_method: :put,
26
26
  path: '/v1/lights/states',
27
27
  body_params: {
28
- states: {required: true},
28
+ states: {required: true, type: :array_of_states},
29
29
  defaults: {type: :hash},
30
30
  },
31
31
  }, {
@@ -90,9 +90,9 @@ class LifxApi
90
90
  http_method: :post,
91
91
  path: '/v1/lights/%{selector}/cycle',
92
92
  body_params: {
93
- states: {required: true, type: 'array of mixed', description: 'Array of state hashes as per Set State. Must have 2 to 5 entries.'},
94
- defaults: {type: 'object', description: 'Default values to use when not specified in each states[] object.'},
95
- direction: {type: 'stringforward', description: 'Direction in which to cycle through the list. Can be forward or backward'},
93
+ states: {required: true, type: :array_of_states, description: 'Array of state hashes as per Set State. Must have 2 to 5 entries.'},
94
+ defaults: {type: :state, description: 'Default values to use when not specified in each states[] object.'},
95
+ direction: {type: :direction, description: 'Direction in which to cycle through the list. Can be forward or backward'},
96
96
  }
97
97
  }, {
98
98
  method_name: :list_scenes,
@@ -107,8 +107,8 @@ class LifxApi
107
107
  },
108
108
  body_params: {
109
109
  duration: {type: :numeric, default_description: '1.0', description: 'The time in seconds to spend performing the scene transition.'},
110
- ignore: {type: 'array of strings', description: 'Any of "power", "infrared", "duration", "intensity", "hue", "saturation", "brightness" or "kelvin", specifying that these properties should not be changed on devices when applying the scene.'},
111
- overrides: {type: 'object', description: 'A state object as per Set State specifying properties to apply to all devices in the scene, overriding those configured in the scene.'},
110
+ ignore: {type: :ignore_array, description: 'Any of "power", "infrared", "duration", "intensity", "hue", "saturation", "brightness" or "kelvin", specifying that these properties should not be changed on devices when applying the scene.'},
111
+ overrides: {type: :state, description: 'A state object as per Set State specifying properties to apply to all devices in the scene, overriding those configured in the scene.'},
112
112
  }
113
113
  }, {
114
114
  method_name: :validate_color,
@@ -1,3 +1,3 @@
1
1
  class LifxApi
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifx_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - cyclotron3k
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2017-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,6 +73,7 @@ extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
75
  - ".gitignore"
76
+ - CHANGELOG
76
77
  - Gemfile
77
78
  - LICENSE.txt
78
79
  - README.md