Documentation ¶
Index ¶
- Constants
- Variables
- func DiffDevice(old, new types.Device) (upserted, deleted map[string]types.Component, deviceChanged bool)
- type AdapterDescription
- type AllAtOnceDiffer
- type ChannelBasedDeviceDiffer
- type DeviceDeleted
- type DeviceDiffer
- type DeviceUpdated
- type IPrioritizer
- type Prioritizer
- type SetOutputBasedDeviceDiffer
Constants ¶
const ( ControllerTypeZigbee = 1 ControllerTypeZWave = 2 ControllerTypeBluetooth = 3 ControllerTypeIPv4 = 4 ControllerTypeAggregator = 255 )
The values in this list are used to prioritize services. Lower numbers are higher priority.
Variables ¶
var Log = logging.Log.New("pkg", "lib")
Log is the logger for the lib package
Functions ¶
func DiffDevice ¶
func DiffDevice(old, new types.Device) (upserted, deleted map[string]types.Component, deviceChanged bool)
DiffDevice determines the differences between one 'old' Device and a 'new' Device, in the context that the 'new' Device is replacing the 'old' Device. It lists the components that would be upserted or deleted, and determines if the Device itself has changed.
Types ¶
type AdapterDescription ¶
type AdapterDescription struct { Type controllerType ID string }
An AdapterDescription describes an adapter for the purpose of prioritization
type AllAtOnceDiffer ¶
type AllAtOnceDiffer struct {
// contains filtered or unexported fields
}
An AllAtOnceDiffer is a DeviceDiffer that expects a caller to Consider all of it's Devices every time it is called. It compares each full device set against the most recent one - if a new Device set contains a Device that was not seen, this is considered to be a new Device. Similarly, if a new Device set does not contain a Device that was previously seen, that Device is considered to have been deleted.
func NewAllAtOnceDiffer ¶
func NewAllAtOnceDiffer() *AllAtOnceDiffer
NewAllAtOnceDiffer properly instantiates an AllAtOnceDiffer
func (*AllAtOnceDiffer) Consider ¶
func (d *AllAtOnceDiffer) Consider(devices map[types.ExternalDeviceID]types.Device)
Consider considers a new Device Set and determines if that set indicates that one or more Devices have been added, updated, or removed from the caller's service. If so, those updates are sent to a destination channel to be consumed.
func (*AllAtOnceDiffer) GetLatest ¶
func (d *AllAtOnceDiffer) GetLatest(id types.ExternalDeviceID) (types.Device, error)
GetLatest returns the latest-considered Device which matches the given types.ExternalDeviceID
func (*AllAtOnceDiffer) OutputChan ¶
func (d *AllAtOnceDiffer) OutputChan() chan interface{}
OutputChan gets the output destination channel for the AllAtOnceDiffer
func (*AllAtOnceDiffer) SetOutput ¶
func (d *AllAtOnceDiffer) SetOutput(dest chan interface{}) error
SetOutput sets the output destination channel for the AllAtOnceDiffer
type ChannelBasedDeviceDiffer ¶
type ChannelBasedDeviceDiffer interface { DeviceDiffer OutputChan() chan interface{} }
A ChannelBasedDeviceDiffer is a DeviceDiffer which returns a results channel
type DeviceDeleted ¶
type DeviceDeleted struct {
ID types.ExternalDeviceID
}
DeviceDeleted describes a single Device which has been deleted
type DeviceDiffer ¶
type DeviceDiffer interface { Consider(map[types.ExternalDeviceID]types.Device) GetLatest(types.ExternalDeviceID) (types.Device, error) }
A DeviceDiffer maintains a state of Device sets which have been considered. Each time a new Device set is considered, it determines whether or not that set indicates that one or more Devices have been added, updated, or removed from the caller's service. If so, those updates are sent to a destination channel to be consumed.
type DeviceUpdated ¶
type DeviceUpdated struct { ID types.ExternalDeviceID NewState types.Device }
DeviceUpdated describes a single Device which has been updated
type IPrioritizer ¶
type IPrioritizer interface { OutputChan() chan interface{} // Get the output channel // Consider evaluates a device update to see if it's worth passing on to // listeners. If there are higher-priority Adapters which are reporting // updates for a device, an update from a lower-priority Adapter will be // ignored. // // If the update comes from the highest-priority Adapter for the Device, // the update will be passed into the prioritizer's output channel. Consider(desc AdapterDescription, update interface{}) error // GetHighestPriorityAdapterForDevice returns the highest priority Adapter // which is reporting on the state of the Device with id 'id'. An empty string // indicates that no such Adapter was found. GetHighestPriorityAdapterForDevice(id types.ExternalDeviceID) string }
An IPrioritizer considers updates from Adapters and determines whether those updates are the highest-priority updates for a particular entity (most often, for a particular Device). If so, the update is passed on to any listeners.
type Prioritizer ¶
type Prioritizer struct {
// contains filtered or unexported fields
}
A Prioritizer considers updates from Adapters and determines whether those updates are the highest-priority updates for a particular entity (most often, for a particular Device). If so, the update is passed on to any listeners.
func NewPrioritizer ¶
func NewPrioritizer(sortFns []lessFunc) *Prioritizer
NewPrioritizer properly instantiates a Prioritizer
func (*Prioritizer) Consider ¶
func (p *Prioritizer) Consider(ad AdapterDescription, update interface{}) error
Consider evaluates a device update to see if it's worth passing on to listeners. If there are higher-priority Adapters which are reporting updates for a device, an update from a lower-priority Adapter will be ignored.
If the update comes from the highest-priority Adapter for the Device, the update will be passed into the prioritizer's output channel.
func (*Prioritizer) GetHighestPriorityAdapterForDevice ¶
func (p *Prioritizer) GetHighestPriorityAdapterForDevice(id types.ExternalDeviceID) string
GetHighestPriorityAdapterForDevice returns the highest priority Adapter which is reporting on the state of the Device with id 'id'. An empty string indicates that no such Adapter was found.
func (*Prioritizer) OutputChan ¶
func (p *Prioritizer) OutputChan() chan interface{}
OutputChan returns the output channel of this Prioritizer.
type SetOutputBasedDeviceDiffer ¶
type SetOutputBasedDeviceDiffer interface { DeviceDiffer SetOutput(dest chan interface{}) error }
A SetOutputBasedDeviceDiffer is a DeviceDiffer which can be set to output results to a given channel