Class: Switchbot::Device
- Inherits:
-
Object
- Object
- Switchbot::Device
- Defined in:
- lib/switchbot/device.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#device_id ⇒ Object
readonly
Returns the value of attribute device_id.
Instance Method Summary collapse
- #commands(command:, parameter: 'default', command_type: 'command') ⇒ Object
-
#initialize(client:, device_id:) ⇒ Device
constructor
A new instance of Device.
- #off ⇒ Object
- #off? ⇒ Boolean
- #on ⇒ Object
- #on? ⇒ Boolean
- #status ⇒ Object
Constructor Details
#initialize(client:, device_id:) ⇒ Device
Returns a new instance of Device.
7 8 9 10 |
# File 'lib/switchbot/device.rb', line 7 def initialize(client:, device_id:) @client = client @device_id = device_id end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/switchbot/device.rb', line 5 def client @client end |
#device_id ⇒ Object (readonly)
Returns the value of attribute device_id.
5 6 7 |
# File 'lib/switchbot/device.rb', line 5 def device_id @device_id end |
Instance Method Details
#commands(command:, parameter: 'default', command_type: 'command') ⇒ Object
16 17 18 |
# File 'lib/switchbot/device.rb', line 16 def commands(command:, parameter: 'default', command_type: 'command') client.commands(device_id: device_id, command: command, parameter: parameter, command_type: command_type) end |
#off ⇒ Object
24 25 26 |
# File 'lib/switchbot/device.rb', line 24 def off client.commands(device_id: device_id, command: 'turnOff') end |
#off? ⇒ Boolean
32 33 34 |
# File 'lib/switchbot/device.rb', line 32 def off? !on? end |
#on ⇒ Object
20 21 22 |
# File 'lib/switchbot/device.rb', line 20 def on client.commands(device_id: device_id, command: 'turnOn') end |
#on? ⇒ Boolean
28 29 30 |
# File 'lib/switchbot/device.rb', line 28 def on? status[:body][:power] == 'on' end |
#status ⇒ Object
12 13 14 |
# File 'lib/switchbot/device.rb', line 12 def status client.status(device_id: device_id) end |