rules

package
v0.18.4 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetZoneState added in v0.17.0

func GetZoneState(zoneName string) func(u poller.Update) (State, error)

GetZoneState returns a function that returns the State of a zone, named zoneName, from a poller.Update.

Types

type Action added in v0.17.0

type Action interface {
	IsState(state State) bool
	IsAction(action Action) bool
	Delay() time.Duration
	Reason() string

	Description(includeDelay bool) string
	Do(context.Context, TadoClient, *slog.Logger) error
	slog.LogValuer
	// contains filtered or unexported methods
}

type Args added in v0.17.0

type Args map[string]any

type Device added in v0.17.0

type Device struct {
	Name string
	Home bool
}

type Devices added in v0.17.0

type Devices []Device

type HomeState added in v0.17.0

type HomeState struct {
	Overlay bool
	Home    bool
}

type Rule added in v0.17.0

type Rule interface {
	Evaluate(State) (Action, error)
}

A Rule determines the next Action, given the current State.

func LoadHomeRule added in v0.17.0

func LoadHomeRule(cfg RuleConfiguration) (Rule, error)

func LoadZoneRule added in v0.17.0

func LoadZoneRule(zoneName string, cfg RuleConfiguration) (Rule, error)

type RuleConfiguration added in v0.17.0

type RuleConfiguration struct {
	Args   Args         `yaml:"args,omitempty"`
	Script ScriptConfig `yaml:"script"`
	Name   string       `yaml:"name"`
	Users  []string     `yaml:"users,omitempty"`
}

type Rules

type Rules struct {
	GetState func(update poller.Update) (State, error)
	// contains filtered or unexported fields
}

Rules groups a set of rules for a zone or home. The Rules' Evaluate method runs through all contained rules and determines the required action, given the current State. The GetState function takes a poller.Update and returns the current State.

func LoadHomeRules added in v0.17.0

func LoadHomeRules(config []RuleConfiguration) (Rules, error)

LoadHomeRules create Rules as per config, for a home.

func LoadZoneRules added in v0.17.0

func LoadZoneRules(zoneName string, config []RuleConfiguration) (Rules, error)

LoadZoneRules create Rules as per config, for a zone named zoneName.

func (Rules) Count added in v0.17.0

func (r Rules) Count() int

func (Rules) Evaluate

func (r Rules) Evaluate(currentState State) (Action, error)

Evaluate takes the current update, determines the next Action for each rule and returns the first Action required. If no rules require an action, it returns an Action for that current state, with the Reason listing all reasons why an action isn't required.

type ScriptConfig added in v0.17.0

type ScriptConfig struct {
	Packaged string `yaml:"packaged,omitempty"`
	Text     string `yaml:"text,omitempty"`
	Path     string `yaml:"path,omitempty"`
}

type State added in v0.17.0

type State struct {
	Devices   Devices
	HomeId    tado.HomeId
	ZoneId    tado.ZoneId
	HomeState HomeState
	ZoneState ZoneState
}

State is the input argument for Evaluate() functions. It summarizes the state of a Tadoº installation, i.e. the state of the house, its registered mobile devices and its zones.

func GetHomeState added in v0.17.0

func GetHomeState(u poller.Update) (State, error)

GetHomeState returns the State of the home in a poller.Update. Only one home is supported.

type TadoClient added in v0.17.0

type TadoClient interface {
	SetPresenceLockWithResponse(ctx context.Context, homeId tado.HomeId, body tado.SetPresenceLockJSONRequestBody, reqEditors ...tado.RequestEditorFn) (*tado.SetPresenceLockResponse, error)
	DeletePresenceLockWithResponse(ctx context.Context, homeId tado.HomeId, reqEditors ...tado.RequestEditorFn) (*tado.DeletePresenceLockResponse, error)
	SetZoneOverlayWithResponse(ctx context.Context, homeId tado.HomeId, zoneId tado.ZoneId, body tado.SetZoneOverlayJSONRequestBody, reqEditors ...tado.RequestEditorFn) (*tado.SetZoneOverlayResponse, error)
	DeleteZoneOverlayWithResponse(ctx context.Context, homeId tado.HomeId, zoneId tado.ZoneId, reqEditors ...tado.RequestEditorFn) (*tado.DeleteZoneOverlayResponse, error)
}

type ZoneState added in v0.17.0

type ZoneState struct {
	Overlay bool
	Heating bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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