Class: LIFX::Site Private

Inherits:
Object
  • Object
show all
Includes:
Seen
Defined in:
lib/lifx/site.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Seen

#last_seen, #seconds_since_seen

Constructor Details

#initialize(id:) ⇒ Site

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Site.



16
17
18
19
20
21
22
23
# File 'lib/lifx/site.rb', line 16

def initialize(id:)
  @id            = id
  @gateways      = {}
  @gateways_mutex = Mutex.new
  @threads       = []
  @threads << initialize_timer_thread
  initialize_stale_gateway_check
end

Instance Attribute Details

#gatewaysObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
# File 'lib/lifx/site.rb', line 14

def gateways
  @gateways
end

#idObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
# File 'lib/lifx/site.rb', line 14

def id
  @id
end

#tag_managerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
# File 'lib/lifx/site.rb', line 14

def tag_manager
  @tag_manager
end

Instance Method Details

#flush(**options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
51
52
53
54
# File 'lib/lifx/site.rb', line 48

def flush(**options)
  @gateways.values.map do |gateway|
    Thread.new do
      gateway.flush(**options)
    end
  end.each(&:join)
end

#handle_message(message, ip, transport) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lifx/site.rb', line 32

def handle_message(message, ip, transport)
  logger.debug("<- #{self} #{transport}: #{message}")
  payload = message.payload
  case payload
  when Protocol::Device::StatePanGateway
    @gateways_mutex.synchronize do
      @gateways[message.device_id] ||= GatewayConnection.new
      @gateways[message.device_id].handle_message(message, ip, transport)
      @gateways[message.device_id].add_observer(self) do |**args|
        notify_observers(**args)
      end
    end
  end
  seen!
end

#stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



61
62
63
64
65
66
67
68
# File 'lib/lifx/site.rb', line 61

def stop
  @threads.each do |thread|
    Thread.kill(thread)
  end
  @gateways.values.each do |gateway|
    gateway.close
  end
end

#to_sObject Also known as: inspect

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
# File 'lib/lifx/site.rb', line 56

def to_s
  %Q{#<LIFX::Site id=#{id}>}
end

#write(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
29
30
# File 'lib/lifx/site.rb', line 25

def write(message)
  message.path.site_id = id
  @gateways.values.each do |gateway|
    gateway.write(message)
  end
end