Class: SyncSign::Node
- Inherits:
-
Object
- Object
- SyncSign::Node
- 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
Instance Attribute Summary collapse
-
#battery ⇒ Integer
readonly
The current battery level of this node (0-100).
-
#id ⇒ String
readonly
The Node ID of this node.
-
#model ⇒ String
readonly
Model of thid node.
-
#name ⇒ String
readonly
The friendly name of this node.
-
#signal ⇒ Integer
readonly
The current signal level of this node (0-100).
Class Method Summary collapse
-
.parse(service: nil, nodeinfo: nil) ⇒ Object
private
Parse a JSON description of a single node into a
Nodeobject. -
.parse_collection(service: nil, nodeinfo: nil) ⇒ Array
private
Parse JSON array of nodes into a collection of Node objects.
Instance Method Summary collapse
-
#hub ⇒ Object
Return the hub that this node is associated with.
-
#initialize(service: nil, id: nil, name: nil, online: nil, battery: nil, signal: nil, model: nil, hubid: nil) ⇒ Node
constructor
Initialize a new Node object (normally only called from Hub#nodes or Service#nodes).
-
#is_online? ⇒ Boolean
Return true if the node was online during the last information gathering.
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
#battery ⇒ Integer (readonly)
Returns the current battery level of this node (0-100).
11 12 13 |
# File 'lib/syncsign/node.rb', line 11 def battery @battery end |
#id ⇒ String (readonly)
Returns the Node ID of this node.
7 8 9 |
# File 'lib/syncsign/node.rb', line 7 def id @id end |
#model ⇒ String (readonly)
Returns model of thid node.
15 16 17 |
# File 'lib/syncsign/node.rb', line 15 def model @model end |
#name ⇒ String (readonly)
Returns the friendly name of this node.
9 10 11 |
# File 'lib/syncsign/node.rb', line 9 def name @name end |
#signal ⇒ Integer (readonly)
Returns 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.
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
#hub ⇒ Object
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.
32 33 34 |
# File 'lib/syncsign/node.rb', line 32 def is_online? @online end |