client

package
v0.0.0-...-927397c Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: MIT Imports: 24 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Discover

func Discover(ctx context.Context, onDevice func(context.Context, *AccessoryDevice), searchDuration time.Duration) error

Discover searches for HomeKit accessory devices on the network for up to searchDuration. When a device is found the onDevice callback is triggered with information about the discovered device.

Types

type AccessoryClient

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

AccessoryClient allows interaction with a HomeKit accessory

func NewAccessoryClient

func NewAccessoryClient(dialer IPDialer, c *ControllerIdentity, a *AccessoryConnectionConfig) *AccessoryClient

NewAccessoryClient returns a new AccessoryClient using IP transport. The client uses the provided ControllerIdentity to connect to the accessory specified in AccessoryConnectionConfig.

Before using AccessoryClient you should first pair with the accessory using SetupClient.

This client is not thread safe.

func (*AccessoryClient) Accessories

func (a *AccessoryClient) Accessories(ctx context.Context) ([]*RawAccessory, error)

Accessories queries the HomeKit accessory to retrieve its Accessory Attribute Database. This returns all hap accessories, services and characteristics available.

func (*AccessoryClient) AddPairing

func (a *AccessoryClient) AddPairing(ctx context.Context, req *AddPairingRequest) error

AddPairing adds access by an additional controller to the accessory.

func (*AccessoryClient) Characteristics

Characteristics returns the values of the characteristics specified in readReq.

func (*AccessoryClient) Close

func (a *AccessoryClient) Close() error

Close releases any resources used by the client.

func (*AccessoryClient) ListPairings

func (a *AccessoryClient) ListPairings(ctx context.Context) ([]*ListPairingResponse, error)

ListPairings queries for a list of controllers that have been paired with the accessory.

func (*AccessoryClient) RemovePairing

func (a *AccessoryClient) RemovePairing(ctx context.Context, controllerDeviceID string) error

RemovePairing removes a pairing for the specified controller

func (*AccessoryClient) SetCharacteristics

SetCharacteristics updates values and settings of characteristics contained in writeReq.

type AccessoryConnectionConfig

type AccessoryConnectionConfig struct {
	DeviceID         string
	PublicKey        []byte
	IPConnectionInfo IPConnectionInfo
}

AccessoryConnectionConfig captures information needed to communicate with a paired accessory.

type AccessoryDevice

type AccessoryDevice struct {
	Name         string
	Model        string
	ID           string
	IPs          []net.IP
	Port         int
	FeatureFlags FeatureFlags
	StatusFlags  StatusFlags
}

AccessoryDevice is information about a discovered HomeKit accessory.

func DeviceByID

func DeviceByID(ctx context.Context, deviceID string, searchDuration time.Duration) (*AccessoryDevice, error)

DeviceByID searches for a device with the provided deviceID and returns it if found. If there hasn't been a match within searchDuration then an error is returned.

type AccessoryPairingConfig

type AccessoryPairingConfig struct {
	DeviceID         string
	PIN              string
	IPConnectionInfo IPConnectionInfo
	PairingMethod    PairingMethod
}

AccessoryPairingConfig contains accessory details needed to perform a pairing.

type AddPairingRequest

type AddPairingRequest struct {
	DeviceID    string
	PublicKey   []byte
	Permissions byte
}

AddPairingRequest specifies an additional controller that should be added to an accessory's pairings.

type CharacteristicReadRequest

type CharacteristicReadRequest struct {
	AccessoryID      uint64
	CharacteristicID uint64
}

CharacteristicReadRequest identifies a single characteristic to be read

type CharacteristicReadResponse

type CharacteristicReadResponse struct {
	AccessoryID      uint64               `json:"aid"`
	CharacteristicID uint64               `json:"iid"`
	Value            characteristic.Value `json:"value"`

	Type        *string  `json:"type,omitempty"`
	Status      *int     `json:"status,omitempty"`
	Events      *bool    `json:"ev,omitempty"`
	Permissions []string `json:"perms,omitempty"`

	Format *string `json:"format,omitempty"`
	Unit   *string `json:"unit,omitempty"`

	MaxLen    *int                 `json:"maxLen,omitempty"`
	MaxValue  characteristic.Value `json:"maxValue,omitempty"`
	MinValue  characteristic.Value `json:"minValue,omitempty"`
	StepValue characteristic.Value `json:"minStep,omitempty"`
}

CharacteristicReadResponse is the result of reading a single characteristic. Some fields are optional depending on the accessory implementation and the options specified in the CharacteristicsReadRequest.

type CharacteristicWriteRequest

type CharacteristicWriteRequest struct {
	AccessoryID      uint64      `json:"aid"`
	CharacteristicID uint64      `json:"iid"`
	Value            interface{} `json:"value,omitempty"`
	Events           bool        `json:"ev,omitempty"`
	AuthData         string      `json:"authdata,omitempty"`
	Remote           bool        `json:"remote,omitempty"`
	Response         bool        `json:"r,omitempty"`
}

CharacteristicWriteRequest specifies a single characteristic to write a value to as well as other optional settings.

type CharacteristicWriteResponse

type CharacteristicWriteResponse struct {
	AccessoryID      uint64               `json:"aid"`
	CharacteristicID uint64               `json:"iid"`
	Status           *int                 `json:"status,omitempty"`
	Value            characteristic.Value `json:"value,omitempty"`
}

CharacteristicWriteResponse is the result of a write to a single characteristic.

type CharacteristicsReadRequest

type CharacteristicsReadRequest struct {
	Characteristics []CharacteristicReadRequest
	Metadata        bool
	Permissions     bool
	Type            bool
	Events          bool
}

CharacteristicsReadRequest identifies a list of characteristics to read as well as options to control what fields are returned for each characteristic.

type CharacteristicsWriteRequest

type CharacteristicsWriteRequest struct {
	Characteristics []CharacteristicWriteRequest `json:"characteristics"`
	PrepareID       *uint64                      `json:"pid,omitempty"`
}

CharacteristicsWriteRequest specifies multiple characteristics to write values to.

type ControllerIdentity

type ControllerIdentity struct {
	DeviceID   string
	PublicKey  []byte
	PrivateKey []byte
}

ControllerIdentity captures required identifying details for a controller.

func NewRandomControllerConfig

func NewRandomControllerConfig() (*ControllerIdentity, error)

NewRandomControllerConfig returns a new config with random keys and a random id.

type FeatureFlags

type FeatureFlags byte

FeatureFlags captures Bonjour TXT feature flags

func (FeatureFlags) PairingMethod

func (f FeatureFlags) PairingMethod() PairingMethod

func (FeatureFlags) String

func (f FeatureFlags) String() string

type HomeKitSecureDialer

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

HomeKitSecureDialer negotiates a secure connection with an accessory using the pair-verify procedure.

func NewHomeKitSecureDialer

func NewHomeKitSecureDialer(dialer IPDialer, c *ControllerIdentity, a *AccessoryConnectionConfig) *HomeKitSecureDialer

NewHomeKitSecureDialer returns a new HomeKitSecureDialer suitable for use between controller c and accessory a.

func (*HomeKitSecureDialer) Close

func (h *HomeKitSecureDialer) Close() error

Close any underlying connections if needed.

func (*HomeKitSecureDialer) Dial

func (h *HomeKitSecureDialer) Dial(ctx context.Context, network, addr string) (net.Conn, error)

Dial will create a connection and negotiate secure communication using the pair-verify procedure prior to returning it. Further communication on the connection will be transparently encrypted. If a connection has already been established then the existing connection is returned.

type IPConnectionInfo

type IPConnectionInfo struct {
	IPAddress string
	Port      int
}

IPConnectionInfo identifies a HomeKit accessory on an ip network.

type IPDialer

type IPDialer func(ctx context.Context, network, address string) (net.Conn, error)

IPDialer establishes a network connection

func NewIPDialer

func NewIPDialer() IPDialer

NewIPDialer returns a default IPDialer that returns a basic connection

type IPTransport

type IPTransport interface {
	Do(req *http.Request) (*http.Response, error)
}

IPTransport provides http client capabilities. TODO: Look at what BluetoothTransport would take

type ListPairingResponse

type ListPairingResponse struct {
	ControllerID string
	PublicKey    []byte
	Admin        bool
}

ListPairingResponse describes a controller pairing returned from the ListPairings call.

type PairingMethod

type PairingMethod int

PairingMethod identifies the pairing method needed to pair the device

const (
	PairingMethodPairSetup PairingMethod = iota
	PairingMethodPairSetupWithAuth
)

type RawAccessory

type RawAccessory struct {
	ID       uint64                `json:"aid"`
	Services []*service.RawService `json:"services"`
}

RawAccessory captures information related to an accessory of a HomeKit accessory.

func (*RawAccessory) Info

func (r *RawAccessory) Info() *service.AccessoryInfo

Info returns the characteristic data from the accessory's info service.Info This service is required by the spec to be present for all accessories but if it's not found then nil is returned.

func (*RawAccessory) ServiceByType

func (r *RawAccessory) ServiceByType(t string) *service.RawService

ServiceByType returns the service of the accessory with a matching type if present. Nil otherwise.

type SetupClient

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

SetupClient negotiates an initial pairing between a controller and an accessory.

func NewSetupClient

func NewSetupClient(t IPTransport) *SetupClient

NewSetupClient returns a new SetupClient for ip accessible accessories.

func (*SetupClient) Pair

Pair will pair the controller c with the accessory a.

type StatusFlags

type StatusFlags byte

StatusFlags captures Bonjour TXT status flags

func (StatusFlags) String

func (s StatusFlags) String() string

type VerifyClient

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

VerifyClient sets up a secure session between a controller and accessory. This authenticates that the controller and accessory are trusted and negotiates a shared secret to encrypt further communciation.

func NewVerifyClient

NewVerifyClient returns a new VerifyClient suitable for performing pair-verify between accessory a and controller c.

func (*VerifyClient) Verify

Verify performs the pair-verify authentication and shared secret exchange and returns a crypto.Cryptographer that can encrypt future communication with the accessory.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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