yeelight-client 1.0.2 → 1.0.3

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: eb98a134503f504391f1761d58cb09eb9679daf9ac1f7a9b70289ee00f05ab76
4
- data.tar.gz: 0a0fee6c5ea0404fef06d81e1df180e42debdc1c5eab37b1abb30588655ae27f
3
+ metadata.gz: 83fbe6a22fa518845613a0a7601688afe2cc1dda13f485aecd1ea9817459d844
4
+ data.tar.gz: 4c22e9a33137a66ff286f1218350970f565e1c084efe942fe3d3d166544004f1
5
5
  SHA512:
6
- metadata.gz: aa273c4520f489e82948d812e1cd3de64f9240463a818baa079ec1e982ff2f041fda57261911a7b234bba33c7402464f653948848aa0de4fb8495f65fa37213b
7
- data.tar.gz: 3b631a17ca51965a6efc6386763e46c16d5d8e0cb36e5bc73fe3bc6e8a3efe1f6c56f1b5e68c6313ef32553789f1cdbba951f131050134ad966556cf9e779805
6
+ metadata.gz: 11038321442e83ea9c7d20f3b70ad0d840e85397bb3a64a2ad3d5321dad88c0341cd4554ed4bbf499880eab5c0679913522f6c00c370db86d66691c2b9224ea7
7
+ data.tar.gz: 7df23d9f91a23940763afdaf4d0781169cf0ad7259f9618d3b2db8af7ccfb85453f6adb6977c2b63480917ab1c42d55fdf99ac8fd03abee6d84bfbf9494a93aa
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yeelight-client (1.0.2)
4
+ yeelight-client (1.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -3,12 +3,39 @@ require "yeelight_client/connection"
3
3
  require "yeelight_client/requests"
4
4
  require "yeelight_client/response"
5
5
  require "yeelight_client/response/result"
6
+ require "yeelight_client/response/properties"
6
7
  require "yeelight_client/response/exception"
7
8
  require "yeelight_client/broadcast"
8
9
 
9
10
  class YeelightClient
10
11
  include Requests
11
12
 
13
+ SUPPORTED_PROPERTIES = %i[
14
+ power
15
+ bright
16
+ ct
17
+ rgb
18
+ hue
19
+ sat
20
+ color_mode
21
+ flowing
22
+ delayoff
23
+ flow_params
24
+ music_on
25
+ name
26
+ bg_power
27
+ bg_flowing
28
+ bg_flow_params
29
+ bg_ct
30
+ bg_lmode
31
+ bg_bright
32
+ bg_rgb
33
+ bg_hue
34
+ bg_sat
35
+ nl_br
36
+ active_mode
37
+ ]
38
+
12
39
  DEFAULT_PARAMS = {
13
40
  effect: "sudden".freeze,
14
41
  duration: 0
@@ -39,4 +66,8 @@ class YeelightClient
39
66
  def prep_params(params)
40
67
  DEFAULT_PARAMS.merge(params)
41
68
  end
69
+
70
+ def prep_props(props)
71
+ props.map(&:to_sym) & SUPPORTED_PROPERTIES
72
+ end
42
73
  end
@@ -2,6 +2,18 @@ class YeelightClient
2
2
  module Requests
3
3
  extend Handler
4
4
 
5
+ def get_prop(props: nil)
6
+ props = prep_props(props || PROPERTIES)
7
+
8
+ query = {
9
+ method: "get_prop",
10
+ params: props
11
+ }
12
+
13
+ responses = @connection.request(query)
14
+ responses.map { |response| Response::Properties.new(props, response) }
15
+ end
16
+
5
17
  def set_bright(value, params: {})
6
18
  params = prep_params(params)
7
19
  .slice(:effect, :duration)
@@ -25,6 +25,8 @@ class YeelightClient
25
25
  def detect_errors
26
26
  # EOFError - when lamp is busy
27
27
  case @exception
28
+ when JSON::ParserError
29
+ assign_errors(:invalid_json, :device_error)
28
30
  when EOFError
29
31
  assign_errors(:device_busy, :device_error)
30
32
  when Timeout::Error, Errno::ETIMEDOUT
@@ -0,0 +1,17 @@
1
+ class YeelightClient
2
+ class Response
3
+ class Properties < YeelightClient::Response::Result
4
+ def initialize(*args)
5
+ @props = args[0]
6
+ super(*args[1..-1])
7
+ end
8
+
9
+ def data
10
+ return {} unless success?
11
+ result = @data["result"]
12
+ array = @props.map.with_index { |prop, i| [prop, result[i]] }
13
+ Hash[array]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,15 +2,22 @@ class YeelightClient
2
2
  class Response
3
3
  class Result < YeelightClient::Response
4
4
  def data
5
- return unless success?
6
- super["result"]
5
+ return {} unless success?
6
+ @data["result"]
7
7
  end
8
8
 
9
- # {"id"=>4, "error"=>{"code"=>-5000, "message"=>"general error"}}
10
- # Result {"id":8232,"error":{"code":-1,"message":"client quota exceeded"}}
11
9
  def detect_errors
12
- return unless success?
10
+ return if success?
11
+ message = @data.dig("error", "message")
13
12
 
13
+ case message
14
+ when /client quota exceeded/i
15
+ assign_errors(:request_quota, :device_error)
16
+ when /general error/i
17
+ assign_errors(:bad_request, :bad_input)
18
+ else
19
+ super
20
+ end
14
21
  end
15
22
  end
16
23
  end
@@ -1,3 +1,3 @@
1
1
  class YeelightClient
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yeelight-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Ostroumov
@@ -107,6 +107,7 @@ files:
107
107
  - lib/yeelight_client/requests.rb
108
108
  - lib/yeelight_client/response.rb
109
109
  - lib/yeelight_client/response/exception.rb
110
+ - lib/yeelight_client/response/properties.rb
110
111
  - lib/yeelight_client/response/result.rb
111
112
  - lib/yeelight_client/version.rb
112
113
  - yeelight-client.gemspec
@@ -128,8 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  - !ruby/object:Gem::Version
129
130
  version: '0'
130
131
  requirements: []
131
- rubyforge_project:
132
- rubygems_version: 2.7.6
132
+ rubygems_version: 3.0.6
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Yeelight Client