Class: LIFX::Client
- Inherits:
-
Object
- Object
- LIFX::Client
- Extended by:
- Forwardable
- Defined in:
- lib/lifx/client.rb
Overview
Client is the top level interface to the library. It mainly maps methods to the backing NetworkContext instance.
Defined Under Namespace
Classes: DiscoveryTimeout
Constant Summary collapse
- DISCOVERY_DEFAULT_TIMEOUT =
Default timeout in seconds for discovery
10
Instance Attribute Summary collapse
-
#context ⇒ NetworkContext
readonly
Refers to the client's network context.
Class Method Summary collapse
-
.lan ⇒ Client
Returns a Client set up for accessing devices on the LAN.
Instance Method Summary collapse
-
#discover ⇒ Client
This method tells the NetworkContext to look for devices asynchronously.
-
#discover!(timeout: DISCOVERY_DEFAULT_TIMEOUT, condition_interval: 0.1) {|Client| ... } ⇒ Client
This method tells the NetworkContext to look for devices, and will block until there's at least one device.
-
#flush(timeout: nil) ⇒ void
Blocks until all messages have been sent to the gateways.
-
#initialize(transport: :lan) ⇒ Client
constructor
A new instance of Client.
-
#lights ⇒ LightCollection
Lights available to the client.
-
#purge_unused_tags! ⇒ Array<String>
Purges unused tags from the system.
-
#refresh ⇒ void
Sends a request to refresh devices and tags.
-
#sync { ... } ⇒ Float
This method takes a block consisting of multiple asynchronous color or power changing targets and it will try to schedule them so they run at the same time.
-
#sync!(&block) ⇒ Float
This is the same as #sync, except it will block until the commands have been executed.
-
#tags ⇒ Array<String>
All tags visible to the client.
-
#unused_tags ⇒ Array<String>
Tags that are currently unused by known devices.
Constructor Details
#initialize(transport: :lan) ⇒ Client
Returns a new instance of Client.
30 31 32 |
# File 'lib/lifx/client.rb', line 30 def initialize(transport: :lan) @context = NetworkContext.new(transport: transport) end |
Instance Attribute Details
#context ⇒ NetworkContext (readonly)
Refers to the client's network context.
27 28 29 |
# File 'lib/lifx/client.rb', line 27 def context @context end |
Class Method Details
.lan ⇒ Client
Returns a LIFX::Client set up for accessing devices on the LAN
17 18 19 |
# File 'lib/lifx/client.rb', line 17 def lan @lan ||= new end |
Instance Method Details
#discover ⇒ Client
This method tells the NetworkContext to look for devices asynchronously.
39 40 41 |
# File 'lib/lifx/client.rb', line 39 def discover @context.discover end |
#discover!(timeout: DISCOVERY_DEFAULT_TIMEOUT, condition_interval: 0.1) {|Client| ... } ⇒ Client
This method tells the NetworkContext to look for devices, and will block until there's at least one device.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/lifx/client.rb', line 55 def discover!(timeout: DISCOVERY_DEFAULT_TIMEOUT, condition_interval: 0.1, &block) block ||= -> { self.lights.count > 0 } try_until -> { block.arity == 1 ? block.call(self) : block.call }, timeout: timeout, timeout_exception: DiscoveryTimeout, condition_interval: condition_interval do discover end self end |
#flush(timeout: nil) ⇒ void
This method returns an undefined value.
Blocks until all messages have been sent to the gateways
132 133 134 |
# File 'lib/lifx/client.rb', line 132 def flush(timeout: nil) context.flush(timeout: timeout) end |
#lights ⇒ LightCollection
Returns Lights available to the client.
104 105 106 |
# File 'lib/lifx/client.rb', line 104 def lights context.lights end |
#purge_unused_tags! ⇒ Array<String>
Purges unused tags from the system. Should only use when all devices are on the network, otherwise offline devices using their tags will not be tagged correctly.
124 125 126 |
# File 'lib/lifx/client.rb', line 124 def context. end |
#refresh ⇒ void
This method returns an undefined value.
Sends a request to refresh devices and tags.
68 69 70 |
# File 'lib/lifx/client.rb', line 68 def refresh @context.refresh end |
#sync { ... } ⇒ Float
This method is in alpha and might go away. Use tags for better group messaging.
This method takes a block consisting of multiple asynchronous color or power changing targets and it will try to schedule them so they run at the same time.
You cannot nest sync
calls, nor call synchronous methods inside a sync
block.
Due to messaging rate constraints, the amount of messages determine the delay before the commands are executed. This method also assumes all the lights have the same time.
89 90 91 |
# File 'lib/lifx/client.rb', line 89 def sync(&block) @context.sync(&block) end |
#sync!(&block) ⇒ Float
This is the same as #sync, except it will block until the commands have been executed.
96 97 98 99 100 |
# File 'lib/lifx/client.rb', line 96 def sync!(&block) sync(&block).tap do |delay| sleep(delay) end end |
#tags ⇒ Array<String>
Returns All tags visible to the client.
110 111 112 |
# File 'lib/lifx/client.rb', line 110 def context. end |
#unused_tags ⇒ Array<String>
Returns Tags that are currently unused by known devices.
116 117 118 |
# File 'lib/lifx/client.rb', line 116 def context. end |