Documentation ¶
Index ¶
- Constants
- Variables
- func DeviceName(id uint16) string
- type BrickData
- type BrickdCollector
- func (b *BrickdCollector) CloseEthernetState(_ uint64)
- func (b *BrickdCollector) Collect(ch chan<- prometheus.Metric)
- func (b *BrickdCollector) DefaultTopic(dev *Device) string
- func (b *BrickdCollector) Describe(ch chan<- *prometheus.Desc)
- func (b *BrickdCollector) ExportMQTT(interval time.Duration)
- func (b *BrickdCollector) OnConnect(reason ipconnection.DisconnectReason)
- func (b *BrickdCollector) OnDisconnect(reason ipconnection.DisconnectReason)
- func (b *BrickdCollector) OnEnumerate(uid string, connectedUid string, position rune, hardwareVersion [3]uint8, ...)
- func (b *BrickdCollector) PollEthernetState(m master_brick.MasterBrick, uid string)
- func (b *BrickdCollector) RegisterAirQualityBricklet(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterAmbientLightV3Bricklet(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterAnalogInV3Bricklet(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterBarometerBricklet(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterBarometerV2Bricklet(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterCO2V2Bricklet(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterHatBrick(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterHumidityBricklet(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterHumidityV2Bricklet(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterMasterBrick(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterOutdoorWeatherBricklet(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterUVLightV2Bricklet(dev *Device) ([]Register, error)
- func (b *BrickdCollector) RegisterZeroHatBrick(dev *Device) ([]Register, error)
- func (b *BrickdCollector) SensorTopic(dev *Device, index int) string
- func (b *BrickdCollector) SetHAConfig(typ, devClass, valueName, unit, uniqueID string, dev *Device, idx int, ...)
- func (b *BrickdCollector) Update()
- type Device
- type HAConfig
- type HADevice
- type HAOrigin
- type Register
- type RegisterFunc
- type Value
Constants ¶
const (
EthernetCallbackID uint64 = math.MaxUint64
)
Variables ¶
var Version string
Functions ¶
func DeviceName ¶
Types ¶
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 Register ¶
Register is a callback register, the Deregister func will be called as reg.Deregister(reg.ID)
type RegisterFunc ¶
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