fanspeed

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: 14 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

DefaultModelOptions holds the default options for the model.

View Source
var DefaultPresets = []Preset{
	{Name: "off", Percentage: 0},
	{Name: "low", Percentage: 15},
	{Name: "med", Percentage: 40},
	{Name: "high", Percentage: 75},
	{Name: "full", Percentage: 100},
}

Functions

func WithFanSpeedApiClientFactory

func WithFanSpeedApiClientFactory(f func(name string) (traits.FanSpeedApiClient, error)) router.Option

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

func WithFanSpeedInfoClientFactory

func WithFanSpeedInfoClientFactory(f func(name string) (traits.FanSpeedInfoClient, error)) router.Option

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

func WithFanSpeedOption

func WithFanSpeedOption(opts ...resource.Option) resource.Option

WithFanSpeedOption configures the fanSpeed resource of the model.

func WithInitialFanSpeed

func WithInitialFanSpeed(fanSpeed *traits.FanSpeed) resource.Option

WithInitialFanSpeed returns an option that configures the model to initialise with the given fan speed.

func WithPresets

func WithPresets(presets ...Preset) resource.Option

WithPresets returns an option that configures the model to use the given presets.

Types

type ApiRouter

ApiRouter is a traits.FanSpeedApiServer that allows routing named requests to specific traits.FanSpeedApiClient

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

func (*ApiRouter) AddFanSpeedApiClient

func (r *ApiRouter) AddFanSpeedApiClient(name string, client traits.FanSpeedApiClient) traits.FanSpeedApiClient

func (*ApiRouter) GetFanSpeed

func (r *ApiRouter) GetFanSpeed(ctx context.Context, request *traits.GetFanSpeedRequest) (*traits.FanSpeed, error)

func (*ApiRouter) GetFanSpeedApiClient

func (r *ApiRouter) GetFanSpeedApiClient(name string) (traits.FanSpeedApiClient, error)

func (*ApiRouter) HoldsType

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

func (*ApiRouter) PullFanSpeed

func (*ApiRouter) Register

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

func (*ApiRouter) RemoveFanSpeedApiClient

func (r *ApiRouter) RemoveFanSpeedApiClient(name string) traits.FanSpeedApiClient

func (*ApiRouter) ReverseFanSpeedDirection

func (r *ApiRouter) ReverseFanSpeedDirection(ctx context.Context, request *traits.ReverseFanSpeedDirectionRequest) (*traits.FanSpeed, error)

func (*ApiRouter) UpdateFanSpeed

func (r *ApiRouter) UpdateFanSpeed(ctx context.Context, request *traits.UpdateFanSpeedRequest) (*traits.FanSpeed, error)

type ApiWrapper

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

func WrapApi

func WrapApi(server traits.FanSpeedApiServer) *ApiWrapper

WrapApi adapts a traits.FanSpeedApiServer and presents it as a traits.FanSpeedApiClient

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

UnwrapServer returns the underlying server instance.

func (*ApiWrapper) UnwrapService

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

type FanSpeedChange

type FanSpeedChange struct {
	Value      *traits.FanSpeed
	ChangeTime time.Time
}

type InfoRouter

InfoRouter is a traits.FanSpeedInfoServer that allows routing named requests to specific traits.FanSpeedInfoClient

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

func (*InfoRouter) AddFanSpeedInfoClient

func (r *InfoRouter) AddFanSpeedInfoClient(name string, client traits.FanSpeedInfoClient) traits.FanSpeedInfoClient

func (*InfoRouter) DescribeFanSpeed

func (r *InfoRouter) DescribeFanSpeed(ctx context.Context, request *traits.DescribeFanSpeedRequest) (*traits.FanSpeedSupport, error)

func (*InfoRouter) GetFanSpeedInfoClient

func (r *InfoRouter) GetFanSpeedInfoClient(name string) (traits.FanSpeedInfoClient, error)

func (*InfoRouter) HoldsType

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

func (*InfoRouter) Register

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

func (*InfoRouter) RemoveFanSpeedInfoClient

func (r *InfoRouter) RemoveFanSpeedInfoClient(name string) traits.FanSpeedInfoClient

type InfoWrapper

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

func WrapInfo

func WrapInfo(server traits.FanSpeedInfoServer) *InfoWrapper

WrapInfo adapts a traits.FanSpeedInfoServer and presents it as a traits.FanSpeedInfoClient

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

UnwrapServer returns the underlying server instance.

func (*InfoWrapper) UnwrapService

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

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 DefaultPresets presets.

func NewModel

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

NewModel constructs a Model with default values using the first of DefaultPresets.

func (*Model) DeriveValues

func (m *Model) DeriveValues(old, new proto.Message)

DeriveValues derives values that haven't been set from those that have. For example setting percentage when the preset changes. Updated values will be set on new.

func (*Model) FanSpeed

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

FanSpeed gets the current fan speed.

func (*Model) PullFanSpeed

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

func (*Model) UpdateFanSpeed

func (m *Model) UpdateFanSpeed(fanSpeed *traits.FanSpeed, opts ...resource.WriteOption) (*traits.FanSpeed, error)

UpdateFanSpeed changes the fan speed. Provide write options to support features like relative changes. Related properties of the fan speed will be set automatically, for example if the preset changes then the percentage and preset index are also changed. Providing a resource.InterceptAfter option will disable related property updating. Using DeriveValues can re-enable related property computation if needed.

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.UnimplementedFanSpeedApiServer
	// contains filtered or unexported fields
}

ModelServer adapts a Model as a traits.FanSpeedApiServer.

func NewModelServer

func NewModelServer(model *Model) *ModelServer

func (*ModelServer) GetFanSpeed

func (s *ModelServer) GetFanSpeed(_ context.Context, request *traits.GetFanSpeedRequest) (*traits.FanSpeed, error)

func (*ModelServer) PullFanSpeed

func (*ModelServer) Register

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

func (*ModelServer) ReverseFanSpeedDirection

func (s *ModelServer) ReverseFanSpeedDirection(ctx context.Context, request *traits.ReverseFanSpeedDirectionRequest) (*traits.FanSpeed, error)

func (*ModelServer) Unwrap

func (s *ModelServer) Unwrap() any

func (*ModelServer) UpdateFanSpeed

func (s *ModelServer) UpdateFanSpeed(_ context.Context, request *traits.UpdateFanSpeedRequest) (*traits.FanSpeed, error)

type Preset

type Preset struct {
	Name       string
	Percentage float32
}

Jump to

Keyboard shortcuts

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