Documentation ¶
Index ¶
- Variables
- func AddLinks(device devices.Linkable, addLinks ...insteon.LinkRecord) (err error)
- func Anonymize(links []insteon.LinkRecord, replacements ...insteon.Address) []insteon.LinkRecord
- func CrossLink(group insteon.Group, d1, d2 devices.Linkable) error
- func CrossLinkAll(group insteon.Group, devices ...devices.Linkable) (err error)
- func DumpLinkDatabase(out io.Writer, linkable devices.Linkable) error
- func DumpLinks(out io.Writer, links []insteon.LinkRecord) error
- func FindDuplicateLinks(linkable devices.Linkable, equal func(l1, l2 insteon.LinkRecord) bool) ([]insteon.LinkRecord, error)
- func FindLinkRecord(device devices.Linkable, controller bool, address insteon.Address, ...) (found insteon.LinkRecord, err error)
- func ForceLink(group insteon.Group, controller, responder devices.Linkable) error
- func Link(group insteon.Group, controller, responder devices.Linkable) (err error)
- func LinksToText(links []insteon.LinkRecord, printHeading bool) string
- func LoadDB(filename string, db Database) (err error)
- func MissingCrosslinks(links []insteon.LinkRecord, forAddresses ...insteon.Address) []insteon.LinkRecord
- func PrintLinkDatabase(out io.Writer, linkable devices.Linkable) error
- func PrintLinks(out io.Writer, links []insteon.LinkRecord) error
- func RemoveLinks(device devices.Linkable, remove ...insteon.LinkRecord) error
- func SaveDB(filename string, db Database) (err error)
- func Snoop(out io.Writer, db Database) devices.Filter
- func TextToLinks(input string) (links []insteon.LinkRecord, err error)
- func Unlink(group insteon.Group, controller, responder devices.Linkable) error
- func UnlinkAll(controller, responder devices.Linkable) error
- type Addresses
- type Database
- type Links
- type Loadable
- type Saveable
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotSaveable = errors.New("Database is not saveable") ErrNotLoadable = errors.New("Database is not loadable") )
var ( // ErrAlreadyLinked is returned when creating a link and an existing matching link is found ErrAlreadyLinked = errors.New("Responder already linked to controller") // ErrLinkNotFound is returned by the Find function when no matching record was found ErrLinkNotFound = errors.New("Link was not found in the database") )
Functions ¶
func Anonymize ¶
func Anonymize(links []insteon.LinkRecord, replacements ...insteon.Address) []insteon.LinkRecord
Anonymize returns a copy of the links where each link Address field has been replaced, in order, by the given replacement addresses. If fewer replacement addresses are supplied than required, a random address is generated using rand.Int31()
Links that have the same addresses in their Address field will all have the same substituted Address
func CrossLink ¶
CrossLink will create bi-directional links between the two linkable devices. Each device will get both a controller and responder link for the given group. When using lighting control devices, this will effectively create a 3-Way light switch configuration
func CrossLinkAll ¶
CrossLinkAll will create bi-directional links among all the devices listed. This is useful for creating virtual N-Way connections
func FindDuplicateLinks ¶
func FindDuplicateLinks(linkable devices.Linkable, equal func(l1, l2 insteon.LinkRecord) bool) ([]insteon.LinkRecord, error)
FindDuplicateLinks will perform a linear search of the LinkDB and return any links that are duplicates. Comparison is done with the provided equal function. If the equal function returns true, then the two links are considered duplicated
func FindLinkRecord ¶
func FindLinkRecord(device devices.Linkable, controller bool, address insteon.Address, group insteon.Group) (found insteon.LinkRecord, err error)
FindLinkRecord will perform a linear search of the database and return a LinkRecord that matches the group, address and controller/responder indicator
func ForceLink ¶
ForceLink will create links in the controller and responder All-Link databases without first checking if the links exist. The links are created by simulating set button presses (using EnterLinkingMode)
func Link ¶
Link will add appropriate entries to the controller's and responder's All-Link database. Each devices' ALDB will be searched for existing links, if both entries exist (a controller link and a responder link) then nothing is done. If only one entry exists than the other is deleted and new links are created. Once the link check/cleanup has taken place the new links are created using ForceLink
func LinksToText ¶
func LinksToText(links []insteon.LinkRecord, printHeading bool) string
LinksToText will take a list of links and marshal them to text for editing
func LoadDB ¶
LoadDB will attempt to load db from the named file. If db does not implement the Loadable interface, then nothing is done and ErrNotLoadable is returned
func MissingCrosslinks ¶
func MissingCrosslinks(links []insteon.LinkRecord, forAddresses ...insteon.Address) []insteon.LinkRecord
MissingCrosslinks loops through the links and looks for controller and responder records for each of the addresses if either a controller or responder link is missing in the input list, then it is added to the slice of "missing" records returned
func PrintLinks ¶
func PrintLinks(out io.Writer, links []insteon.LinkRecord) error
func RemoveLinks ¶
func RemoveLinks(device devices.Linkable, remove ...insteon.LinkRecord) error
func SaveDB ¶
SaveDB will attempt to save the database to the named file. If the database is not saveable (does not implement the Saveable interface) then ErrNotSaveable is returned
func TextToLinks ¶
func TextToLinks(input string) (links []insteon.LinkRecord, err error)
TextToLinks will take an input string and parse it into a list of link records. This is useful for manually editing link databases
Types ¶
type Database ¶
type Database interface { // Get will look up the Address in the database and return the // matching DeviceInfo object. If no entry is found, then // found returns false Get(addr insteon.Address) (info devices.DeviceInfo, found bool) // Put will store the DeviceInfo object in the Database overwriting // any existing object Put(info devices.DeviceInfo) error // Filter will return a list of addresses that match the // given device categories Filter(domains ...insteon.Domain) []insteon.Address // Open will look for the device info in the database and return // an initialized device if found. If not found, Open will call // insteon.Open and store the info upon success. If dbfile is // not an empty string, SaveDB will be called at the end Open(mw devices.MessageWriter, addr insteon.Address, filters ...devices.Filter) (*devices.BasicDevice, error) }
Database is the interface representing a collection of Insteon devices. This provides a way to collect and store data about linked devices thus reducing the need to perform common first time queries (namely EngineVersion request and ID Request) every time you want to interact with an Insteon network. EngineVersion requests and ID Requests can actually take longer than the intended direct message (such as turning on a light) therefore using a database for a long running process that interacts with many devices can significantly reduce Insteon network load
type Links ¶
type Links []insteon.LinkRecord
type Loadable ¶
type Loadable interface { // Load will replace the current database content with that // provided from the io.Reader Load(io.Reader) error }
Loadable is any database that can be loaded from an io.Reader
type Saveable ¶
type Saveable interface { Database // Save will write the current database state to the given writer Save(io.Writer) error // NeedsSaving indicates whether the database has changed since the // last save NeedsSaving() bool }
Saveable is any database that can be written to an io.Writer