github.com/simpleiot/simpleiot@v0.18.3/node/onewire-io-node.go (about)

     1  package node
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/simpleiot/simpleiot/data"
     7  )
     8  
     9  type oneWireIONode struct {
    10  	nodeID          string
    11  	description     string
    12  	id              string
    13  	units           string
    14  	value           float64
    15  	disabled        bool
    16  	errorCount      int
    17  	errorCountReset bool
    18  }
    19  
    20  func newOneWireIONode(node *data.NodeEdge) (*oneWireIONode, error) {
    21  	ret := oneWireIONode{
    22  		nodeID: node.ID,
    23  	}
    24  
    25  	var ok bool
    26  
    27  	ret.id, ok = node.Points.Text(data.PointTypeID, "")
    28  	if !ok {
    29  		return nil, errors.New("Must define onewire ID")
    30  	}
    31  
    32  	ret.description, _ = node.Points.Text(data.PointTypeDescription, "")
    33  	ret.units, _ = node.Points.Text(data.PointTypeUnits, "")
    34  
    35  	ret.value, _ = node.Points.Value(data.PointTypeValue, "")
    36  	ret.disabled, _ = node.Points.ValueBool(data.PointTypeDisabled, "")
    37  	ret.errorCount, _ = node.Points.ValueInt(data.PointTypeErrorCount, "")
    38  	ret.errorCountReset, _ = node.Points.ValueBool(data.PointTypeErrorCountReset, "")
    39  
    40  	return &ret, nil
    41  }
    42  
    43  // Changed returns true if the config of the IO has changed
    44  // FIXME, we should not need this once we get NATS wired
    45  func (io *oneWireIONode) Changed(newIO *oneWireIONode) bool {
    46  	if io.id != newIO.id ||
    47  		io.value != newIO.value ||
    48  		io.errorCountReset != newIO.errorCountReset {
    49  		return true
    50  	}
    51  
    52  	return false
    53  }