collector

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EthernetCallbackID uint64 = math.MaxUint64
)

Variables

View Source
var Version string

Functions

func DeviceName

func DeviceName(id uint16) string

Types

type BrickData

type BrickData struct {
	Address string
	Devices map[string]*Device
	Values  map[string]map[int]Value
}

BrickData are discovered devices and their values

type BrickdCollector

type BrickdCollector struct {
	sync.RWMutex
	Address        string
	Password       string
	Data           *BrickData
	Registry       map[string][]Register
	Connection     ipconnection.IPConnection
	Values         chan Value
	Devices        map[uint16]RegisterFunc
	CallbackPeriod uint32
	IgnoredUIDs    []string
	Labels         map[string]string
	SensorLabels   map[string]map[string]map[string]string
	EthernetState  chan interface{}
	ExpirePeriod   time.Duration
	ConnectCounter int64
	MQTT           *mqtt.MQTT
}

BrickdCollector does all the work

func NewCollector

func NewCollector(addr, password string, cbPeriod time.Duration, ignoredUIDs []string,
	labels map[string]string, sensorLabels map[string]map[string]map[string]string,
	expirePeriod time.Duration, mq *mqtt.MQTT) *BrickdCollector

NewCollector creates a new collector for the given address (and authenticates with the password)

func (*BrickdCollector) CloseEthernetState

func (b *BrickdCollector) CloseEthernetState(_ uint64)

func (*BrickdCollector) Collect

func (b *BrickdCollector) Collect(ch chan<- prometheus.Metric)

Collect is part of the prometheus.Collector interface

func (*BrickdCollector) DefaultTopic

func (b *BrickdCollector) DefaultTopic(dev *Device) string

func (*BrickdCollector) Describe

func (b *BrickdCollector) Describe(ch chan<- *prometheus.Desc)

Describe is part of the prometheus.Collector interface

func (*BrickdCollector) ExportMQTT

func (b *BrickdCollector) ExportMQTT(interval time.Duration)

Collect is part of the prometheus.Collector interface

func (*BrickdCollector) OnConnect

func (b *BrickdCollector) OnConnect(reason ipconnection.DisconnectReason)

OnConnect is called when the brickd collector (re-)connects to the brickd

func (*BrickdCollector) OnDisconnect

func (b *BrickdCollector) OnDisconnect(reason ipconnection.DisconnectReason)

OnDisconnect is called when the brickd collector disconnects from the brickd

func (*BrickdCollector) OnEnumerate

func (b *BrickdCollector) OnEnumerate(
	uid string,
	connectedUid string,
	position rune,
	hardwareVersion [3]uint8,
	firmwareVersion [3]uint8,
	deviceIdentifier uint16,
	enumerationType ipconnection.EnumerationType)

OnEnumerate receives the callbacks from the Enumerate() call

func (*BrickdCollector) PollEthernetState

func (b *BrickdCollector) PollEthernetState(m master_brick.MasterBrick, uid string)

func (*BrickdCollector) RegisterAirQualityBricklet

func (b *BrickdCollector) RegisterAirQualityBricklet(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterAmbientLightV3Bricklet

func (b *BrickdCollector) RegisterAmbientLightV3Bricklet(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterAnalogInV3Bricklet

func (b *BrickdCollector) RegisterAnalogInV3Bricklet(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterBarometerBricklet

func (b *BrickdCollector) RegisterBarometerBricklet(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterBarometerV2Bricklet

func (b *BrickdCollector) RegisterBarometerV2Bricklet(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterCO2V2Bricklet

func (b *BrickdCollector) RegisterCO2V2Bricklet(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterHatBrick

func (b *BrickdCollector) RegisterHatBrick(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterHumidityBricklet

func (b *BrickdCollector) RegisterHumidityBricklet(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterHumidityV2Bricklet

func (b *BrickdCollector) RegisterHumidityV2Bricklet(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterMasterBrick

func (b *BrickdCollector) RegisterMasterBrick(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterOutdoorWeatherBricklet

func (b *BrickdCollector) RegisterOutdoorWeatherBricklet(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterUVLightV2Bricklet

func (b *BrickdCollector) RegisterUVLightV2Bricklet(dev *Device) ([]Register, error)

func (*BrickdCollector) RegisterZeroHatBrick

func (b *BrickdCollector) RegisterZeroHatBrick(dev *Device) ([]Register, error)

func (*BrickdCollector) SensorTopic

func (b *BrickdCollector) SensorTopic(dev *Device, index int) string

func (*BrickdCollector) SetHAConfig

func (b *BrickdCollector) SetHAConfig(typ, devClass, valueName, unit, uniqueID string, dev *Device, idx int, deviceID string)

SetHAConfig writes the HomeAssistant config to MQTT Parameters: * typ - HA type, probably either "sensor" or "binary_sensor" * devClass - type of sensor, must be a valid HA device class * valueName - name of the value inside the JSON of the MQTT topic we're publishing to * unit - HA unit * uniqueID - make these sensors unique * dev - the *Device * idx - unless there can be multiple sensors (like in the Outdoor Weather Bricklet) this is 0 * deviceID - make a new "device" when not empty, just used in the Outdoor Weather Bricklet, otherwise ""

func (*BrickdCollector) Update

func (b *BrickdCollector) Update()

Update runs in the background and discovers devices and collects the Values

type Device

type Device struct {
	UID             string
	ConnectedUID    string
	Position        rune
	HardwareVersion string
	FirmwareVersion string
	DeviceID        uint16
	Available       bool
}

Device is a discovered device

type HAConfig

type HAConfig struct {
	Name              string   `json:"name"`
	DeviceClass       string   `json:"device_class"`
	StateTopic        string   `json:"state_topic"`
	UnitOfMeasurement string   `json:"unit_of_measurement"`
	ValueTemplate     string   `json:"value_template"`
	UniqueID          string   `json:"unique_id"`
	ObjectID          string   `json:"object_id"`
	Device            HADevice `json:"device"`
	Origin            HAOrigin `json:"origin"`
}

type HADevice

type HADevice struct {
	Identifiers      []string `json:"identifiers"`
	Name             string   `json:"name,omitempty"`
	Manufacturer     string   `json:"manufacturer"`
	Model            string   `json:"model"`
	SerialNumber     string   `json:"serial_number,omitempty"`
	HWVersion        string   `json:"hw_version,omitempty"`
	SWVersion        string   `json:"sw_version,omitempty"`
	ConfigurationURL string   `json:"configuration_url,omitempty"`
}

type HAOrigin

type HAOrigin struct {
	Name       string `json:"name"`
	SWVersion  string `json:"sw_version"`
	SupportURL string `json:"support_url"`
}

type Register

type Register struct {
	Deregister func(uint64)
	ID         uint64
}

Register is a callback register, the Deregister func will be called as reg.Deregister(reg.ID)

type RegisterFunc

type RegisterFunc func(*Device) ([]Register, error)

RegisterFunc is the funcion of BrickdCollector to register callbacks

type Value

type Value struct {
	Index    int                  // index in BrickData.Values, needs to be assigned by the callback
	DeviceID uint16               // https://www.tinkerforge.com/en/doc/Software/Device_Identifier.html
	UID      string               // UID as given from brickd
	SensorID int                  // sensor id in outdoor_weather_bricklet
	Type     prometheus.ValueType // probably just prometheus.GaugeValue
	Help     string               // help for users, i.e. prometheus' "# HELP brickd_humidity_value ..." line, (just the help text)
	Name     string               // value name, such as "usb_voltage" or "humidity"
	Value    float64              // the measurement value
	Received time.Time            // when the value was received
}

Value is returned from the callbacks

Jump to

Keyboard shortcuts

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