discovery

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const (
	AlltercoRoboticsLTDCompanyID uint16 = 2985
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthCallback added in v0.2.0

type AuthCallback func(ctx context.Context, desc string) (pw string, err error)

type BLEDevice

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

func (*BLEDevice) AddHandler

func (b *BLEDevice) AddHandler(method string, handler mgrpc.Handler)

func (*BLEDevice) Call

func (b *BLEDevice) Call(
	ctx context.Context, dst string, cmd *frame.Command, getCreds mgrpc.GetCredsCallback,
) (*frame.Response, error)

func (*BLEDevice) Disconnect

func (b *BLEDevice) Disconnect(ctx context.Context) error

func (*BLEDevice) IsConnected

func (b *BLEDevice) IsConnected() bool

func (*BLEDevice) SetCodecOptions

func (b *BLEDevice) SetCodecOptions(opts *codec.Options) error

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

func (*Device) BestName

func (d *Device) BestName() string

func (*Device) Instance

func (d *Device) Instance() string

func (*Device) Log

func (d *Device) Log(ll zerolog.Logger) zerolog.Logger

func (*Device) LogCtx

func (d *Device) LogCtx(ctx context.Context) zerolog.Logger

func (*Device) Open

func (d *Device) Open(ctx context.Context) (mgrpc.MgRPC, error)

Open creates an mongoose rpc channel to the device.

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) AddBLE

func (d *Discoverer) AddBLE(ctx context.Context, mac string) (*Device, error)

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.

func (*Discoverer) Search

func (d *Discoverer) Search(ctx context.Context) ([]*Device, error)

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 SearchConfirm func(desc string) (approveDevice bool, continueSearch bool, err error)

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.

Jump to

Keyboard shortcuts

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