mode

package
v0.0.0-...-8846729 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 11 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultModes = &traits.Modes{
	Modes: []*traits.Modes_Mode{
		{Name: "temperature", Ordered: true, Values: []*traits.Modes_Value{
			{Name: "delicates"},
			{Name: "medium"},
			{Name: "whites"},
		}},
		{Name: "spin", Ordered: false, Values: []*traits.Modes_Value{
			{Name: "auto"},
			{Name: "slow"},
			{Name: "fast"},
		}},
	},
}

DefaultModes define the available modes of a Model if none are provided.

Functions

func WithModeApiClientFactory

func WithModeApiClientFactory(f func(name string) (traits.ModeApiClient, error)) router.Option

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

func WithModeInfoClientFactory

func WithModeInfoClientFactory(f func(name string) (traits.ModeInfoClient, error)) router.Option

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

Types

type ApiRouter

type ApiRouter struct {
	traits.UnimplementedModeApiServer

	router.Router
}

ApiRouter is a traits.ModeApiServer that allows routing named requests to specific traits.ModeApiClient

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.ModeApiClient.

func (*ApiRouter) AddModeApiClient

func (r *ApiRouter) AddModeApiClient(name string, client traits.ModeApiClient) traits.ModeApiClient

func (*ApiRouter) GetModeApiClient

func (r *ApiRouter) GetModeApiClient(name string) (traits.ModeApiClient, error)

func (*ApiRouter) GetModeValues

func (r *ApiRouter) GetModeValues(ctx context.Context, request *traits.GetModeValuesRequest) (*traits.ModeValues, error)

func (*ApiRouter) HoldsType

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

func (*ApiRouter) PullModeValues

func (r *ApiRouter) PullModeValues(request *traits.PullModeValuesRequest, server traits.ModeApi_PullModeValuesServer) error

func (*ApiRouter) Register

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

func (*ApiRouter) RemoveModeApiClient

func (r *ApiRouter) RemoveModeApiClient(name string) traits.ModeApiClient

func (*ApiRouter) UpdateModeValues

func (r *ApiRouter) UpdateModeValues(ctx context.Context, request *traits.UpdateModeValuesRequest) (*traits.ModeValues, error)

type ApiWrapper

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

func WrapApi

func WrapApi(server traits.ModeApiServer) *ApiWrapper

WrapApi adapts a traits.ModeApiServer and presents it as a traits.ModeApiClient

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.ModeApiServer

UnwrapServer returns the underlying server instance.

func (*ApiWrapper) UnwrapService

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

type InfoRouter

type InfoRouter struct {
	traits.UnimplementedModeInfoServer

	router.Router
}

InfoRouter is a traits.ModeInfoServer that allows routing named requests to specific traits.ModeInfoClient

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.ModeInfoClient.

func (*InfoRouter) AddModeInfoClient

func (r *InfoRouter) AddModeInfoClient(name string, client traits.ModeInfoClient) traits.ModeInfoClient

func (*InfoRouter) DescribeModes

func (r *InfoRouter) DescribeModes(ctx context.Context, request *traits.DescribeModesRequest) (*traits.ModesSupport, error)

func (*InfoRouter) GetModeInfoClient

func (r *InfoRouter) GetModeInfoClient(name string) (traits.ModeInfoClient, error)

func (*InfoRouter) HoldsType

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

func (*InfoRouter) Register

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

func (*InfoRouter) RemoveModeInfoClient

func (r *InfoRouter) RemoveModeInfoClient(name string) traits.ModeInfoClient

type InfoWrapper

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

func WrapInfo

func WrapInfo(server traits.ModeInfoServer) *InfoWrapper

WrapInfo adapts a traits.ModeInfoServer and presents it as a traits.ModeInfoClient

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.ModeInfoServer

UnwrapServer returns the underlying server instance.

func (*InfoWrapper) UnwrapService

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

type ModeValuesChange

type ModeValuesChange struct {
	Value      *traits.ModeValues
	ChangeTime time.Time
}

type Model

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

Model provides a data structure for supporting the Fan Speed trait. Unless configured otherwise, this model supports DefaultModes presets.

func NewModel

func NewModel() *Model

NewModel is like NewModelModes(DefaultModes).

func NewModelModes

func NewModelModes(modes *traits.Modes) *Model

NewModelModes constructs a Model with the given modes. The first value of each mode will be selected.

func (*Model) AvailableValues

func (m *Model) AvailableValues(modeName string) []*traits.Modes_Value

func (*Model) ModeValues

func (m *Model) ModeValues(opts ...resource.ReadOption) *traits.ModeValues

ModeValues gets the current mode values.

func (*Model) Modes

func (m *Model) Modes() *traits.Modes

func (*Model) PullModeValues

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

func (*Model) UpdateModeValues

func (m *Model) UpdateModeValues(values *traits.ModeValues, opts ...resource.WriteOption) (*traits.ModeValues, error)

type ModelServer

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

ModelServer adapts a Model as a traits.ModeApiServer. Relative mode value updates will wrap around in both directions.

func NewModelServer

func NewModelServer(model *Model) *ModelServer

func (*ModelServer) GetModeValues

func (m *ModelServer) GetModeValues(_ context.Context, request *traits.GetModeValuesRequest) (*traits.ModeValues, error)

func (*ModelServer) PullModeValues

func (*ModelServer) Register

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

func (*ModelServer) Unwrap

func (m *ModelServer) Unwrap() any

func (*ModelServer) UpdateModeValues

func (m *ModelServer) UpdateModeValues(_ context.Context, request *traits.UpdateModeValuesRequest) (*traits.ModeValues, error)

Jump to

Keyboard shortcuts

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