gohome

package
v0.0.0-...-0896cb3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2020 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DTDimmer - dimmer
	DTDimmer DeviceType = "dimmer"

	// DTSwitch - switch
	DTSwitch = "switch"

	// DTShade - shade
	DTShade = "shade"

	// DTHub - hub
	DTHub = "hub"

	// DTRemote - remote control
	DTRemote = "remote"

	// DTUnknown - unknown device type
	DTUnknown = "unknown"
)

TODO: Needed?

View Source
const (
	// TimeTriggerModeSunrise - the time trigger is relative to sunrise
	TimeTriggerModeSunrise string = "sunrise"

	// TimeTriggerModeSunset - the time trigger is relative to sunset
	TimeTriggerModeSunset string = "sunset"

	// TimeTriggerModeExact - the time trigger is an exact time
	TimeTriggerModeExact string = "exact"
)
View Source
const (
	TimeTriggerDaysSun   uint32 = 1
	TimeTriggerDaysMon   uint32 = 2
	TimeTriggerDaysTues  uint32 = 4
	TimeTriggerDaysWed   uint32 = 8
	TimeTriggerDaysThurs uint32 = 16
	TimeTriggerDaysFri   uint32 = 32
	TimeTriggerDaysSat   uint32 = 64
)
View Source
const MonitorContext = "__MONITOR__"

Variables

This section is empty.

Functions

func LoadAutomation

func LoadAutomation(sys automationSys, path string) (map[string]*Automation, error)

LoadAutomation loads all of the automation files from the specified path

func SupressFeatureReporting

func SupressFeatureReporting(sys *System, featureID string, attrs map[string]*attr.Attribute, delay time.Duration)

SupressFeatureReporting will stop all FeatureReportingEvt events from being enqueued on the system event bus, if they are for the feature that matches the specified featureID. The filter will be automatically removed after the specified delay. The reason you may want to call this (see extensions/honeywell/cmd_builder.go) is that for some hardware after you set a new state if you query it for the current state you will get the old state not the new state for some period of time. If the extension is polling the hardware for current values and we set new values but then report old values, the UI will jump back to an incorrect state. So after setting new values, you can call this function with a delay and all updates from the extension will be ignored for that time period.

Types

type Area

type Area struct {
	ID          string
	Name        string
	Description string
	Areas       []*Area
	Parent      *Area
	Features    []*feature.Feature
}

Area represents a physical space e.g. Bathroom, garden etc

func (*Area) AddArea

func (a *Area) AddArea(area *Area)

func (*Area) AddFeature

func (a *Area) AddFeature(f *feature.Feature)

type Auth

type Auth struct {
	Login    string
	Password string
	Token    string
}

Auth contains authentication information such as login/password/security token

type Automation

type Automation struct {
	Name    string
	TempID  string
	Enabled bool
	Trigger Trigger
	evtbus.Consumer
	Triggered func(actions *CommandGroup)
}

Automation represents an automation instance. Each piece of automation has a trigger which is a set of conditions which when evaluating to true cause the automation actions to execute

func NewAutomation

func NewAutomation(sys automationSys, config string) (*Automation, error)

NewAutomation creates a new automation instance

func (*Automation) ConsumerName

func (a *Automation) ConsumerName() string

func (*Automation) StartConsuming

func (a *Automation) StartConsuming(ch chan evtbus.Event)

func (*Automation) StopConsuming

func (a *Automation) StopConsuming()

type AutomationTriggeredEvt

type AutomationTriggeredEvt struct {
	Name string
}

AutomationTriggeredEvt is fired when a piece of automation is triggered

func (*AutomationTriggeredEvt) String

func (e *AutomationTriggeredEvt) String() string

String returns a debug string

type ChangeBatch

type ChangeBatch struct {
	MonitorID string
	Features  map[string]map[string]*attr.Attribute
}

ChangeBatch contains a list of features whos values have changed

func (*ChangeBatch) String

func (cb *ChangeBatch) String() string

type ClientConnectedEvt

type ClientConnectedEvt struct {
	ConnectionID string `json:"connectionId"`
	MonitorID    string `json:"-"`
	Origin       string `json:"origin"`
}

ClientConnectedEvt is raised when a client registers to get updates for zone and sensor values

func (*ClientConnectedEvt) String

func (cc *ClientConnectedEvt) String() string

String returns a debug string

type ClientDisconnectedEvt

type ClientDisconnectedEvt struct {
	ConnectionID string `json:"connectionId"`
}

ClientDisconnectedEvt is raised when a client connection is closed

func (*ClientDisconnectedEvt) String

func (cc *ClientDisconnectedEvt) String() string

String returns a debug string

type CommandBuilder

type CommandBuilder interface {
	Build(cmd.Command) (*cmd.Func, error)
}

CommandBuilder know how to take an abstract command like ZoneSetLevel and turn it in to a device specific set of instructions, for a specific piee of hardware

type CommandGroup

type CommandGroup struct {
	Desc string
	Cmds []cmd.Command
}

CommandGroup contains a collection of commands that need to be run sequentially

func NewCommandGroup

func NewCommandGroup(desc string, cmds ...cmd.Command) CommandGroup

NewCommandGroup returns a CommandGroup instance with the Desc and Cmds field set

type CommandProcessor

type CommandProcessor interface {
	Start()
	Stop()
	Enqueue(CommandGroup) error
}

CommandProcessor represents an interface to a type that knows how to process commands

func NewCommandProcessor

func NewCommandProcessor(system *System, maxWorkers, queueSize int) CommandProcessor

NewCommandProcessor returns an initialized type that implements the CommandProcessor interface

type Config

type Config struct {
	// SystemPath is a path to the json file containing all of the system information
	SystemPath string `json:"systemPath"`

	// EventLogPath is the path where the event log will be written
	EventLogPath string `json:"eventLogPath"`

	// AutomationPath is the path where all the automation files live
	AutomationPath string `json:"automationPath"`

	// WebUIPath is the path to the dist folder in the goHOME source code, where the web UI lives
	WebUIPath string `json:"webUIPath"`

	// WWWAddr is the IP address for the WWW server
	WWWAddr string `json:"wwwAddr"`

	// WWWPort is the port for the WWW server
	WWWPort string `json:"wwwPort"`

	// UPNPNotifyAddr is the IP of the UPNP Notify server
	UPNPNotifyAddr string `json:"upnpNotifyAddr"`

	// UPNPNotifyPort is the port of the UPNP Notify server
	UPNPNotifyPort string `json:"upnpNotifyPort"`

	// Location specifies the lat/long where the home is physically located. This is needed
	// if you want to get accurate sunrise/sunset times
	Location location `json:"location"`
}

func NewDefaultConfig

func NewDefaultConfig(systemPath, webUIPath string) *Config

defaultConfig returns a default Config option with all the values populated to some default values

func (*Config) Merge

func (c *Config) Merge(cfg Config)

type Device

type Device struct {
	// ID a unique system wide ID, this is set when the device is added to the system
	// don't set this manually unless you know what you are doing
	ID string

	// Address can be whatever type of address is needed for the device e.g.
	// an IP address 192.168.0.9:23 or some value that is custom to whatever
	// system we have imported
	Address string

	// Name is a friendly name for the device, it will be shown in the UI
	Name string

	// Description provides more detailed information about the device
	Description string

	// Type describes what type of device this is e.g. Hub, Switch, Shade etc
	Type DeviceType

	// ModelName
	ModelName string

	// Modelnumber
	ModelNumber string

	// SoftwareVersion can store what version of software is installed on the device
	SoftwareVersion string

	// Features is a slice of features the device owns and exports
	// TODO: Hide behind getter/setter, mutex
	Features []*feature.Feature

	// CmdBuilder knows how to take an abstract command like ZoneSetLevel and turn
	// it in to specific commands for this particular piece of hardware.
	CmdBuilder cmd.Builder

	// Connections is optional, if the device needs a connection pool to communicate.
	Connections *pool.ConnectionPool

	// Auth - if authentication information is required to access the device, it is stored here
	Auth *Auth

	// Hub is the device that should be communicated with to talk to this device.  For example
	// you may have a keypad device, you don't talk directly to that but to some hub which
	// has a network address that then knows how to talk to the keypad.  Calling Hub will give
	// you that device.
	// TODO: Rename? Router/Gateway
	Hub *Device
}

Device is a piece of hardware. It could be a dimmer, a shade, a remote etc

func NewDevice

func NewDevice(
	ID,
	name,
	description,
	modelNumber,
	modelName,
	softwareVersion,
	address string,
	hub *Device,
	cmdBuilder cmd.Builder,
	connPool *pool.ConnectionPool,
	auth *Auth) *Device

NewDevice returns an initialized device object

func (*Device) AddFeature

func (d *Device) AddFeature(f *feature.Feature) error

func (*Device) ButtonByAddress

func (d *Device) ButtonByAddress(addr string) *feature.Feature

ButtonByAddress returns the button feature which has the matching address, nil if no matching button is found

func (*Device) FeatureTypeByAddress

func (d *Device) FeatureTypeByAddress(t string, addr string) *feature.Feature

FeatureByAddress returns the first feature that matches the specified address nil if no match is found

func (*Device) IsDupeFeature

func (d *Device) IsDupeFeature(f *feature.Feature) bool

IsDupeFeature returns true if this is considered a duplicates feature, otherwise false. Features are considered equal, if they have the same type and address.

func (*Device) OwnedFeatures

func (d *Device) OwnedFeatures(featureIDs map[string]bool) []*feature.Feature

OwnedFeature returns a slice of features that the device owns, where the map is keyed by feature.ID

func (*Device) String

func (d *Device) String() string

String returns a friendly string describing the device that can be useful for debugging

func (*Device) Validate

func (d *Device) Validate() *validation.Errors

Validate checks that all of the requirements for this to be a valid device are met

type DeviceLostEvt

type DeviceLostEvt struct {
	DeviceName string
	DeviceID   string
}

DeviceLostEvt indicates that connection to a device has been lost

func (*DeviceLostEvt) String

func (dl *DeviceLostEvt) String() string

String returns a debug string

type DeviceProducingEvt

type DeviceProducingEvt struct {
	Device *Device
}

DeviceProducingEvt is raised when a device starts producing events in the system

func (*DeviceProducingEvt) String

func (dp *DeviceProducingEvt) String() string

String returns a debug string

type DeviceType

type DeviceType string

DeviceType explains the type of a device e.g. Dimmer or Shade

type Discoverer

type Discoverer interface {
	Info() DiscovererInfo
	ScanDevices(*System, map[string]string) (*DiscoveryResults, error)
}

Discoverer represents an interface for types that can discover devices on the network or from a config file string.

type DiscovererInfo

type DiscovererInfo struct {
	// ID a unique ID for the discoverer, extension should put a prefix like "extensionname.hardware.version"
	// etc. as the ID, make it as unique as possible so it won't clash with other Discoverer IDs in other extensions
	ID string

	// Name is a friendly name for the Discoverer, it will be shown in the UI
	Name string

	// Description should contain more info about the discoverer, that wasn't shown in the UI e.g. maybe it
	// explains the discoverer only supports v1.0 of some hardware.
	Description string

	// UIFields is a list of fields that will be displayed to the user before the scan
	// begins, these can be used to get extra information from the user if necessary. For example
	// some system may export a config file but not include the IP address of the device in the
	// export so you can add a UI field to get the user to enter the IP address
	UIFields []UIField

	// PreScanInfo is a string that will be shown to the user before
	// scanning for devices. An example might be some text saying:
	// "Press the sync button on the hub before scanning" - it can be
	// instructions the user should perform before scanning.
	PreScanInfo string
}

DiscovererInfo represents information about a Discoverer instance. Extensions might export multiple Discoverers that know how to find devices on a network or create devices from config strings

type Discovery

type Discovery interface {
	Discoverers() []DiscovererInfo
	DiscovererFromID(ID string) Discoverer
}

Discovery is the interface exposed by an extension if it supports discovering devices on a netowkr or can create devices from a config file

type DiscoveryResults

type DiscoveryResults struct {
	Devices []*Device
	Scenes  []*Scene
}

DiscoveryResults contains all of the devices found by the discoverer instance

type EventLogger

type EventLogger struct {
	// Path the directory and file name where the log will be saved
	Path string

	// Verbose if set to true outputs more noisy events to the event log
	Verbose bool
}

EventLogger consumes events from the event bus and outputs them to the event log

func (*EventLogger) ConsumerName

func (c *EventLogger) ConsumerName() string

func (*EventLogger) StartConsuming

func (c *EventLogger) StartConsuming(ch chan evtbus.Event)

func (*EventLogger) StopConsuming

func (c *EventLogger) StopConsuming()

type ExtEvents

type ExtEvents struct {
	Consumer evtbus.Consumer
	Producer evtbus.Producer
}

ExtEvent is a struct that contains a producer and consumer, if the extension exports those types

type Extension

type Extension interface {

	// Name returns a friendly name for the extension
	Name() string

	// BuilderForDevice should return a cmd.Builder if the extension exports a builder
	// for the device that was passed in to the function, nil otherwise
	BuilderForDevice(*System, *Device) cmd.Builder

	// NetworkForDevice should return a gohome.Network if the extension exports a Network interface
	// for the device that was passed in to the function, nil otherwise
	NetworkForDevice(*System, *Device) Network

	// EventsForDevice should return a gohome.ExtEvents instance if the extension supports
	// producing and consuming events for the device passed in to the function
	EventsForDevice(sys *System, d *Device) *ExtEvents

	// Discovery returns a gohome.Discovery instance if the extension can scan for devices
	// on the local network or can create devices from a config file, nil otherwise
	Discovery(sys *System) Discovery
}

Extension represents the interface any extension has to implement in order to be added to the system

type Extensions

type Extensions struct {
	// contains filtered or unexported fields
}

Extensions contains references to all of the loaded extensions in a system

func NewExtensions

func NewExtensions() *Extensions

NewExtensions inits and returns a new Extensions instance

func (*Extensions) FindCmdBuilder

func (e *Extensions) FindCmdBuilder(sys *System, d *Device) cmd.Builder

FindCmdBuilder returns a cmd.Builder instance if there is any extension that exports one for the device passed in to the function

func (*Extensions) FindDiscovererFromID

func (e *Extensions) FindDiscovererFromID(sys *System, ID string) Discoverer

FindDiscovererFromID returns a Discoverer instance matching the specified ID

func (*Extensions) FindEvents

func (e *Extensions) FindEvents(sys *System, d *Device) *ExtEvents

FindEvents returns a gohome.ExtEvents instance if there is any extension that supports producing events for the device

func (*Extensions) FindNetwork

func (e *Extensions) FindNetwork(sys *System, d *Device) Network

FindNetwork returns a gohome.Network instance if there is any extension that exports one for the device passed in to the function

func (*Extensions) ListDiscoverers

func (e *Extensions) ListDiscoverers(sys *System) []DiscovererInfo

ListDiscoverers returns a slice containing all of the Discoverers registered with all of the extensions in the system

func (*Extensions) Register

func (e *Extensions) Register(ext Extension)

Register adds a new extension to the Extensions instance

type FeatureAttrsChangedEvt

type FeatureAttrsChangedEvt struct {
	FeatureID string
	Context   string
	Attrs     map[string]*attr.Attribute
}

FeatureAttrsChangedEvt is fired when the system determines an attribute of a feature has changed value. Note this is not always reflective of the actual hardware in that when the system first starts and has no initial value, this will fire even if the value didn't change on the hardware intially

func (*FeatureAttrsChangedEvt) String

func (e *FeatureAttrsChangedEvt) String() string

String returns a debug string

type FeatureReportingEvt

type FeatureReportingEvt struct {
	FeatureID string
	Attrs     map[string]*attr.Attribute
}

FeatureReportingEvt is fired when a devices feature(s) responds to a FeaturesReportEvt for the current state of the device features

func (*FeatureReportingEvt) String

func (e *FeatureReportingEvt) String() string

String returns a debug string

type FeatureTrigger

type FeatureTrigger struct {
	Condition *condition
	Triggered func()

	// Count the number of times the trigger must evaluate to true before triggering
	Count int

	// Duration the maximum amount of time allowed for the trigger to reach the Count amount. If the
	// count amount is notreached in this time the time is reset e.g. you may say get 3 events within
	// 3000 milliseconds
	Duration time.Duration
	// contains filtered or unexported fields
}

FeatureTrigger is a trigger that can be used to fire based on a features attributes changing

func (*FeatureTrigger) ConsumerName

func (e *FeatureTrigger) ConsumerName() string

func (*FeatureTrigger) StartConsuming

func (e *FeatureTrigger) StartConsuming(ch chan evtbus.Event)

func (*FeatureTrigger) StopConsuming

func (e *FeatureTrigger) StopConsuming()

func (*FeatureTrigger) Trigger

func (e *FeatureTrigger) Trigger()

type FeaturesReportEvt

type FeaturesReportEvt struct {
	FeatureIDs map[string]bool
}

FeaturesReportEvt is fired when the system wants certain features to report their current values

func (*FeaturesReportEvt) Add

func (e *FeaturesReportEvt) Add(featureID string)

Add adds a feature to the request list

func (*FeaturesReportEvt) String

func (e *FeaturesReportEvt) String() string

String returns a debug string

type Monitor

type Monitor struct {
	// contains filtered or unexported fields
}

Monitor keeps track of the current feature attribute values in the system and reports updates to clients

func NewMonitor

func NewMonitor(sys *System, evtBus *evtbus.Bus) *Monitor

NewMonitor returns an initialzed Monitor instance

func (*Monitor) ConsumerName

func (m *Monitor) ConsumerName() string

func (*Monitor) Group

func (m *Monitor) Group(monitorID string) (*MonitorGroup, bool)

Group returns the group for the specified ID if one exists

func (*Monitor) InvalidateValues

func (m *Monitor) InvalidateValues(monitorID string)

InvalidateValues removes any cached values, for any features listed in the monitor group

func (*Monitor) ProducerName

func (m *Monitor) ProducerName() string

======== evtbus.Producer interface TODO: Remove?

func (*Monitor) Refresh

func (m *Monitor) Refresh(monitorID string, force bool)

Refresh causes the monitor to report the current values for any item in the monitor group, specified by the monitorID parameter. If force is true then the current cached values stored in the monitor are ignored and new values are requested

func (*Monitor) StartConsuming

func (m *Monitor) StartConsuming(c chan evtbus.Event)

func (*Monitor) StartProducing

func (m *Monitor) StartProducing(evtBus *evtbus.Bus)

func (*Monitor) StopConsuming

func (m *Monitor) StopConsuming()

func (*Monitor) StopProducing

func (m *Monitor) StopProducing()

func (*Monitor) Subscribe

func (m *Monitor) Subscribe(g *MonitorGroup, refresh bool) (string, error)

Subscribe requests that the monitor keep track of updates for all of the features listed in the MonitorGroup parameter. If refresh == true, the monitor will go and request values for all items in the monitor group, if false it won't until the caller calls the Subscribe method. The function returns a monitorID value that can be passed into other functions, such as Unsubscribe and Refresh.

func (*Monitor) SubscribeRenew

func (m *Monitor) SubscribeRenew(monitorID string) error

SubscribeRenew updates the timeout parameter for the group to increment to now() + timeout where timeout was specified in the initial call to Subscribe

func (*Monitor) Unsubscribe

func (m *Monitor) Unsubscribe(monitorID string)

Unsubscribe removes all references and updates for the specified monitorID

type MonitorDelegate

type MonitorDelegate interface {
	Update(b *ChangeBatch)
	Expired(monitorID string)
}

MonitorDelegate is the interface for receiving updates values from the monitor

type MonitorGroup

type MonitorGroup struct {
	//TODO: change name to FeatureIDs
	Features map[string]bool
	Handler  MonitorDelegate
	Timeout  time.Duration
	// contains filtered or unexported fields
}

MonitorGroup represents a group of features a client wished to receive updates for.

func (*MonitorGroup) String

func (mg *MonitorGroup) String() string

type Network

type Network interface {
	NewConnection(sys *System, d *Device) (func(pool.Config) (net.Conn, error), error)
}

Network is an interface that must be exported by an extension that provides network related functionality pertaining to the extensions hardware

type NullExtension

type NullExtension struct{}

func (*NullExtension) BuilderForDevice

func (e *NullExtension) BuilderForDevice(sys *System, d *Device) cmd.Builder

func (*NullExtension) Discovery

func (e *NullExtension) Discovery(sys *System) Discovery

func (*NullExtension) EventsForDevice

func (e *NullExtension) EventsForDevice(sys *System, d *Device) *ExtEvents

func (*NullExtension) NetworkForDevice

func (e *NullExtension) NetworkForDevice(sys *System, d *Device) Network

type Scene

type Scene struct {
	Address     string
	ID          string
	Name        string
	Description string

	// Managed is true if gohome knows about the items the scene is controlling,
	// false otherwise. For example when you import a Lutron scene, we don't know
	// what zones it is controlling, it is managed by the Lutron device, but if you
	// create a GoHome scene, we do know what zones it will affect
	Managed  bool
	Commands []cmd.Command
}

Scene represents a target state for the system. A scene is just a list of commands that should be executed when the scene is chosen

func (*Scene) AddCommand

func (s *Scene) AddCommand(c cmd.Command) error

AddCommand adds a new command to the scene

func (*Scene) DeleteCommand

func (s *Scene) DeleteCommand(cmdID string) error

DeleteCommand deletes a command from the scene

func (*Scene) Validate

func (s *Scene) Validate() *validation.Errors

Validate verfies the scene is in a good state

type ServerStartedEvt

type ServerStartedEvt struct{}

ServerStartEvt fires when the server is started

func (*ServerStartedEvt) String

func (e *ServerStartedEvt) String() string

String returns a debug string

type Sessions

type Sessions struct {
	// contains filtered or unexported fields
}

Sessions manages user sessions in the app

func NewSessions

func NewSessions() *Sessions

NewSessions returns a newly instantiated Sessions instance

func (*Sessions) Add

func (s *Sessions) Add() (string, error)

Add adds a new session and returns the session ID back to the caller. You must call Save() at some point to persist the sessions to disk

func (*Sessions) Get

func (s *Sessions) Get(SID string) (map[string]interface{}, bool)

Get returns the values associated with the session ID. If the session ID is not valid it returns false as the second return value

func (*Sessions) Save

func (s *Sessions) Save() error

Save persists the session information to backing store

type SunriseEvt

type SunriseEvt struct{}

SunriseEvt is fired when it is sunrise

func (*SunriseEvt) String

func (e *SunriseEvt) String() string

String returns a debug string

type SunsetEvt

type SunsetEvt struct{}

Sunset is fired when it is sunset

func (*SunsetEvt) String

func (e *SunsetEvt) String() string

String returns a debug string

type System

type System struct {
	Name        string
	Description string
	Area        *Area
	Extensions  *Extensions
	Services    SystemServices
	// contains filtered or unexported fields
}

System is a container that holds information such as all the zones and devices that have been created.

func NewSystem

func NewSystem(name string) *System

NewSystem returns an initial System instance. It is still up to the caller to create all of the services and add them to the system after calling this function

func (*System) AddAutomation

func (s *System) AddAutomation(a *Automation)

AddAutomation adds an automation instance to the system, indexed by name

func (*System) AddDevice

func (s *System) AddDevice(d *Device)

AddDevice adds a device to the system

func (*System) AddFeature

func (s *System) AddFeature(f *feature.Feature)

AddFeature adds a feature to the system. If a feature with the same ID already exists it is replaced with the new feature

func (*System) AddScene

func (s *System) AddScene(scn *Scene)

AddScene adds a scene to the system. If a scene with the same ID already exists, it is overwritten with the new scene

func (*System) AddUser

func (s *System) AddUser(u *User)

AddUser adds the user to the system

func (*System) AutomationByTempID

func (s *System) AutomationByTempID(ID string) *Automation

AutomationByTempID returns the automation instance with the specified TempID, nil if not found

func (*System) Automations

func (s *System) Automations() map[string]*Automation

Automations reutrns all of the automation scripts keyed by ID

func (*System) DeleteDevice

func (s *System) DeleteDevice(d *Device)

DeleteDevice deletes a device from the system and stops all associated services, for all zones and devices this is responsible for

func (*System) DeleteScene

func (s *System) DeleteScene(scn *Scene)

DeleteScene deletes a scene from the system

func (*System) DeviceByAddress

func (s *System) DeviceByAddress(addr string) *Device

DeviceByAddress returns the first device found with the specified address

func (*System) DeviceByID

func (s *System) DeviceByID(ID string) *Device

DeviceByID returns the device with the specified ID, nil if not found

func (*System) Devices

func (s *System) Devices() map[string]*Device

Devices returns a map of all the devices in the system, keyed by device ID

func (*System) FeatureByAID

func (s *System) FeatureByAID(AID string) *feature.Feature

FeatureByAID returns the feature with the specified automation ID, nil if not found

func (*System) FeatureByID

func (s *System) FeatureByID(ID string) *feature.Feature

FeatureByID returns the feature with the specified ID, nil if not found

func (*System) FeaturesByType

func (s *System) FeaturesByType(ft string) map[string]*feature.Feature

FeaturesByType returns a map of all the features in the system that match the feature type, keyed by feature ID

func (*System) InitDevice

func (s *System) InitDevice(d *Device) error

InitDevice initializes a device. If the device has a connection pool, this is when it will be initialized. Also if the device produces or consumes events from the system bus, this is where it will be added to the event bus

func (*System) InitDevices

func (s *System) InitDevices()

InitDevices loops through all of the devices in the system and initializes them. This is async so after returning from this function the devices are still probably trying to initialize. A device may try to create network connections or other tasks when it is initialized

func (*System) IsDupeDevice

func (s *System) IsDupeDevice(x *Device) (*Device, bool)

IsDupeDevice returns true if the device is a dupe of one the system already owns. This check is not based on ID equality, since you could have scanned for a device previosuly and a second time, both scans will give a different ID for the device, since they are globally unique even though they are the same device

func (*System) NewID

func (s *System) NewID() string

NewID returns the next unique global ID that can be used as an identifier for an item in the system.

func (*System) SceneByID

func (s *System) SceneByID(ID string) *Scene

SceneByID returns the scene with the specified ID, nil if not found

func (*System) Scenes

func (s *System) Scenes() map[string]*Scene

Scenes returns a map of all the scenes in the system keyed by scene ID

func (*System) StopDevice

func (s *System) StopDevice(d *Device)

StopDevice stops the device, closes any network connections and any other services associated with the device

func (*System) Users

func (s *System) Users() map[string]*User

Users returns a map of all the users, keyed by user ID

type SystemServices

type SystemServices struct {
	UPNP         *upnp.SubServer
	Monitor      *Monitor
	EvtBus       *evtbus.Bus
	CmdProcessor CommandProcessor
}

SystemServices is a collection of services that devices can access such as UPNP notification and discovery

type TimeHelper

type TimeHelper struct {
	Time      clock.Time
	System    *System
	Latitude  float64
	Longitude float64
	Produce   bool
}

TimeHelper helps with some time related functionality, such as firing sunrise/sunset events

func (*TimeHelper) ProducerName

func (th *TimeHelper) ProducerName() string

func (*TimeHelper) StartProducing

func (th *TimeHelper) StartProducing(b *evtbus.Bus)

func (*TimeHelper) StopProducing

func (th *TimeHelper) StopProducing()

type TimeTrigger

type TimeTrigger struct {
	Name      string
	Mode      string
	At        time.Time
	Days      uint32
	Time      clock.Time
	Triggered func()
}

TimeTrigger is a trigger that can be used to execute actions either at sunrise/sunset or at an exact time. You can also specify for the trigger to only fire on certain days of the week

func (*TimeTrigger) ConsumerName

func (t *TimeTrigger) ConsumerName() string

func (*TimeTrigger) StartConsuming

func (t *TimeTrigger) StartConsuming(ch chan evtbus.Event)

func (*TimeTrigger) StopConsuming

func (t *TimeTrigger) StopConsuming()

func (*TimeTrigger) Trigger

func (t *TimeTrigger) Trigger()

type Trigger

type Trigger interface {
	evtbus.Consumer
	Trigger()
}

Trigger is an interface representing an automation trigger

type UIField

type UIField struct {
	// ID a unique ID for the field, doesn't need to be globally unique
	ID string

	// Label is a string that is shown to the user. This should be short, for more
	// information use the Description field
	Label string

	// Description is a string that will be shown to the user.
	Description string

	// Default is the value that shoud be shown by default
	Default string

	// Required indicates the field must be filled out by the user before a scan can occur
	Required bool
}

type UIPrefs

type UIPrefs struct {
	// HiddenZones is a map keyed by zone IDs for zones that should
	// not be displayed in the UI.
	HiddenZones map[string]bool
}

UIPrefs contains preferences for the UI

type User

type User struct {
	ID        string
	Login     string
	Prefs     UserPrefs
	HashedPwd string
	Salt      string
}

User represents a user of the system

func (*User) SetPassword

func (u *User) SetPassword(pwd string) error

SetPassword sets the users password

func (*User) Validate

func (u *User) Validate() *validation.Errors

Validate verifies the user object is in a good state

func (*User) VerifyPassword

func (u *User) VerifyPassword(pwd string) error

VerifyPassword returns nil if the password matches the users password, otherwise an error is returned

type UserLoginEvt

type UserLoginEvt struct {
	Login   string `json:"login"`
	Success bool   `json:"success"`
}

UserLoginEvt is fired when a user logs in to the system, or there is an unsuccessful login attempt

func (*UserLoginEvt) String

func (ul *UserLoginEvt) String() string

String returns a debug string

type UserLogoutEvt

type UserLogoutEvt struct {
	Login string `json:"login"`
}

UserLogoutEvt is fired when a user logs out of the system explicitly

func (*UserLogoutEvt) String

func (ul *UserLogoutEvt) String() string

String returns a debug string

type UserPrefs

type UserPrefs struct {
	// UI are user UI preference settings
	UI UIPrefs
}

UserPrefs contains all of the user specific preferences

Jump to

Keyboard shortcuts

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