bms

package
v0.0.0-test-multiarch Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const AutoType = "bms"

Variables

View Source
var Factory auto.Factory = factory{}

Functions

func CountActions

func CountActions(actions Actions) (Actions, *ActionCounts)

CountActions wraps an Actions and counts the number of invocations.

Types

type ActionCounts

type ActionCounts struct {
	TotalWrites int

	ModeUpdates map[string]map[string][]DeviceName // [key][value]names
	ModeWrites  []string

	AirTemperatureUpdates map[float64][]DeviceName // [setPoint]names
	AirTemperatureWrites  []string
}

func (ActionCounts) Changes

func (a ActionCounts) Changes() []string

type Actions

type Actions interface {
	UpdateAirTemperature(ctx context.Context, req *traits.UpdateAirTemperatureRequest, ws *WriteState) error
	UpdateModeValues(ctx context.Context, req *traits.UpdateModeValuesRequest, ws *WriteState) error
}

Actions defines the only side effects the automation can have. This is intended to allow easier testing of the business logic, a bit like a DAO would for database access.

func CacheWriteAction

func CacheWriteAction(actions Actions, cacheExpiry time.Duration) Actions

CacheWriteAction wraps an Actions and caches successful writes for cacheExpiry. Calling action methods with the same arguments will return the cached result and not perform the write so long as the cache is not expired.

func ClientActions

func ClientActions(clients node.Clienter) (Actions, error)

ClientActions creates a new Actions backed by node.Clienter clients.

func LogActions

func LogActions(actions Actions, logger *zap.Logger) Actions

LogActions wraps an Actions and logs all invocations.

type AirTemperaturePatches

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

AirTemperaturePatches contributes patches for changing the state based on occupancy sensor readings.

func (*AirTemperaturePatches) Poll

func (o *AirTemperaturePatches) Poll(ctx context.Context, changes chan<- Patcher) error

func (*AirTemperaturePatches) Pull

func (o *AirTemperaturePatches) Pull(ctx context.Context, changes chan<- Patcher) error

func (*AirTemperaturePatches) Subscribe

func (o *AirTemperaturePatches) Subscribe(ctx context.Context, changes chan<- Patcher) error

type Auto

type Auto struct {
	*service.Service[config.Root]
	// contains filtered or unexported fields
}

type DeviceName

type DeviceName = string

type MeanOATempPatches

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

MeanOATempPatches emits MeanOATemp patches based on an exponential running mean. During Subscribe it will attempt to fetch historical data from the device to seed the running mean before pulling updated data from the device. If this fails then the initial mean will be potentially inaccurate.

func (*MeanOATempPatches) Subscribe

func (m *MeanOATempPatches) Subscribe(ctx context.Context, changes chan<- Patcher) error

type ModePatches

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

ModePatches contributes patches for changing the state based on mode changes. Note that read times are recorded against _unique mode value updates_, not against sends from the remote device. This helps with tracking as we can see when a mode key last changed its value, this is more important than when any mode key changed its value.

func (*ModePatches) Poll

func (o *ModePatches) Poll(ctx context.Context, changes chan<- Patcher) error

func (*ModePatches) Pull

func (o *ModePatches) Pull(ctx context.Context, changes chan<- Patcher) error

func (*ModePatches) Subscribe

func (o *ModePatches) Subscribe(ctx context.Context, changes chan<- Patcher) error

type NilActions

type NilActions struct{}

NilActions is an Actions that has no side effects. Actions are still recorded in the WriteState.

func (NilActions) UpdateAirTemperature

func (_ NilActions) UpdateAirTemperature(_ context.Context, req *traits.UpdateAirTemperatureRequest, ws *WriteState) error

func (NilActions) UpdateModeValues

func (_ NilActions) UpdateModeValues(_ context.Context, req *traits.UpdateModeValuesRequest, ws *WriteState) error

type OccupancySensorPatches

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

OccupancySensorPatches contributes patches for changing the state based on occupancy sensor readings.

func (*OccupancySensorPatches) Poll

func (o *OccupancySensorPatches) Poll(ctx context.Context, changes chan<- Patcher) error

func (*OccupancySensorPatches) Pull

func (o *OccupancySensorPatches) Pull(ctx context.Context, changes chan<- Patcher) error

func (*OccupancySensorPatches) Subscribe

func (o *OccupancySensorPatches) Subscribe(ctx context.Context, changes chan<- Patcher) error

type PatchFunc

type PatchFunc func(s *ReadState)

func (PatchFunc) Patch

func (p PatchFunc) Patch(s *ReadState)

type Patcher

type Patcher interface {
	Patch(s *ReadState)
}

Patcher represents a single patch that adjusts ReadState.

type ReadState

type ReadState struct {
	Config    config.Root
	Now       func() time.Time
	StartTime time.Time // when was the automation started

	AirTemperature map[DeviceName]Value[*traits.AirTemperature]
	Modes          map[DeviceName]map[string]Value[string]
	Occupancy      map[DeviceName]Value[*traits.Occupancy]

	MeanOATemp *types.Temperature // mean outdoor air temperature
}

func NewReadState

func NewReadState() *ReadState

func (*ReadState) Clone

func (s *ReadState) Clone() *ReadState

type UnexpectedResponseError

type UnexpectedResponseError struct {
	Message   string
	Want, Got any
}

func (UnexpectedResponseError) Error

func (u UnexpectedResponseError) Error() string

type Value

type Value[V any] struct {
	V   V
	At  time.Time // Read or write time
	Err error     // an error associated with either the read or write
	Hit int       // how many times did we hit the cache, or has the value been updated
}

Value represents either a value read from a device or a value written to a device.

type WriteState

type WriteState struct {
	Now     func() time.Time // override for testing
	T0, T1  time.Time
	Reasons []string

	Modes           map[DeviceName]Value[*traits.ModeValues]
	AirTemperatures map[DeviceName]Value[*traits.AirTemperature]
}

func NewWriteState

func NewWriteState() *WriteState

func (*WriteState) AddReason

func (ws *WriteState) AddReason(reason string)

func (*WriteState) AddReasonf

func (ws *WriteState) AddReasonf(format string, args ...any)

func (*WriteState) After

func (ws *WriteState) After()

After should be called after processing has completed.

func (*WriteState) Before

func (ws *WriteState) Before()

Before should be called before processing starts.

func (*WriteState) CopyFromReadState

func (ws *WriteState) CopyFromReadState(rs *ReadState)

CopyFromReadState copies the values from rs into ws. This keeps the write state up to date with information we've explicitly read, which can then be used to make cache decisions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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