light

package
v0.0.0-...-0f67f6e Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultModelOptions = []resource.Option{
	WithInitialBrightness(&traits.Brightness{}),
}

DefaultModelOptions holds the default options for the model.

Functions

func InitialBrightness

func InitialBrightness() *traits.Brightness

func WithBrightnessOption

func WithBrightnessOption(opts ...resource.Option) resource.Option

WithBrightnessOption configures the brightness resource of the model.

func WithInitialBrightness

func WithInitialBrightness(brightness *traits.Brightness) resource.Option

WithInitialBrightness returns an option that configures the model to initialise with the given brightness.

func WithLightApiClientFactory

func WithLightApiClientFactory(f func(name string) (traits.LightApiClient, error)) router.Option

WithLightApiClientFactory instructs the router to create a new client the first time Get is called for that name.

func WithLightInfoClientFactory

func WithLightInfoClientFactory(f func(name string) (traits.LightInfoClient, error)) router.Option

WithLightInfoClientFactory instructs the router to create a new client the first time Get is called for that name.

func WithPreset

func WithPreset(levelPercent float32, p *traits.LightPreset) resource.Option

WithPreset instructs the model to set the light to the given level when preset p is selected.

Types

type ApiRouter

type ApiRouter struct {
	traits.UnimplementedLightApiServer

	router.Router
}

ApiRouter is a traits.LightApiServer that allows routing named requests to specific traits.LightApiClient

func NewApiRouter

func NewApiRouter(opts ...router.Option) *ApiRouter

func (*ApiRouter) Add

func (r *ApiRouter) Add(name string, client any) any

Add extends Router.Add to panic if client is not of type traits.LightApiClient.

func (*ApiRouter) AddLightApiClient

func (r *ApiRouter) AddLightApiClient(name string, client traits.LightApiClient) traits.LightApiClient

func (*ApiRouter) GetBrightness

func (r *ApiRouter) GetBrightness(ctx context.Context, request *traits.GetBrightnessRequest) (*traits.Brightness, error)

func (*ApiRouter) GetLightApiClient

func (r *ApiRouter) GetLightApiClient(name string) (traits.LightApiClient, error)

func (*ApiRouter) HoldsType

func (r *ApiRouter) HoldsType(client any) bool

func (*ApiRouter) PullBrightness

func (*ApiRouter) Register

func (r *ApiRouter) Register(server grpc.ServiceRegistrar)

func (*ApiRouter) RemoveLightApiClient

func (r *ApiRouter) RemoveLightApiClient(name string) traits.LightApiClient

func (*ApiRouter) UpdateBrightness

func (r *ApiRouter) UpdateBrightness(ctx context.Context, request *traits.UpdateBrightnessRequest) (*traits.Brightness, error)

type ApiWrapper

type ApiWrapper struct {
	traits.LightApiClient
	// contains filtered or unexported fields
}

func WrapApi

func WrapApi(server traits.LightApiServer) *ApiWrapper

WrapApi adapts a traits.LightApiServer and presents it as a traits.LightApiClient

func (*ApiWrapper) Unwrap

func (w *ApiWrapper) Unwrap() any

Unwrap implements wrap.Unwrapper and returns the underlying server instance as an unknown type.

func (*ApiWrapper) UnwrapServer

func (w *ApiWrapper) UnwrapServer() traits.LightApiServer

UnwrapServer returns the underlying server instance.

func (*ApiWrapper) UnwrapService

func (w *ApiWrapper) UnwrapService() (grpc.ClientConnInterface, grpc.ServiceDesc)

type Group

type Group struct {
	traits.UnimplementedLightApiServer

	ReadExecution  group.ExecutionStrategy
	WriteExecution group.ExecutionStrategy
	// contains filtered or unexported fields
}

Group combines multiple named devices into a single named device.

func NewGroup

func NewGroup(impl traits.LightApiClient, members ...string) *Group

NewGroup creates a new Group instance with ExecutionStrategyAll for both reads and writes.

func (*Group) GetBrightness

func (s *Group) GetBrightness(ctx context.Context, request *traits.GetBrightnessRequest) (*traits.Brightness, error)

func (*Group) PullBrightness

func (s *Group) PullBrightness(request *traits.PullBrightnessRequest, server traits.LightApi_PullBrightnessServer) error

func (*Group) UpdateBrightness

func (s *Group) UpdateBrightness(ctx context.Context, request *traits.UpdateBrightnessRequest) (*traits.Brightness, error)

type InfoRouter

type InfoRouter struct {
	traits.UnimplementedLightInfoServer

	router.Router
}

InfoRouter is a traits.LightInfoServer that allows routing named requests to specific traits.LightInfoClient

func NewInfoRouter

func NewInfoRouter(opts ...router.Option) *InfoRouter

func (*InfoRouter) Add

func (r *InfoRouter) Add(name string, client any) any

Add extends Router.Add to panic if client is not of type traits.LightInfoClient.

func (*InfoRouter) AddLightInfoClient

func (r *InfoRouter) AddLightInfoClient(name string, client traits.LightInfoClient) traits.LightInfoClient

func (*InfoRouter) DescribeBrightness

func (r *InfoRouter) DescribeBrightness(ctx context.Context, request *traits.DescribeBrightnessRequest) (*traits.BrightnessSupport, error)

func (*InfoRouter) GetLightInfoClient

func (r *InfoRouter) GetLightInfoClient(name string) (traits.LightInfoClient, error)

func (*InfoRouter) HoldsType

func (r *InfoRouter) HoldsType(client any) bool

func (*InfoRouter) Register

func (r *InfoRouter) Register(server grpc.ServiceRegistrar)

func (*InfoRouter) RemoveLightInfoClient

func (r *InfoRouter) RemoveLightInfoClient(name string) traits.LightInfoClient

type InfoWrapper

type InfoWrapper struct {
	traits.LightInfoClient
	// contains filtered or unexported fields
}

func WrapInfo

func WrapInfo(server traits.LightInfoServer) *InfoWrapper

WrapInfo adapts a traits.LightInfoServer and presents it as a traits.LightInfoClient

func (*InfoWrapper) Unwrap

func (w *InfoWrapper) Unwrap() any

Unwrap implements wrap.Unwrapper and returns the underlying server instance as an unknown type.

func (*InfoWrapper) UnwrapServer

func (w *InfoWrapper) UnwrapServer() traits.LightInfoServer

UnwrapServer returns the underlying server instance.

func (*InfoWrapper) UnwrapService

func (w *InfoWrapper) UnwrapService() (grpc.ClientConnInterface, grpc.ServiceDesc)

type MemoryDevice

type MemoryDevice struct {
	traits.UnimplementedLightApiServer
	// contains filtered or unexported fields
}

MemoryDevice implements the LightApiServer interface for a single device by storing state in memory.

func NewMemoryDevice

func NewMemoryDevice() *MemoryDevice

func (*MemoryDevice) GetBrightness

func (*MemoryDevice) PullBrightness

func (*MemoryDevice) UpdateBrightness

func (s *MemoryDevice) UpdateBrightness(ctx context.Context, request *traits.UpdateBrightnessRequest) (*traits.Brightness, error)

type Model

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

func NewModel

func NewModel(opts ...resource.Option) *Model

func (*Model) GetBrightness

func (m *Model) GetBrightness(opts ...resource.ReadOption) (*traits.Brightness, error)

func (*Model) ListPresets

func (m *Model) ListPresets() []*traits.LightPreset

func (*Model) PullBrightness

func (m *Model) PullBrightness(ctx context.Context, opts ...resource.ReadOption) <-chan PullBrightnessChange

func (*Model) UpdateBrightness

func (m *Model) UpdateBrightness(light *traits.Brightness, opts ...resource.WriteOption) (*traits.Brightness, error)

type ModelOption

type ModelOption interface {
	resource.Option
	// contains filtered or unexported methods
}

ModelOption defined the base type for all options that apply to this traits model.

type ModelServer

type ModelServer struct {
	traits.UnimplementedLightApiServer
	traits.UnimplementedLightInfoServer
	// contains filtered or unexported fields
}

func NewModelServer

func NewModelServer(model *Model) *ModelServer

func (*ModelServer) DescribeBrightness

func (*ModelServer) GetBrightness

func (*ModelServer) PullBrightness

func (*ModelServer) Register

func (s *ModelServer) Register(server grpc.ServiceRegistrar)

func (*ModelServer) Unwrap

func (s *ModelServer) Unwrap() any

func (*ModelServer) UpdateBrightness

func (s *ModelServer) UpdateBrightness(_ context.Context, request *traits.UpdateBrightnessRequest) (*traits.Brightness, error)

type PullBrightnessChange

type PullBrightnessChange struct {
	Value      *traits.Brightness
	ChangeTime time.Time
}

Jump to

Keyboard shortcuts

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