site

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package site builds the effective site model from configured connections, devices and meters plus their profiles: roles, categories, hierarchy, the series catalogue and the capabilities the UI is built from (spec 2, 3, 11).

Index

Constants

View Source
const (
	KindGauge  = 1
	KindEnergy = 2

	OriginMeasured   = 1
	OriginIntegrated = 2
	OriginShare      = 3
)

Series kinds and origins (spec 7.1).

View Source
const (
	ChannelGridImportRaw = "grid_import_raw"
	ChannelGridExportRaw = "grid_export_raw"
	ChannelGridCancelled = "grid_cancelled"
)

Hidden channel names of app netting (spec 6).

View Source
const (
	QuantityPV          = "site/pv"
	QuantityGridIn      = "site/grid_in"
	QuantityGridOut     = "site/grid_out"
	QuantityBatteryIn   = "site/battery_in"
	QuantityBatteryOut  = "site/battery_out"
	QuantitySoC         = "site/soc"
	QuantityConsumption = "site/consumption"
	QuantityHouseRest   = "site/house_rest"
	QuantityLoadpoints  = "site/loadpoints/"
)

Site quantity IDs (spec 2). Loadpoint quantities are QuantityLoadpoints + category.

View Source
const CategoryOther = "other"

CategoryOther is the default consumer category.

View Source
const ParentSite = "site"

ParentSite is the parent ID of meters directly under the site.

Variables

This section is empty.

Functions

func IntegratedChannels

func IntegratedChannels(role string) (pos, neg string)

IntegratedChannels returns the energy channels that power of a role is integrated into when its block has no energy channel: for positive and for negative power.

func LiveKey

func LiveKey(quantity string) string

LiveKey returns the live key of a site quantity (spec 9.3): power quantities carry the suffix ".power", the state of charge is the bare quantity ID.

func ParseAddress

func ParseAddress(addr string) (key, scheme string, err error)

ParseAddress normalises a connection address and returns its key and scheme.

Types

type Capabilities

type Capabilities struct {
	PV         int
	Battery    int
	Grid       bool
	Backup     bool
	Loadpoints map[string]int // per category, consumers directly under the site
}

Capabilities summarises what the site has (spec 9.1 /api/v1/site).

type Connection

type Connection struct {
	Address string
	Scheme  string // tcp | rtu | http | https
	Timeout time.Duration
	Serial  Serial
	Devices []string // sorted device IDs
}

Connection is one physical access path shared by its devices.

type ConnectionSpec

type ConnectionSpec struct {
	Address string
	Timeout time.Duration
	Serial  Serial
}

ConnectionSpec is a configured connection.

type Device

type Device struct {
	ID         string
	Connection string // Connection address key
	Unit       int
	Profile    *profile.Loaded
	Interval   time.Duration
	Timeout    time.Duration
	Read       string // effective read mode (modbus)
	Rollover   string
	Netting    string // effective netting for its grid meter
	History    []string
	User       string
	Password   string // passed to the transport, never logged
	Insecure   bool
	Meters     []string // sorted meter IDs provided by this device
	Blocks     []string // sorted profile blocks its meters use; only these are polled
}

Device is a polled device with its resolved profile and options.

type DeviceSpec

type DeviceSpec struct {
	Connection string
	Address    string
	Unit       int
	Profile    *profile.Loaded
	Interval   time.Duration
	Timeout    time.Duration
	Read       string
	Rollover   string
	Netting    string
	History    []string
	User       string
	Password   string // passed to the transport, never logged
	Insecure   bool
}

DeviceSpec is a configured device; Connection or an inline Address (plus Timeout) is set.

type Error

type Error struct {
	Problems []Problem
}

Error lists every problem found while building the site.

func (*Error) Error

func (e *Error) Error() string

type Meter

type Meter struct {
	ID         string
	Device     string
	Source     string
	Role       string
	Category   string
	Parent     string
	Label      string
	KWp        float64
	CapacityWh float64
	Critical   bool
	Block      profile.Block
}

Meter is a logical measuring point.

func (*Meter) Nested

func (m *Meter) Nested() bool

Nested reports whether the meter sits inside another meter (a PV string below its total, a consumer sub-meter); site quantities count only meters that are not nested.

type MeterSpec

type MeterSpec struct {
	Device     string
	Source     string
	Role       string
	Category   string
	Parent     string
	Label      string
	KWp        float64
	CapacityWh float64
	Critical   bool
}

MeterSpec is a configured meter; empty Role and Category come from the profile block.

type Problem

type Problem struct {
	Path    string
	Message string
}

Problem is one domain validation finding with its config path.

type Serial

type Serial struct {
	Speed    int
	DataBits int
	Parity   string
	StopBits int
}

Serial holds RTU line parameters.

type SeriesInfo

type SeriesInfo struct {
	Meter   string
	Channel string
	Kind    int
	Origin  int
	Hidden  bool
	Unit    string
}

SeriesInfo describes one stored series of a meter channel.

func (SeriesInfo) Key

func (s SeriesInfo) Key() string

Key returns "<meter>/<channel>".

type Site

type Site struct {
	Name        string
	Rev         int64                  // config_rev of the UI configuration the site was built from
	Connections map[string]*Connection // keyed by normalised address
	Devices     map[string]*Device
	Meters      map[string]*Meter
}

Site is the effective, validated site model.

func Build

func Build(spec Spec) (*Site, error)

Build validates the spec against the profiles and returns the effective site. All problems are reported at once as *Error.

func (*Site) Capabilities

func (s *Site) Capabilities() Capabilities

Capabilities counts meters per role and loadpoints per category.

func (*Site) LiveKeys

func (s *Site) LiveKeys() []string

LiveKeys returns every key a live client may subscribe to: all channels of every meter ("<meter>/<channel>") and the live site quantities, sorted.

func (*Site) Quantities

func (s *Site) Quantities() []string

Quantities returns the site quantities this site has, in a fixed order: PV only with a pv meter, battery quantities only with a battery, one loadpoint quantity per category present directly under the site.

func (*Site) Series

func (s *Site) Series() []SeriesInfo

Series returns the stored series of the site, sorted by key: historised channels of every meter plus the hidden inputs of app netting.

type Spec

type Spec struct {
	Name        string
	Connections map[string]ConnectionSpec
	Devices     map[string]DeviceSpec
	Meters      map[string]MeterSpec
}

Spec is the input of Build, mapped by internal/app from the configuration.

Jump to

Keyboard shortcuts

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