Documentation ¶
Index ¶
- Constants
- Variables
- type AllLinkMode
- type AllLinkRecord
- type AllLinkRecordFlags
- type AllLinkRecordSlice
- type Category
- type CommandCode
- type Configuration
- type ConfigurationDevice
- type DeviceEvent
- type DeviceInfo
- type ErrNoSuchDevice
- type Group
- type HTTPPowerLineModem
- func (m *HTTPPowerLineModem) Beep(ctx context.Context, identity ID) error
- func (m *HTTPPowerLineModem) GetAllLinkDB(ctx context.Context) (records AllLinkRecordSlice, err error)
- func (m *HTTPPowerLineModem) GetDeviceInfo(ctx context.Context, identity ID) (deviceInfo *DeviceInfo, err error)
- func (m *HTTPPowerLineModem) GetDeviceState(ctx context.Context, identity ID) (state *LightState, err error)
- func (m *HTTPPowerLineModem) GetIMInfo(ctx context.Context) (imInfo *IMInfo, err error)
- func (m *HTTPPowerLineModem) Monitor(ctx context.Context, events chan<- DeviceEvent) error
- func (m *HTTPPowerLineModem) SetDeviceInfo(ctx context.Context, identity ID, deviceInfo DeviceInfo) error
- func (m *HTTPPowerLineModem) SetDeviceState(ctx context.Context, identity ID, state LightState) error
- type HubitatConfiguration
- type HubitatEvent
- type ID
- type IMInfo
- type LightOnOff
- type LightState
- type LightStateChange
- type MainCategory
- type Message
- type MessageFlags
- type PowerLineModem
- type SerialPowerLineModem
- func (m *SerialPowerLineModem) Beep(ctx context.Context, identity ID) (err error)
- func (m *SerialPowerLineModem) GetAllLinkDB(ctx context.Context) (records AllLinkRecordSlice, err error)
- func (m *SerialPowerLineModem) GetDeviceInfo(ctx context.Context, identity ID) (deviceInfo *DeviceInfo, err error)
- func (m *SerialPowerLineModem) GetDeviceState(ctx context.Context, identity ID) (state *LightState, err error)
- func (m *SerialPowerLineModem) GetIMInfo(ctx context.Context) (imInfo *IMInfo, err error)
- func (m *SerialPowerLineModem) Monitor(ctx context.Context, events chan<- DeviceEvent) error
- func (m *SerialPowerLineModem) SetDeviceInfo(ctx context.Context, identity ID, deviceInfo DeviceInfo) (err error)
- func (m *SerialPowerLineModem) SetDeviceLEDBrightness(ctx context.Context, identity ID, level float64) (err error)
- func (m *SerialPowerLineModem) SetDeviceOnLevel(ctx context.Context, identity ID, level float64) (err error)
- func (m *SerialPowerLineModem) SetDeviceRampRate(ctx context.Context, identity ID, rampRate time.Duration) (err error)
- func (m *SerialPowerLineModem) SetDeviceState(ctx context.Context, identity ID, state LightState) (err error)
- func (m *SerialPowerLineModem) SetDeviceX10Address(ctx context.Context, identity ID, x10Address [2]byte) (err error)
- type SubCategory
- type WebService
Constants ¶
const ( // EnvPowerLineModemDevice is the environment variable that contains // the system PowerLine Modem device. EnvPowerLineModemDevice = "INSTEON_POWERLINE_MODEM_DEVICE" // EnvPowerLineModemDebug is the environment variable that contains the // system PowerLine Modem debug setting. EnvPowerLineModemDebug = "INSTEON_POWERLINE_MODEM_DEBUG" // EnvWebServiceDebug is the environment variable that contains the // system web-service debug setting. EnvWebServiceDebug = "INSTEON_WEB_SERVICE_DEBUG" )
const ( // DefaultPowerLineModemDevice is the default PowerLine Modem // device. DefaultPowerLineModemDevice = "/dev/tty0" )
Variables ¶
var ( // PowerLineModemDevice is the current PowerLine Modem device. PowerLineModemDevice = getEnvOrDefault( EnvPowerLineModemDevice, DefaultPowerLineModemDevice, ) // PowerLineModemDebug is the current PowerLine Modem debug setting. PowerLineModemDebug = getBoolEnvOrDefault(EnvPowerLineModemDebug, false) // WebServiceDebug is the current web-service debug setting. WebServiceDebug = getBoolEnvOrDefault(EnvWebServiceDebug, false) )
var DefaultPowerLineModem = func() PowerLineModem { plm, err := NewPowerLineModem(PowerLineModemDevice) if err != nil { panic(fmt.Errorf("instanciating default PowerLine Modem: %s", err)) } return plm }()
DefaultPowerLineModem is the default PowerLine Modem instance.
var ( // ErrCommandFailed is returned when a command failed. ErrCommandFailed = errors.New("command failed") )
Functions ¶
This section is empty.
Types ¶
type AllLinkMode ¶
type AllLinkMode byte
AllLinkMode represents an all-link mode.
const ( // ModeResponder represents a responder. ModeResponder AllLinkMode = 0x00 // ModeController represents a controller. ModeController AllLinkMode = 0x01 // ModeAuto represents auto-selection of the mode. ModeAuto AllLinkMode = 0x03 // ModeDelete represents a deletion of an all-link record. ModeDelete AllLinkMode = 0xff )
func (AllLinkMode) String ¶
func (m AllLinkMode) String() string
type AllLinkRecord ¶
type AllLinkRecord struct { Flags AllLinkRecordFlags `json:"flags"` Group Group `json:"group"` ID ID `json:"id"` LinkData []byte `json:"link_data"` }
AllLinkRecord represents a all-link record.
func (*AllLinkRecord) MarshalBinary ¶
func (r *AllLinkRecord) MarshalBinary() ([]byte, error)
MarshalBinary -
func (AllLinkRecord) Mode ¶
func (r AllLinkRecord) Mode() AllLinkMode
Mode returns the mode of an all-link record.
func (*AllLinkRecord) UnmarshalBinary ¶
func (r *AllLinkRecord) UnmarshalBinary(b []byte) error
UnmarshalBinary -
type AllLinkRecordFlags ¶
type AllLinkRecordFlags byte
AllLinkRecordFlags represents an all-link record flags.
type AllLinkRecordSlice ¶
type AllLinkRecordSlice []AllLinkRecord
AllLinkRecordSlice is a slice of all link records.
func (AllLinkRecordSlice) Len ¶
func (l AllLinkRecordSlice) Len() int
Len returns the length of the list.
func (AllLinkRecordSlice) Less ¶
func (l AllLinkRecordSlice) Less(i, j int) bool
Less returns whether the element at i should appear before the element at j.
func (AllLinkRecordSlice) Swap ¶
func (l AllLinkRecordSlice) Swap(i, j int)
Swap swaps two elements.
type Category ¶
type Category struct { MainCategory `json:"main"` SubCategory `json:"sub"` }
Category represents a category.
func (*Category) UnmarshalBinary ¶
UnmarshalBinary -
type CommandCode ¶
type CommandCode byte
CommandCode represents a command code sent between the PLM and the host.
type Configuration ¶
type Configuration struct { Devices []ConfigurationDevice `yaml:"devices"` Hubitat HubitatConfiguration `yaml:"hubitat"` }
Configuration represents a configuration.
func LoadConfiguration ¶
func LoadConfiguration(r io.Reader) (*Configuration, error)
LoadConfiguration loads a configuration from a YAML stream.
func LoadDefaultConfiguration ¶
func LoadDefaultConfiguration() (*Configuration, error)
LoadDefaultConfiguration loads the default configuration.
func (*Configuration) GetDevice ¶
func (c *Configuration) GetDevice(id ID) (*ConfigurationDevice, error)
GetDevice finds a device from its id.
func (*Configuration) LookupDevice ¶
func (c *Configuration) LookupDevice(alias string) (*ConfigurationDevice, error)
LookupDevice finds a device from its alias.
type ConfigurationDevice ¶
type ConfigurationDevice struct { ID ID `yaml:"id" json:"insteon_id"` Name string `yaml:"name" json:"description"` Alias string `yaml:"alias" json:"id"` Group string `yaml:"group,omitempty" json:"-"` MirrorDeviceIDs []ID `yaml:"mirror_devices" json:"-"` ControllerIDs []ID `yaml:"controllers" json:"-"` }
ConfigurationDevice represents a device in the configuration.
func (*ConfigurationDevice) UnmarshalYAML ¶
func (d *ConfigurationDevice) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML -
type DeviceEvent ¶
type DeviceEvent struct { Identity ID `json:"id"` OnOff LightOnOff `json:"onoff"` Change LightStateChange `json:"change,omitempty"` }
DeviceEvent represents a DeviceEvent.
type DeviceInfo ¶
type DeviceInfo struct { X10Address *[2]byte `json:"x10_address,omitempty"` RampRate *time.Duration `json:"ramp_rate,omitempty"` OnLevel *float64 `json:"on_level,omitempty"` LEDBrightness *float64 `json:"led_brightness,omitempty"` }
DeviceInfo contains information about a device.
func (DeviceInfo) MarshalBinary ¶
func (i DeviceInfo) MarshalBinary() ([]byte, error)
MarshalBinary -
func (*DeviceInfo) UnmarshalBinary ¶
func (i *DeviceInfo) UnmarshalBinary(b []byte) error
UnmarshalBinary -
type ErrNoSuchDevice ¶
ErrNoSuchDevice is returned whenever a lookup on a given device alias failed.
func (ErrNoSuchDevice) Error ¶
func (e ErrNoSuchDevice) Error() string
Error returns the error string.
type HTTPPowerLineModem ¶
type HTTPPowerLineModem struct { URL *url.URL Client *http.Client // contains filtered or unexported fields }
HTTPPowerLineModem implements a PowerLine modem over HTTP.
func NewHTTPPowerLineModem ¶
func NewHTTPPowerLineModem(p string) (*HTTPPowerLineModem, error)
NewHTTPPowerLineModem instanciates a new HTTP PowerLine modem.
func (*HTTPPowerLineModem) Beep ¶
func (m *HTTPPowerLineModem) Beep(ctx context.Context, identity ID) error
Beep causes a device to beep.
func (*HTTPPowerLineModem) GetAllLinkDB ¶
func (m *HTTPPowerLineModem) GetAllLinkDB(ctx context.Context) (records AllLinkRecordSlice, err error)
GetAllLinkDB gets the on level of a device.
func (*HTTPPowerLineModem) GetDeviceInfo ¶
func (m *HTTPPowerLineModem) GetDeviceInfo(ctx context.Context, identity ID) (deviceInfo *DeviceInfo, err error)
GetDeviceInfo returns the information about a device.
func (*HTTPPowerLineModem) GetDeviceState ¶
func (m *HTTPPowerLineModem) GetDeviceState(ctx context.Context, identity ID) (state *LightState, err error)
GetDeviceState gets the on level of a device.
func (*HTTPPowerLineModem) GetIMInfo ¶
func (m *HTTPPowerLineModem) GetIMInfo(ctx context.Context) (imInfo *IMInfo, err error)
GetIMInfo gets information about the PowerLine Modem.
func (*HTTPPowerLineModem) Monitor ¶
func (m *HTTPPowerLineModem) Monitor(ctx context.Context, events chan<- DeviceEvent) error
Monitor the Insteon network for changes for as long as the specified context remains valid.
All events are pushed to the specified events channel.
func (*HTTPPowerLineModem) SetDeviceInfo ¶
func (m *HTTPPowerLineModem) SetDeviceInfo(ctx context.Context, identity ID, deviceInfo DeviceInfo) error
SetDeviceInfo sets the information on device.
func (*HTTPPowerLineModem) SetDeviceState ¶
func (m *HTTPPowerLineModem) SetDeviceState(ctx context.Context, identity ID, state LightState) error
SetDeviceState sets the state of a lighting device.
type HubitatConfiguration ¶
type HubitatConfiguration struct {
HubURL string `yaml:"hub_url"`
}
HubitatConfiguration contains the Hubitat configuration.
type HubitatEvent ¶
type HubitatEvent struct { Alias string `json:"id"` State LightState `json:"state"` }
HubitatEvent represents a Hubitat event.
type ID ¶
type ID [3]byte
ID represents a device ID.
func (ID) AsGroup ¶
AsGroup returns the ID as a group. Result is only meaningful if the identity is the target of a broadcast message.
func (ID) MarshalText ¶
MarshalText implements text marshaling.
func (*ID) UnmarshalText ¶
UnmarshalText implements text unmarshalling.
type IMInfo ¶
type IMInfo struct { ID ID `json:"id"` Category Category `json:"category"` FirmwareVersion uint8 `json:"firmware_version"` }
IMInfo contains information about a PowerLine Modem.
type LightOnOff ¶
type LightOnOff bool
LightOnOff represents a light on/off state.
const ( // LightOn indicates an on light. LightOn LightOnOff = true // LightOff indicates an off light. LightOff LightOnOff = false )
func (LightOnOff) String ¶
func (s LightOnOff) String() string
type LightState ¶
type LightState struct { OnOff LightOnOff `json:"onoff"` Change LightStateChange `json:"change,omitempty"` Level float64 `json:"level,omitempty"` }
LightState represents a light state.
func (LightState) MarshalBinary ¶
func (s LightState) MarshalBinary() ([]byte, error)
MarshalBinary -
func (*LightState) UnmarshalBinary ¶
func (s *LightState) UnmarshalBinary(b []byte) error
UnmarshalBinary -
type LightStateChange ¶
type LightStateChange int
LightStateChange represents a light state change.
const ( // ChangeNormal indicates that the light state must change as if a single // press had been done. ChangeNormal LightStateChange = iota // ChangeInstant indicates that the light state must change instantly, as // if a quick double-press had been done. ChangeInstant // ChangeStep indicates that the light state must change for one step up or // down. ChangeStep // ChangeStart indicates that the light state must start changing until a // ChangeStop change is set. ChangeStart // ChangeStop stops a light change started with ChangeStart. ChangeStop )
func (LightStateChange) MarshalText ¶
func (c LightStateChange) MarshalText() ([]byte, error)
MarshalText -
func (*LightStateChange) UnmarshalText ¶
func (c *LightStateChange) UnmarshalText(b []byte) error
UnmarshalText -
type Message ¶
type Message struct { Source ID Target ID HopsLeft int MaxHops int Flags MessageFlags CommandBytes [2]byte UserData [14]byte }
Message is sent through the PLM to communicate with other devices.
func (Message) IsExtended ¶
IsExtended returns whether the message is an extended message.
func (*Message) UnmarshalBinary ¶
UnmarshalBinary -
type MessageFlags ¶
type MessageFlags byte
MessageFlags represents the message flags.
const ( // MessageFlagExtended indicates extended messages. MessageFlagExtended MessageFlags = 0x10 // MessageFlagAck indicates an acquitement message. MessageFlagAck MessageFlags = 0x20 // MessageFlagAllLink indicates an all-link message. MessageFlagAllLink MessageFlags = 0x40 // MessageFlagBroadcast indicates a broadcast message. MessageFlagBroadcast MessageFlags = 0x80 )
func (MessageFlags) String ¶
func (f MessageFlags) String() string
type PowerLineModem ¶
type PowerLineModem interface { GetIMInfo(ctx context.Context) (imInfo *IMInfo, err error) GetAllLinkDB(ctx context.Context) (records AllLinkRecordSlice, err error) GetDeviceState(ctx context.Context, identity ID) (state *LightState, err error) SetDeviceState(ctx context.Context, identity ID, state LightState) (err error) GetDeviceInfo(ctx context.Context, identity ID) (deviceInfo *DeviceInfo, err error) SetDeviceInfo(ctx context.Context, identity ID, deviceInfo DeviceInfo) error Beep(ctx context.Context, identity ID) (err error) Monitor(ctx context.Context, events chan<- DeviceEvent) error }
PowerLineModem represnts a powerline modem.
func NewPowerLineModem ¶
func NewPowerLineModem(device string) (PowerLineModem, error)
NewPowerLineModem instantiates a new PowerLine Modem.
type SerialPowerLineModem ¶
type SerialPowerLineModem struct { // Device is the underlying device to use to send and receive PLM commands. // // Can be a local serial port or a remote one (TCP). Device io.ReadWriteCloser ExecutionTimeout time.Duration // contains filtered or unexported fields }
SerialPowerLineModem represnts a powerline modem.
func NewLocalPowerLineModem ¶
func NewLocalPowerLineModem(serialPort string) (*SerialPowerLineModem, error)
NewLocalPowerLineModem instantiates a new local PowerLine Modem.
func NewRemotePowerLineModem ¶
func NewRemotePowerLineModem(host string) (*SerialPowerLineModem, error)
NewRemotePowerLineModem instantiates a new remote PowerLine Modem.
func (*SerialPowerLineModem) Beep ¶
func (m *SerialPowerLineModem) Beep(ctx context.Context, identity ID) (err error)
Beep causes a device to beep.
func (*SerialPowerLineModem) GetAllLinkDB ¶
func (m *SerialPowerLineModem) GetAllLinkDB(ctx context.Context) (records AllLinkRecordSlice, err error)
GetAllLinkDB gets the on level of a device.
func (*SerialPowerLineModem) GetDeviceInfo ¶
func (m *SerialPowerLineModem) GetDeviceInfo(ctx context.Context, identity ID) (deviceInfo *DeviceInfo, err error)
GetDeviceInfo returns the information about a device.
func (*SerialPowerLineModem) GetDeviceState ¶
func (m *SerialPowerLineModem) GetDeviceState(ctx context.Context, identity ID) (state *LightState, err error)
GetDeviceState gets the on level of a device.
func (*SerialPowerLineModem) GetIMInfo ¶
func (m *SerialPowerLineModem) GetIMInfo(ctx context.Context) (imInfo *IMInfo, err error)
GetIMInfo gets information about the PowerLine Modem.
func (*SerialPowerLineModem) Monitor ¶
func (m *SerialPowerLineModem) Monitor(ctx context.Context, events chan<- DeviceEvent) error
Monitor the Insteon network for changes for as long as the specified context remains valid.
All events are pushed to the specified events channel.
func (*SerialPowerLineModem) SetDeviceInfo ¶
func (m *SerialPowerLineModem) SetDeviceInfo(ctx context.Context, identity ID, deviceInfo DeviceInfo) (err error)
SetDeviceInfo sets the information on device.
func (*SerialPowerLineModem) SetDeviceLEDBrightness ¶
func (m *SerialPowerLineModem) SetDeviceLEDBrightness(ctx context.Context, identity ID, level float64) (err error)
SetDeviceLEDBrightness sets a device LED brightness.
func (*SerialPowerLineModem) SetDeviceOnLevel ¶
func (m *SerialPowerLineModem) SetDeviceOnLevel(ctx context.Context, identity ID, level float64) (err error)
SetDeviceOnLevel sets a device on level.
func (*SerialPowerLineModem) SetDeviceRampRate ¶
func (m *SerialPowerLineModem) SetDeviceRampRate(ctx context.Context, identity ID, rampRate time.Duration) (err error)
SetDeviceRampRate sets a device ramp rate.
func (*SerialPowerLineModem) SetDeviceState ¶
func (m *SerialPowerLineModem) SetDeviceState(ctx context.Context, identity ID, state LightState) (err error)
SetDeviceState sets the state of a lighting device.
func (*SerialPowerLineModem) SetDeviceX10Address ¶
func (m *SerialPowerLineModem) SetDeviceX10Address(ctx context.Context, identity ID, x10Address [2]byte) (err error)
SetDeviceX10Address sets a device X10 address.
type WebService ¶
type WebService struct { PowerLineModem PowerLineModem Configuration *Configuration // DisablePowerLineModem is a boolean value that, if set, disables // exposition of the PowerLineModem routes. DisablePowerLineModem bool // DisableAPI is a boolean value that, if set, disables exposition of the // API routes. DisableAPI bool // ForceRefreshPeriod is the period after which to consider a device state // stale. ForceRefreshPeriod time.Duration // contains filtered or unexported fields }
WebService implements a web-service that manages Insteon devices.
func NewWebService ¶
func NewWebService(powerLineModem PowerLineModem, configuration *Configuration) *WebService
NewWebService instanciates a new web service.
If no PowerLine modem is specified, the default one is taken. If no configuration is specified, the default one is taken.
func (*WebService) Handler ¶
func (s *WebService) Handler() http.Handler
Handler returns the HTTP handler associated to the web-service.
func (*WebService) Run ¶
func (s *WebService) Run(ctx context.Context) error
Run the web-service for as long as the specified context remains valid.
func (*WebService) Synchronize ¶
func (s *WebService) Synchronize(ctx context.Context, failOnMissingOptimization bool) error
Synchronize the web-service with the Insteon network to optimize efficiency.
Must be done before Run is called or the HTTP handler is served.
Source Files ¶
- all_link_record.go
- category.go
- command_bytes.go
- command_code.go
- configuration.go
- debug.go
- defaults.go
- device_event.go
- device_info.go
- error.go
- group.go
- http_power_line_modem.go
- hubitat.go
- id.go
- im_info.go
- inbox.go
- light_state.go
- message.go
- packet.go
- packet_reader.go
- packet_writer.go
- power_line_modem.go
- serial_power_line_modem.go
- web_service.go