config

package
v0.0.0-...-0565850 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2017 License: BSD-2-Clause Imports: 6 Imported by: 2

Documentation

Overview

A module to support bookmarking discovered UPnP devices.

This module is intended to solve the problem of addressing commands to a specific UPnP device, where each device is known by a user-unfriendly UUID, where network addresses are subject to change, ala DHCP, and where it is not desirable to repeat device discovery each time a command is to be sent.

Since device discovery is slow, it should only be run once in a while when DHCP leases would have expired. The discovery process writes the list of discovered devices to the list of bookmarks.

Once, when the device is installed, an association is added to the list of bookmarks, making a memorable alias, i.e. 'kitchen', point to a particular UUID.

Now whenever network addresses change disovery can be rerun, with aliases automatically pointing to the new address associated with the static UUID.

Look at sonos_test.go for examples of how this class is used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bookmark

type Bookmark struct {
	// A memorable string standing in for a UUID
	Alias string `json:"alias,omitempty"`
	// The name of the device's product, e.g. 'Sonos'
	Product string `json:"product,omitempty"`
	// The product version (e.g. "28.1-83040 (BR100)")
	ProductVersion string `json:"productVersion,omitempty"`
	// The last know location of the device
	Location ssdp.Location `json:"location,omitempty"`
	// The device's UUID
	UUID ssdp.UUID `json:"uuid"`
}

A strucutre that holds all of the fields required to build a UPnP device without first trying to discover it.

type Bookmarks

type Bookmarks map[string]Bookmark

A map holding a set of bookmarks, where the key is alternately the UUID of the device, or an alias to a device.

type Config

type Config struct {

	// A set of discovered devices
	Bookmarks Bookmarks
	// contains filtered or unexported fields
}

A container for the runtime configuration used by go-sonos application.

func MakeConfig

func MakeConfig(dir string) *Config

Create a configuration object where @dir is the path to the configuration directory. Note that Init() must be called in order to use the newly created object.

func (*Config) AddAlias

func (this *Config) AddAlias(uuid ssdp.UUID, alias string)

Add @alias as an alias for @uuid.

func (*Config) AddBookmark

func (this *Config) AddBookmark(ident, product, productVersion string, location ssdp.Location, uuid ssdp.UUID)

Add a bookmark to the bookmark set where @ident is either the uuid or the alias to add; @product is the product string, such as 'Sonos'; @localtion is the network location of the resource; and @uuid is the device's UUID. When adding a device @ident and @uuid should be the same; when adding an alias @ident and @uuid will be different.

func (*Config) ClearAlias

func (this *Config) ClearAlias(alias string)

Remove any association of a device to the alias @alias. If @alias is a UUID this method is a noop.

func (*Config) ClearAliases

func (this *Config) ClearAliases()

Remove all aliases from the set of bookmarks.

func (*Config) Init

func (this *Config) Init()

Initialize the configuration object by loading any existing configuration from disk. This method creates the configuration directory, if needed.

func (*Config) Lookup

func (this *Config) Lookup(ident string) ssdp.Device

Try to find the device associated with the UUID or alias @ident. Returns nil if there is no device associated with @ident.

func (*Config) Save

func (this *Config) Save()

Write the current configuration to disk.

Jump to

Keyboard shortcuts

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