Documentation ¶
Index ¶
- Constants
- type AuthCallback
- type BLEDevice
- func (b *BLEDevice) AddHandler(method string, handler mgrpc.Handler)
- func (b *BLEDevice) Call(ctx context.Context, dst string, cmd *frame.Command, ...) (*frame.Response, error)
- func (b *BLEDevice) Disconnect(ctx context.Context) error
- func (b *BLEDevice) IsConnected() bool
- func (b *BLEDevice) SetCodecOptions(opts *codec.Options) error
- type Device
- func (d *Device) AuthCallback(ctx context.Context) mgrpc.GetCredsCallback
- func (d *Device) BestName() string
- func (d *Device) Instance() string
- func (d *Device) Log(ll zerolog.Logger) zerolog.Logger
- func (d *Device) LogCtx(ctx context.Context) zerolog.Logger
- func (d *Device) Open(ctx context.Context) (mgrpc.MgRPC, error)
- type DeviceOption
- type Discoverer
- func (d *Discoverer) AddBLE(ctx context.Context, mac string) (*Device, error)
- func (d *Discoverer) AddDeviceByAddress(ctx context.Context, addr string, opts ...DeviceOption) (*Device, error)
- func (d *Discoverer) AllDevices() []*Device
- func (d *Discoverer) Search(ctx context.Context) ([]*Device, error)
- type DiscovererOption
- func WithAuthCallback(authCallback AuthCallback) DiscovererOption
- func WithBLEAdapter(ble *bluetooth.Adapter) DiscovererOption
- func WithBLESearchEnabled(enabled bool) DiscovererOption
- func WithConcurrency(concurrency int) DiscovererOption
- func WithDeviceTTL(ttl time.Duration) DiscovererOption
- func WithIPVersion(ipVersion string) DiscovererOption
- func WithMDNSInterface(iface *net.Interface) DiscovererOption
- func WithMDNSSearchEnabled(enabled bool) DiscovererOption
- func WithMDNSService(service string) DiscovererOption
- func WithMDNSZone(zone string) DiscovererOption
- func WithSearchConfirm(confirm SearchConfirm) DiscovererOption
- func WithSearchStrictTimeout(strictTimeoutMode bool) DiscovererOption
- func WithSearchTimeout(timeout time.Duration) DiscovererOption
- type SearchConfirm
- type TestDevice
- func (d *TestDevice) AddMockErrorResponse(method string, matcher TestParamMatcher, statusCode int, statusMsg string) *TestDevice
- func (d *TestDevice) AddMockResponse(method string, matcher TestParamMatcher, response json.RawMessage) *TestDevice
- func (d *TestDevice) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (d *TestDevice) Shutdown()
- type TestDiscoverer
- type TestParamMatcher
Constants ¶
const ( // DefaultDeviceTTL sets the default time-to-live for discovered devices on long-lived commands. DefaultDeviceTTL = 5 * time.Minute DefaultMDNSZone = "local" DefaultMDNSService = "_shelly._tcp" DefaultMDNSSearchTimeout = 1 * time.Second DefaultConcurrency = 5 )
const (
AlltercoRoboticsLTDCompanyID uint16 = 2985
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthCallback ¶ added in v0.2.0
type BLEDevice ¶
type BLEDevice struct {
// contains filtered or unexported fields
}
func (*BLEDevice) IsConnected ¶
type Device ¶
type Device struct { MACAddr string Name string Specs shelly.DeviceSpecs // contains filtered or unexported fields }
Device describes one shelly device.
func (*Device) AuthCallback ¶ added in v0.2.0
func (d *Device) AuthCallback(ctx context.Context) mgrpc.GetCredsCallback
type DeviceOption ¶
type DeviceOption func(*Device)
func WithDeviceName ¶
func WithDeviceName(name string) DeviceOption
type Discoverer ¶
type Discoverer struct {
// contains filtered or unexported fields
}
Discoverer finds shelly gen 2 devices and provides basic metadata.
func NewDiscoverer ¶
func NewDiscoverer(opts ...DiscovererOption) *Discoverer
func (*Discoverer) AddDeviceByAddress ¶
func (d *Discoverer) AddDeviceByAddress(ctx context.Context, addr string, opts ...DeviceOption) (*Device, error)
AddDeviceByAddress attempts to parse a user-provided URI and add the device. An error will be generated if the address cannot be parsed or is unreachable. If no schema is provided, `http` is assumed. Any non-empty URI path other than `/rpc` is invalid and will be rejected. If the hostname ends in the mDNS zone (.local by default) the name will be resolved via mDNS.
func (*Discoverer) AllDevices ¶
func (d *Discoverer) AllDevices() []*Device
AllDevices returns all known devices.
type DiscovererOption ¶
type DiscovererOption func(*Discoverer)
DiscovererOption provides optional parameters for the Discoverer.
func WithAuthCallback ¶ added in v0.2.0
func WithAuthCallback(authCallback AuthCallback) DiscovererOption
WithAuthCallback sets a default callback for authenticating .
func WithBLEAdapter ¶
func WithBLEAdapter(ble *bluetooth.Adapter) DiscovererOption
WithBLEAdapter configures a BLE adapter for use in discovery.
func WithBLESearchEnabled ¶
func WithBLESearchEnabled(enabled bool) DiscovererOption
WithMDNSSearchEnabled allows enabling or disabling BLE discovery.
func WithConcurrency ¶
func WithConcurrency(concurrency int) DiscovererOption
WithConcurrency configures the number of concurrent device probes to evaluate.
func WithDeviceTTL ¶
func WithDeviceTTL(ttl time.Duration) DiscovererOption
WithDeviceTTL configures a time-to-live for devices in long-lived commands like the prometheus server.
func WithIPVersion ¶
func WithIPVersion(ipVersion string) DiscovererOption
WithIPVersion sets a required IP version for discovery. Values "4" or "6" are accepted.
func WithMDNSInterface ¶
func WithMDNSInterface(iface *net.Interface) DiscovererOption
WithMDNSInterface configures a specific network interface to search.
func WithMDNSSearchEnabled ¶
func WithMDNSSearchEnabled(enabled bool) DiscovererOption
WithMDNSSearchEnabled allows enabling or disabling mDNS discovery.
func WithMDNSService ¶
func WithMDNSService(service string) DiscovererOption
WithMDNSService configures the mDNS service name to search. Shelly devices are commonly at `_shelly._tcp`.
func WithMDNSZone ¶
func WithMDNSZone(zone string) DiscovererOption
WithMDNSZone configures the mDNS zone to search. This is commonly `.local`.
func WithSearchConfirm ¶
func WithSearchConfirm(confirm SearchConfirm) DiscovererOption
WithSearchConfirm sets a callback to confirm search results.
func WithSearchStrictTimeout ¶ added in v0.3.0
func WithSearchStrictTimeout(strictTimeoutMode bool) DiscovererOption
WithSearchStrictTimeout will force devices which have been discovered, but not resolved and added to finish within the search timeout or be cancelled.
func WithSearchTimeout ¶
func WithSearchTimeout(timeout time.Duration) DiscovererOption
WithSearchTimeout specifies the duration to wait for mDNS responses and the initial probe.
type SearchConfirm ¶
type TestDevice ¶
type TestDevice struct { *Device // contains filtered or unexported fields }
TestDevice wraps Device with functionality for mocking a Device.
func (*TestDevice) AddMockErrorResponse ¶
func (d *TestDevice) AddMockErrorResponse(method string, matcher TestParamMatcher, statusCode int, statusMsg string) *TestDevice
AddMockErrorResponse mocks an error response for a method.
func (*TestDevice) AddMockResponse ¶
func (d *TestDevice) AddMockResponse(method string, matcher TestParamMatcher, response json.RawMessage) *TestDevice
AddMockResponse mocks a response for a method.
func (*TestDevice) ServeHTTP ¶
func (d *TestDevice) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
func (*TestDevice) Shutdown ¶
func (d *TestDevice) Shutdown()
Shutdown closes network servers associated with test.
type TestDiscoverer ¶
type TestDiscoverer struct {
*Discoverer
}
TestDiscoverer is a wrapper around the Discoverer w/ additional options for testing.
func NewTestDiscoverer ¶
func NewTestDiscoverer(t *testing.T, opts ...DiscovererOption) *TestDiscoverer
NewTestDiscoverer creates a discoverer for use in testing.
func (*TestDiscoverer) NewTestDevice ¶
func (td *TestDiscoverer) NewTestDevice(t *testing.T, add bool) *TestDevice
NewTestDevice creates a TestDevice which mocks a real Shelly device.
func (*TestDiscoverer) SetMDNSQueryFunc ¶
func (td *TestDiscoverer) SetMDNSQueryFunc(q func(context.Context, *mdns.QueryParam) error)
SetMDNSQueryFunc facilitates overriding the mDNS query function for testing.
type TestParamMatcher ¶
type TestParamMatcher func(*testing.T, json.RawMessage) bool
TestParamMatcher describes functions which can match a particular requests parameters.