switchbot 0.2.0 → 0.5.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
  SHA256:
3
- metadata.gz: 990f1f755928da1c7b552986461ef23fe759e174fa3bfac50e71c302a1602769
4
- data.tar.gz: cf07e66ff95980862c53a24cda08c930d0e5b51f4c3b08bf17b663198294a5af
3
+ metadata.gz: b35104bc79a51e707f6a2295423a135e5ee06380eb4f5b2ad14b1fea15a72288
4
+ data.tar.gz: d01885018b1ff8759a6ac2c8b1e2c14704d2e15105b282e74c24cc2a937a8f84
5
5
  SHA512:
6
- metadata.gz: c1aadb12d0af5102103b9304aeae71300ca75e7828552bb43ed778a91c39e6b38999a00717e1e090cc7f388dd7ce024f7ca5b6bb0aa3af562be05b1598c6cf04
7
- data.tar.gz: 774fbf9e8bb38df81d15af448c29aa0b0b1b10a1523f24b545e1181736f2b6692dc0d44a4d34f82e2e3c452aeab34218a63564e3423a1c020384cdf10c83774f
6
+ metadata.gz: a3ecbbc03b18cbf6e7650f0171b645055a25eb541f1115b689fb7cde2a34a622f2f6ee898944fd45dacbd6cc6ebbbb0b0478bcdfb0e9e6703938fe24716c76e9
7
+ data.tar.gz: 6c0fcb55db5bb61d78ed247dc2dc9c40a269dc4bed68a27832b1a22f74a718d68055f1fa40483603fc33c771be6f77ff0cd4980deee43f89b9928703162ac7bd
@@ -5,12 +5,17 @@ on: [push,pull_request]
5
5
  jobs:
6
6
  build:
7
7
  runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
11
+ ruby: [2.5, 2.6, 2.7, '3.0', 3.1]
12
+ name: Ruby ${{ matrix.ruby }}
8
13
  steps:
9
14
  - uses: actions/checkout@v2
10
15
  - name: Set up Ruby
11
16
  uses: ruby/setup-ruby@v1
12
17
  with:
13
- ruby-version: 2.5.7
18
+ ruby-version: ${{ matrix.ruby }}
14
19
  - name: Run the default task
15
20
  run: |
16
21
  gem install bundler -v 2.2.4
data/.rubocop.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  AllCops:
2
+ TargetRubyVersion: 2.5
2
3
  NewCops: enable
3
4
 
4
5
  Style/Documentation:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  ## Unreleased
2
- [full changelog](http://github.com/ytkg/switchbot/compare/v0.2.0...main)
2
+ [full changelog](http://github.com/ytkg/switchbot/compare/v0.5.1...main)
3
+
4
+ ## v0.5.1
5
+ [full changelog](http://github.com/ytkg/switchbot/compare/v0.5.0...v0.5.1)
6
+
7
+ * Enable MFA requirement for gem releasing
8
+ * https://github.com/ytkg/switchbot/pull/11
9
+
10
+ ## v0.5.0
11
+ [full changelog](http://github.com/ytkg/switchbot/compare/v0.4.0...v0.5.0)
12
+
13
+ * Add Bot
14
+ * https://github.com/ytkg/switchbot/pull/9
15
+
16
+ ## v0.4.0
17
+ [full changelog](http://github.com/ytkg/switchbot/compare/v0.3.0...v0.4.0)
18
+
19
+ * Add Humidifier
20
+ * https://github.com/ytkg/switchbot/pull/7
21
+ * Add Light
22
+ * https://github.com/ytkg/switchbot/pull/6
23
+ * Add Device#on? and Device#off?
24
+ * https://github.com/ytkg/switchbot/pull/5
25
+
26
+ ## v0.3.0
27
+ [full changelog](http://github.com/ytkg/switchbot/compare/v0.2.0...v0.3.0)
28
+
29
+ * Add `Device#on` and `Device#off`
30
+ * https://github.com/ytkg/switchbot/pull/4
31
+ * Add Device#commands
32
+ * https://github.com/ytkg/switchbot/pull/3
3
33
 
4
34
  ## v0.2.0
5
35
  [full changelog](http://github.com/ytkg/switchbot/compare/v0.1.0...v0.2.0)
data/README.md CHANGED
@@ -20,13 +20,15 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- ```
23
+ ```ruby
24
24
  require 'switchbot'
25
25
 
26
26
  client = Switchbot::Client.new('YOUR_TOKEN')
27
+ ```
27
28
 
28
- # Get device list
29
- # GET https://api.switch-bot.com/v1.0/devices
29
+ ### Get device list
30
+ GET https://api.switch-bot.com/v1.0/devices
31
+ ```ruby
30
32
  client.devices
31
33
  #=> {:status_code=>100,
32
34
  # :body=>
@@ -42,9 +44,11 @@ client.devices
42
44
  # :remote_type=>"TV",
43
45
  # :hub_device_id=>"FA7310762361"}]},
44
46
  # :message=>"success"}
47
+ ```
45
48
 
46
- # Get device status
47
- # GET https://api.switch-bot.com/v1.0/devices/C271111EC0AB/status
49
+ ### Get device status
50
+ GET https://api.switch-bot.com/v1.0/devices/C271111EC0AB/status
51
+ ```ruby
48
52
  client.status(device_id: 'C271111EC0AB')
49
53
  # or
50
54
  client.device('C271111EC0AB').status
@@ -56,16 +60,24 @@ client.device('C271111EC0AB').status
56
60
  # :humidity=>52,
57
61
  # :temperature=>26.1},
58
62
  # :message=>"success"}
63
+ ```
59
64
 
60
- # Send device control commands
61
- # POST https://api.switch-bot.com/v1.0/devices/210/commands
65
+ ### Send device control commands
66
+ POST https://api.switch-bot.com/v1.0/devices/210/commands
67
+ ```ruby
62
68
  client.commands(device_id: '210', command: 'turnOn')
69
+ # or
70
+ client.device('C271111EC0AB').commands(command: 'turnOn')
71
+ # or
72
+ client.device('C271111EC0AB').on
63
73
  #=> {:status_code=>100,
64
74
  # :body=>{},
65
75
  # :message=>"success"}
76
+ ```
66
77
 
67
- # Get scene list
68
- # GET https://api.switch-bot.com/v1.0/scenes
78
+ ### Get scene list
79
+ GET https://api.switch-bot.com/v1.0/scenes
80
+ ```ruby
69
81
  client.scenes
70
82
  #=> {:status_code=>100,
71
83
  # :body=>
@@ -80,9 +92,11 @@ client.scenes
80
92
  # {:scene_id=>"T02-202011062059-26364981",
81
93
  # :scene_name=>"Set Bedroom to 26 degree"}],
82
94
  # :message=>"success"}
95
+ ```
83
96
 
84
- # Execute manual scenes
85
- # POST https://api.switch-bot.com/v1.0/scenes/T02-202009221414-48924101/execute
97
+ ### Execute manual scenes
98
+ POST https://api.switch-bot.com/v1.0/scenes/T02-202009221414-48924101/execute
99
+ ```ruby
86
100
  client.execute(scene_id: 'T02-202009221414-48924101')
87
101
  # or
88
102
  client.scene('T02-202009221414-48924101').execute
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Switchbot
4
+ class Bot < Device
5
+ def press
6
+ commands(command: 'press')
7
+ end
8
+ end
9
+ end
@@ -56,6 +56,18 @@ module Switchbot
56
56
  )
57
57
  end
58
58
 
59
+ def bot(device_id)
60
+ Bot.new(client: self, device_id: device_id)
61
+ end
62
+
63
+ def light(device_id)
64
+ Light.new(client: self, device_id: device_id)
65
+ end
66
+
67
+ def humidifier(device_id)
68
+ Humidifier.new(client: self, device_id: device_id)
69
+ end
70
+
59
71
  private
60
72
 
61
73
  def headers
@@ -12,5 +12,25 @@ module Switchbot
12
12
  def status
13
13
  client.status(device_id: device_id)
14
14
  end
15
+
16
+ def commands(command:, parameter: 'default', command_type: 'command')
17
+ client.commands(device_id: device_id, command: command, parameter: parameter, command_type: command_type)
18
+ end
19
+
20
+ def on
21
+ client.commands(device_id: device_id, command: 'turnOn')
22
+ end
23
+
24
+ def off
25
+ client.commands(device_id: device_id, command: 'turnOff')
26
+ end
27
+
28
+ def on?
29
+ status[:body][:power] == 'on'
30
+ end
31
+
32
+ def off?
33
+ !on?
34
+ end
15
35
  end
16
36
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Switchbot
4
+ class Humidifier < Device
5
+ def mode(value)
6
+ commands(command: 'setMode', parameter: value.to_s)
7
+ end
8
+
9
+ def auto
10
+ mode(:auto)
11
+ end
12
+
13
+ def low
14
+ mode(101)
15
+ end
16
+
17
+ def medium
18
+ mode(102)
19
+ end
20
+
21
+ def high
22
+ mode(103)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Switchbot
4
+ class Light < Device
5
+ def brightness_up
6
+ commands(command: 'brightnessUp')
7
+ end
8
+
9
+ def brightness_down
10
+ commands(command: 'brightnessDown')
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchbot
4
- VERSION = '0.2.0'
4
+ VERSION = '0.5.1'
5
5
  end
data/lib/switchbot.rb CHANGED
@@ -8,6 +8,9 @@ require_relative 'switchbot/version'
8
8
  require_relative 'switchbot/client'
9
9
  require_relative 'switchbot/device'
10
10
  require_relative 'switchbot/scene'
11
+ require_relative 'switchbot/bot'
12
+ require_relative 'switchbot/light'
13
+ require_relative 'switchbot/humidifier'
11
14
 
12
15
  module Switchbot
13
16
  class Error < StandardError; end
data/switchbot.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.metadata['homepage_uri'] = spec.homepage
20
20
  spec.metadata['source_code_uri'] = 'https://github.com/ytkg/switchbot'
21
21
  spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
22
23
 
23
24
  # Specify which files should be added to the gem when it is released.
24
25
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -37,7 +38,7 @@ Gem::Specification.new do |spec|
37
38
  spec.add_development_dependency 'rake', '~> 13.0'
38
39
  spec.add_development_dependency 'rspec', '~> 3.0'
39
40
  spec.add_development_dependency 'rspec-its'
40
- spec.add_development_dependency 'rubocop', '~> 0.80'
41
+ spec.add_development_dependency 'rubocop', '>= 1.24.1'
41
42
  spec.add_development_dependency 'webmock'
42
43
 
43
44
  # For more information and examples about making a new gem, checkout our
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiki Takagi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-04 00:00:00.000000000 Z
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '0.80'
103
+ version: 1.24.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '0.80'
110
+ version: 1.24.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: webmock
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -142,8 +142,11 @@ files:
142
142
  - bin/console
143
143
  - bin/setup
144
144
  - lib/switchbot.rb
145
+ - lib/switchbot/bot.rb
145
146
  - lib/switchbot/client.rb
146
147
  - lib/switchbot/device.rb
148
+ - lib/switchbot/humidifier.rb
149
+ - lib/switchbot/light.rb
147
150
  - lib/switchbot/scene.rb
148
151
  - lib/switchbot/version.rb
149
152
  - switchbot.gemspec
@@ -154,7 +157,8 @@ metadata:
154
157
  homepage_uri: https://github.com/ytkg/switchbot
155
158
  source_code_uri: https://github.com/ytkg/switchbot
156
159
  changelog_uri: https://github.com/ytkg/switchbot/blob/main/CHANGELOG.md
157
- post_install_message:
160
+ rubygems_mfa_required: 'true'
161
+ post_install_message:
158
162
  rdoc_options: []
159
163
  require_paths:
160
164
  - lib
@@ -169,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
173
  - !ruby/object:Gem::Version
170
174
  version: '0'
171
175
  requirements: []
172
- rubygems_version: 3.2.4
173
- signing_key:
176
+ rubygems_version: 3.3.3
177
+ signing_key:
174
178
  specification_version: 4
175
179
  summary: SwitchBot API client for Ruby
176
180
  test_files: []