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
- func IntegratedChannels(role string) (pos, neg string)
- func LiveKey(quantity string) string
- func ParseAddress(addr string) (key, scheme string, err error)
- type Capabilities
- type Connection
- type ConnectionSpec
- type Device
- type DeviceSpec
- type Error
- type Meter
- type MeterSpec
- type Problem
- type Serial
- type SeriesInfo
- type Site
- type Spec
Constants ¶
const ( KindGauge = 1 KindEnergy = 2 OriginMeasured = 1 OriginIntegrated = 2 )
Series kinds and origins (spec 7.1).
const ( ChannelGridImportRaw = "grid_import_raw" ChannelGridExportRaw = "grid_export_raw" ChannelGridCancelled = "grid_cancelled" )
Hidden channel names of app netting (spec 6).
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.
const CategoryOther = "other"
CategoryOther is the default consumer category.
const ParentSite = "site"
ParentSite is the parent ID of meters directly under the site.
Variables ¶
This section is empty.
Functions ¶
func IntegratedChannels ¶
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 ¶
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 ¶
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 ¶
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.
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.
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 SeriesInfo ¶
SeriesInfo describes one stored series of a 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 ¶
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 ¶
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 ¶
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.