Class: SyncSign::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/syncsign/node.rb

Overview

Object that represents a SyncSign node. TODO: Split this up and add support for non-display nodes.

Direct Known Subclasses

Display

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service: nil, id: nil, name: nil, online: nil, battery: nil, signal: nil, model: nil, hubid: nil) ⇒ Node

Initialize a new Node object (normally only called from Hub#nodes or Service#nodes).



19
20
21
22
23
24
25
26
27
28
# File 'lib/syncsign/node.rb', line 19

def initialize(service: nil, id: nil, name: nil, online: nil, battery: nil, signal: nil, model: nil, hubid: nil)
  @service = service
  @id = id
  @name = name
  @online = online
  @battery = battery
  @signal = signal
  @model = model
  @hubid = hubid
end

Instance Attribute Details

#batteryInteger (readonly)

Returns the current battery level of this node (0-100).

Returns:

  • (Integer)

    the current battery level of this node (0-100)



11
12
13
# File 'lib/syncsign/node.rb', line 11

def battery
  @battery
end

#idString (readonly)

Returns the Node ID of this node.

Returns:

  • (String)

    the Node ID of this node.



7
8
9
# File 'lib/syncsign/node.rb', line 7

def id
  @id
end

#modelString (readonly)

Returns model of thid node.

Returns:

  • (String)

    model of thid node.



15
16
17
# File 'lib/syncsign/node.rb', line 15

def model
  @model
end

#nameString (readonly)

Returns the friendly name of this node.

Returns:

  • (String)

    the friendly name of this node.



9
10
11
# File 'lib/syncsign/node.rb', line 9

def name
  @name
end

#signalInteger (readonly)

Returns the current signal level of this node (0-100).

Returns:

  • (Integer)

    the current signal level of this node (0-100)



13
14
15
# File 'lib/syncsign/node.rb', line 13

def signal
  @signal
end

Class Method Details

.parse(service: nil, nodeinfo: nil) ⇒ 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.

Parse a JSON description of a single node into a Node object. Normally only called from Hub#nodes or Service#nodes.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/syncsign/node.rb', line 46

def self.parse(service: nil, nodeinfo: nil)
  node_class = Node
  case nodeinfo['type']
    when 'DISPLAY'
      node_class = Display
    # TODO: support sensors and any other node types
  end
  node_class.new(
    service: service,
    id: nodeinfo['nodeId'],
    name: nodeinfo['name'],
    online: nodeinfo['onlined'],
    battery: nodeinfo['batteryLevel'],
    signal: nodeinfo['signalLevel'],
    model: nodeinfo['model'],
    hubid: nodeinfo['thingName']
  )
end

.parse_collection(service: nil, nodeinfo: nil) ⇒ Array

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.

Parse JSON array of nodes into a collection of Node objects.

Parameters:

  • service (SyncSign::Service) (defaults to: nil)

    Instance of the SyncSign Service class.

  • nodeinfo (String) (defaults to: nil)

    Information about a collection of nodes, in JSON format.

Returns:

  • (Array)

    Array of Node objects.



72
73
74
75
76
77
78
79
# File 'lib/syncsign/node.rb', line 72

def self.parse_collection(service: nil, nodeinfo: nil)
  nodes = []
  nodeinfo.each do |node|
    nodes.push Node::parse(service: service, nodeinfo: node)
  end
p nodes
  nodes
end

Instance Method Details

#hubObject

Return the hub that this node is associated with



38
39
40
# File 'lib/syncsign/node.rb', line 38

def hub
  Hub.new(service: @service, sn: @hubid)
end

#is_online?Boolean

Return true if the node was online during the last information gathering.

Returns:

  • (Boolean)


32
33
34
# File 'lib/syncsign/node.rb', line 32

def is_online?
  @online
end