hapip

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusSuccess                     = Status(0)
	StatusInsufficientPrivileges      = Status(-70401)
	StatusServiceCommunicationFailure = Status(-70402)
	StatusResourceBusy                = Status(-70403)
	StatusReadOnlyCharacteristic      = Status(-70404)
	StatusWriteOnlyCharacteristic     = Status(-70405)
	StatusNotificationNotSupported    = Status(-70406)
	StatusOutOfResource               = Status(-70407)
	StatusOperationTimedOut           = Status(-70408)
	StatusResourceDoesNotExist        = Status(-70409)
	StatusInvalidValueInRequest       = Status(-70410)
)

Variables

This section is empty.

Functions

func PrepareServer

func PrepareServer(server *http.Server, acc map[uint16]Accessory, options ...option) *http.Server

PrepareServer will create a notification.Manager, hook it to the connection events and wrap the server.Handler with an initialized hapip.Handler.

func WithLogger

func WithLogger(logger log.Logger) option

WithLogger adds structured logging to the pairing server.

func WriteJSON

func WriteJSON(rw http.ResponseWriter, httpCode int, data interface{}) error

func WriteStatus

func WriteStatus(rw http.ResponseWriter, httpCode int, hapCode Status) error

Types

type Accessory

type Accessory interface {
	Services() []Service
}

type AccessoryResource

type AccessoryResource interface {
	Accessory
	Resource(rw http.ResponseWriter, typ string, width, height int) error
}

type Characteristic

type Characteristic interface {
	Type() string
	Meta() CharacteristicMeta
}

type CharacteristicID

type CharacteristicID struct {
	AID uint16
	IID uint32
}

func (CharacteristicID) String

func (cid CharacteristicID) String() string

type CharacteristicMeta

type CharacteristicMeta struct {
	Format string

	// Optional
	Description string

	Unit        string
	MaxLen      int
	MinValue    interface{}
	MaxValue    interface{}
	MinStep     interface{}
	ValidValues interface{}
	ValidRange  interface{}
	MaxDataLen  int
}

type CharacteristicNotifier

type CharacteristicNotifier interface {
	Characteristic
	Notify(func(ctx context.Context, val, old interface{}))
}

type CharacteristicReader

type CharacteristicReader interface {
	Characteristic
	Read(context.Context) (interface{}, error)
}

type CharacteristicWriter

type CharacteristicWriter interface {
	Characteristic
	Write(context.Context, json.RawMessage) error
}

type Handler

type Handler struct {
	Logger   log.Logger
	Notifier Notifier

	Accessories map[uint16]Accessory
	// contains filtered or unexported fields
}

Handler is a http.Handler to handle /accessories and /characterisitc request. It fields must not be changed after calling .Initialize().

func (*Handler) Initialize

func (h *Handler) Initialize()

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type Notifier

type Notifier interface {
	Subscribe(context.Context, CharacteristicID, bool) error
	IsSubscribed(context.Context, CharacteristicID) (bool, error)
	Publish(context.Context, CharacteristicID, io.WriterTo)
}

type Service

type Service interface {
	Type() string
	Characteristics() []Characteristic
	IsPrimary() bool
}

type Status

type Status int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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