Documentation ¶
Index ¶
- Constants
- Variables
- func CountActions(actions Actions) (Actions, *ActionCounts)
- type ActionCounts
- type Actions
- type AirTemperaturePatches
- type Auto
- type DeviceName
- type MeanOATempPatches
- type ModePatches
- type NilActions
- type OccupancySensorPatches
- type PatchFunc
- type Patcher
- type ReadState
- type UnexpectedResponseError
- type Value
- type WriteState
Constants ¶
const AutoType = "bms"
Variables ¶
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 ¶
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 ¶
ClientActions creates a new Actions backed by node.Clienter clients.
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
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.
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
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
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
type UnexpectedResponseError ¶
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.