util

package
v0.0.0-...-fe5e139 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSaveable = errors.New("Database is not saveable")
	ErrNotLoadable = errors.New("Database is not loadable")
)
View Source
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 AddLinks(device devices.Linkable, addLinks ...insteon.LinkRecord) (err error)

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(group insteon.Group, d1, d2 devices.Linkable) error

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

func CrossLinkAll(group insteon.Group, devices ...devices.Linkable) (err error)

CrossLinkAll will create bi-directional links among all the devices listed. This is useful for creating virtual N-Way connections

func DumpLinkDatabase

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)

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(group insteon.Group, controller, responder devices.Linkable) error

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(group insteon.Group, controller, responder devices.Linkable) (err error)

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

func LoadDB(filename string, db Database) (err error)

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(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 PrintLinkDatabase

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

func SaveDB(filename string, db Database) (err error)

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 Snoop

func Snoop(out io.Writer, db Database) devices.Filter
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

func Unlink(group insteon.Group, controller, responder devices.Linkable) error

Unlink will unlink a controller from a responder for a given Group. The controller is put into UnlinkingMode (analogous to unlinking mode via the set button) and then the responder is put into unlinking mode (also analogous to the set button pressed)

func UnlinkAll

func UnlinkAll(controller, responder devices.Linkable) error

UnlinkAll will unlink all groups between a controller and a responder device

Types

type Addresses

type Addresses []insteon.Address

func (*Addresses) Get

func (a *Addresses) Get() interface{}

func (*Addresses) Set

func (a *Addresses) Set(str []string) error

func (*Addresses) String

func (a *Addresses) String() string

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

func NewFileDB

func NewFileDB(filename string) (Database, error)
type Links []insteon.LinkRecord

func (Links) Len

func (l Links) Len() int

func (Links) Less

func (l Links) Less(i, j int) bool

func (Links) Swap

func (l Links) Swap(i, j int)

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

func NewMemDB

func NewMemDB() Saveable

NewMemDB returns a memory-backed database

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL