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 +4 -4
- data/.github/workflows/main.yml +6 -1
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +31 -1
- data/README.md +25 -11
- data/lib/switchbot/bot.rb +9 -0
- data/lib/switchbot/client.rb +12 -0
- data/lib/switchbot/device.rb +20 -0
- data/lib/switchbot/humidifier.rb +25 -0
- data/lib/switchbot/light.rb +13 -0
- data/lib/switchbot/version.rb +1 -1
- data/lib/switchbot.rb +3 -0
- data/switchbot.gemspec +2 -1
- metadata +14 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b35104bc79a51e707f6a2295423a135e5ee06380eb4f5b2ad14b1fea15a72288
|
4
|
+
data.tar.gz: d01885018b1ff8759a6ac2c8b1e2c14704d2e15105b282e74c24cc2a937a8f84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3ecbbc03b18cbf6e7650f0171b645055a25eb541f1115b689fb7cde2a34a622f2f6ee898944fd45dacbd6cc6ebbbb0b0478bcdfb0e9e6703938fe24716c76e9
|
7
|
+
data.tar.gz: 6c0fcb55db5bb61d78ed247dc2dc9c40a269dc4bed68a27832b1a22f74a718d68055f1fa40483603fc33c771be6f77ff0cd4980deee43f89b9928703162ac7bd
|
data/.github/workflows/main.yml
CHANGED
@@ -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:
|
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
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
## Unreleased
|
2
|
-
[full changelog](http://github.com/ytkg/switchbot/compare/v0.
|
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
|
-
|
29
|
-
|
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
|
-
|
47
|
-
|
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
|
-
|
61
|
-
|
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
|
-
|
68
|
-
|
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
|
-
|
85
|
-
|
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
|
data/lib/switchbot/client.rb
CHANGED
@@ -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
|
data/lib/switchbot/device.rb
CHANGED
@@ -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
|
data/lib/switchbot/version.rb
CHANGED
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', '
|
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.
|
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:
|
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:
|
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:
|
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
|
-
|
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.
|
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: []
|