Class: Switchbot::Client
- Inherits:
-
Object
- Object
- Switchbot::Client
- Defined in:
- lib/switchbot/client.rb
Constant Summary collapse
- API_VERSION =
'v1.1'
Instance Method Summary collapse
- #bot(device_id) ⇒ Object
- #color_bulb(device_id) ⇒ Object
- #commands(device_id:, command:, parameter: 'default', command_type: 'command') ⇒ Object
- #device(device_id) ⇒ Object
- #devices ⇒ Object
- #execute(scene_id:) ⇒ Object
- #humidifier(device_id) ⇒ Object
-
#initialize(token = nil, secret = nil) ⇒ Client
constructor
A new instance of Client.
- #light(device_id) ⇒ Object
- #lock(device_id) ⇒ Object
- #plug_mini(device_id) ⇒ Object
- #scene(scene_id) ⇒ Object
- #scenes ⇒ Object
- #status(device_id:) ⇒ Object
Constructor Details
#initialize(token = nil, secret = nil) ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/switchbot/client.rb', line 7 def initialize(token = nil, secret = nil) @token = token || ENV.fetch('SWITCHBOT_API_TOKEN', '') @secret = secret || ENV.fetch('SWITCHBOT_API_SECRET', '') end |
Instance Method Details
#bot(device_id) ⇒ Object
41 42 43 |
# File 'lib/switchbot/client.rb', line 41 def bot(device_id) Bot.new(client: self, device_id: device_id) end |
#color_bulb(device_id) ⇒ Object
53 54 55 |
# File 'lib/switchbot/client.rb', line 53 def color_bulb(device_id) ColorBulb.new(client: self, device_id: device_id) end |
#commands(device_id:, command:, parameter: 'default', command_type: 'command') ⇒ Object
24 25 26 27 |
# File 'lib/switchbot/client.rb', line 24 def commands(device_id:, command:, parameter: 'default', command_type: 'command') request.post("/#{API_VERSION}/devices/#{device_id}/commands", params: { command: command, parameter: parameter, commandType: command_type }) end |
#device(device_id) ⇒ Object
16 17 18 |
# File 'lib/switchbot/client.rb', line 16 def device(device_id) Device.new(client: self, device_id: device_id) end |
#devices ⇒ Object
12 13 14 |
# File 'lib/switchbot/client.rb', line 12 def devices request.get("/#{API_VERSION}/devices") end |
#execute(scene_id:) ⇒ Object
37 38 39 |
# File 'lib/switchbot/client.rb', line 37 def execute(scene_id:) request.post("/#{API_VERSION}/scenes/#{scene_id}/execute") end |
#humidifier(device_id) ⇒ Object
49 50 51 |
# File 'lib/switchbot/client.rb', line 49 def humidifier(device_id) Humidifier.new(client: self, device_id: device_id) end |
#light(device_id) ⇒ Object
45 46 47 |
# File 'lib/switchbot/client.rb', line 45 def light(device_id) Light.new(client: self, device_id: device_id) end |
#lock(device_id) ⇒ Object
57 58 59 |
# File 'lib/switchbot/client.rb', line 57 def lock(device_id) Lock.new(client: self, device_id: device_id) end |
#plug_mini(device_id) ⇒ Object
61 62 63 |
# File 'lib/switchbot/client.rb', line 61 def plug_mini(device_id) PlugMini.new(client: self, device_id: device_id) end |
#scene(scene_id) ⇒ Object
33 34 35 |
# File 'lib/switchbot/client.rb', line 33 def scene(scene_id) Scene.new(client: self, scene_id: scene_id) end |
#scenes ⇒ Object
29 30 31 |
# File 'lib/switchbot/client.rb', line 29 def scenes request.get("/#{API_VERSION}/scenes") end |
#status(device_id:) ⇒ Object
20 21 22 |
# File 'lib/switchbot/client.rb', line 20 def status(device_id:) request.get("/#{API_VERSION}/devices/#{device_id}/status") end |