manifest

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package manifest enables declarative configuration of AHA devices.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	Perform(a aha) error
}

Action is one operation on the home automation system.

type Applier

type Applier interface {
	// Apply performs the changes necessary to transition from src to target configuration. If the target plan
	// could be realized, it returns an error. If the plan was applied successfully, it returns null.
	Apply(src, target *Plan) error
}

Applier defines the interface to apply a plan to the AHA system.

func DryRunner

func DryRunner() Applier

DryRunner is an Applier that only plans changes to the AHA system.

func NewApplier added in v1.4.17

func NewApplier(f aha) Applier

NewApplier is an Applier that performs changes to the AHA system via the HTTP API.

Example

Using an Applier, one can change the config of devices in one run.

package main

import (
	"net/url"

	"github.com/coolduke/fritzctl/fritz"
	"github.com/coolduke/fritzctl/manifest"
)

func main() {
	h := fritz.NewHomeAuto(fritz.URL(&url.URL{
		Host:   "fritz-box.home",
		Scheme: "https",
	}))
	a := manifest.NewApplier(h)
	a.Apply(&manifest.Plan{
		Switches: []manifest.Switch{{Name: "Switch1", State: false}, {Name: "Switch2", State: false}},
	}, &manifest.Plan{
		Switches: []manifest.Switch{{Name: "Switch1", State: false}, {Name: "Switch2", State: false}},
	})
}
Output:

type Exporter

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

Exporter allows exporting of a Plan.

func ExporterTo

func ExporterTo(w io.Writer) *Exporter

ExporterTo creates an Exporter, which writes to the given io.Writer.

func (*Exporter) Export

func (e *Exporter) Export(plan *Plan) error

Export performs the export.

type Plan

type Plan struct {
	Switches    []Switch     // The power switches.
	Thermostats []Thermostat // The HKR devices.
}

Plan represents the data model of an absolute state of the fritz smart home.

func ConvertDevicelist

func ConvertDevicelist(l *fritz.Devicelist) *Plan

ConvertDevicelist converts a fritz.Devicelist to a Plan.

func Parse

func Parse(r io.Reader) (*Plan, error)

Parse takes an io.Reader and marshals the contents as a Plan, returning a pointer it.

func ParseFile

func ParseFile(filename string) (*Plan, error)

ParseFile opens a file and marshals the contents as a Plan, returning a pointer it.

type Planner

type Planner interface {
	Plan(src, target *Plan) ([]Action, error)
}

Planner represents an execution planner, returning actions to transition from a src to a target state.

func TargetBasedPlanner

func TargetBasedPlanner(scf switchCommandFactory, tcf thermostatCommandFactory) Planner

TargetBasedPlanner creates a Planner that only focuses on target state. Devices in the source state that are not referenced in the target will be left untouched.

type Switch

type Switch struct {
	Name  string // Name of the switch.
	State bool   // On (true) or off (false).
}

Switch represents the state of a switch.

type Thermostat

type Thermostat struct {
	Name        string  // Name of the device.
	Temperature float64 // The temperature in °C.
}

Thermostat represents the state of a HKR device.

Jump to

Keyboard shortcuts

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