Documentation
¶
Index ¶
- func AbeewayBatV(raw byte) float64
- func DecodePayloadBytes(encoded string) ([]byte, error)
- func ExtractBytes(payload *RawPayload) []byte
- func GenerateEntityID(domain, orgSlug, manufacturer, model, devEUI, entityType string) string
- func GenerateUniqueID(model, devEUI, entityType string) string
- func GetEntityDomain(entityType string) string
- func I16BE(b []byte, off int) int16
- func I16LE(b []byte, off int) int16
- func I32BE(b []byte, off int) int32
- func I32LE(b []byte, off int) int32
- func LinearBatPct(v, minV, maxV float64) float64
- func LocationSource(deviceGPS *Location) string
- func ReadInt24BE(b []byte, off int) int32
- func U16BE(b []byte, off int) uint16
- func U16LE(b []byte, off int) uint16
- func U24BE(b []byte, off int) uint32
- func U32BE(b []byte, off int) uint32
- func U32LE(b []byte, off int) uint32
- func ValidateCoordinates(lat, lon float64) error
- func YabbyBatV(raw uint32) float64
- type DeviceInfo
- type DeviceType
- type Entity
- func BuildEntitiesFromState(orgSlug, model, manufacturer, modelKey, devEUI string, defs []EntityDef, ...) []Entity
- func BuildEntityFromDef(orgSlug, model, manufacturer, modelKey, devEUI string, def EntityDef, ...) Entity
- func BuildEntityTemplates(orgSlug, model, manufacturer, modelKey, devEUI string, defs []EntityDef) []Entity
- func BuildLocationTemplate(orgSlug, model, manufacturer, modelKey, devEUI string, gpsCapable bool, ...) Entity
- type EntityDef
- type EntitySkipFunc
- type EntityTemplateDef
- type EntityTransformFunc
- type GatewayInfo
- type Location
- type ParseResult
- type ParsedData
- type Parser
- type RawPayload
- type TemplateProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbeewayBatV ¶
AbeewayBatV converts an Abeeway raw battery byte to volts. Formula: (raw * 10 + 2000) / 1000
func DecodePayloadBytes ¶
DecodePayloadBytes decodes a base64-encoded payload string to bytes.
func ExtractBytes ¶
func ExtractBytes(payload *RawPayload) []byte
ExtractBytes returns raw payload bytes from a RawPayload. It first tries the LNS handler (when LNSType is set), then falls back to standard base64 decoding of the Data field.
func GenerateEntityID ¶
GenerateEntityID creates a descriptive entity ID.
func GenerateUniqueID ¶
GenerateUniqueID creates a simple registry key for an entity.
func GetEntityDomain ¶
GetEntityDomain returns the HA domain for a given entity type key.
func LinearBatPct ¶
LinearBatPct returns a battery percentage assuming a linear curve from minV (0 %) to maxV (100 %), clamped to [0, 100].
func LocationSource ¶
LocationSource returns "gps" when the device itself provided a valid fix, or "gateway" when the location was computed from gateway trilateration as a fallback.
func ReadInt24BE ¶
ReadInt24BE reads a signed 24-bit big-endian integer with sign extension. Used by Cayenne LPP GPS channels (tbeam).
func ValidateCoordinates ¶
ValidateCoordinates checks that lat/lon are within valid ranges and not null-island.
Types ¶
type DeviceInfo ¶
type DeviceInfo struct {
Identifiers []string `json:"identifiers"`
Connections [][]string `json:"connections,omitempty"`
Name string `json:"name"`
Manufacturer string `json:"manufacturer"`
Model string `json:"model"`
ModelID string `json:"model_id"`
SWVersion string `json:"sw_version,omitempty"`
HWVersion string `json:"hw_version,omitempty"`
ViaDevice string `json:"via_device,omitempty"`
}
DeviceInfo carries device metadata for Home-Assistant-style discovery.
func CreateDeviceInfo ¶
func CreateDeviceInfo(devEUI, name, manufacturer, model, modelID string) DeviceInfo
CreateDeviceInfo builds a DeviceInfo struct.
type DeviceType ¶
type DeviceType string
DeviceType represents the model/type of a device.
const DeviceTypeUnknown DeviceType = "UNKNOWN"
DeviceTypeUnknown is the default when the type cannot be determined.
type Entity ¶
type Entity struct {
Key string `json:"key,omitempty"`
UniqueID string `json:"unique_id"`
EntityID string `json:"entity_id"`
EntityType string `json:"entity_type"`
DeviceClass string `json:"device_class,omitempty"`
Name string `json:"name"`
State interface{} `json:"state"`
Attributes map[string]interface{} `json:"attributes"`
DisplayType []string `json:"display_type,omitempty"`
UnitOfMeas string `json:"unit_of_measurement,omitempty"`
Icon string `json:"icon,omitempty"`
Enabled bool `json:"enabled"`
Timestamp time.Time `json:"timestamp"`
}
Entity represents a single device capability or sensor reading.
func BuildEntitiesFromState ¶ added in v0.0.5
func BuildEntityFromDef ¶ added in v0.0.5
func BuildEntityTemplates ¶ added in v0.0.5
type EntitySkipFunc ¶ added in v0.0.5
type EntityTemplateDef ¶ added in v0.0.5
type EntityTemplateDef = EntityDef
type EntityTransformFunc ¶ added in v0.0.5
type GatewayInfo ¶
type GatewayInfo struct {
GatewayID string `json:"gateway_id"`
RSSI int `json:"rssi"`
SNR float64 `json:"snr"`
Location Location `json:"location,omitempty"`
}
GatewayInfo contains information about a gateway that received the message.
type Location ¶
type Location struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Altitude float64 `json:"altitude,omitempty"`
Bearing float64 `json:"bearing,omitempty"`
}
Location represents geographical coordinates.
func ExtractGPS ¶
ExtractGPS looks for latitude/longitude in a decoded field map using common key names. Returns nil if no valid coordinates are found.
func ResolveLocationBearing ¶ added in v0.0.5
func ResolveLocationBearing(parsedLocation, deviceLocation *Location, sensorData map[string]interface{}) *Location
ResolveLocationBearing returns the preferred bearing for a location, using a device-reported heading when present and otherwise falling back to the computed device location bearing.
type ParseResult ¶
type ParseResult struct {
DeviceEUI string `json:"device_eui"`
DeviceID string `json:"device_id,omitempty"`
SpaceSlug string `json:"space_slug,omitempty"`
DeviceInfo DeviceInfo `json:"device_info"`
Entities []Entity `json:"entities"`
Timestamp time.Time `json:"timestamp"`
}
ParseResult is the final result containing all generated entities.
type ParsedData ¶
type ParsedData struct {
DeviceEUI string `json:"device_eui"`
DeviceType DeviceType `json:"device_type"`
Timestamp time.Time `json:"timestamp"`
Location *Location `json:"location,omitempty"`
SensorData map[string]interface{} `json:"sensor_data"`
BatteryLevel *float64 `json:"battery_level,omitempty"`
RawData string `json:"raw_data,omitempty"`
}
ParsedData is the intermediate result of parsing a single device uplink.
type Parser ¶
type Parser interface {
ParsePayload(payload *RawPayload) (*ParsedData, error)
ParseToEntities(orgSlug, model string, payload *RawPayload, deviceLocation *Location) ([]Entity, error)
SupportsGPS() bool
GetSupportedPorts() []int
GetSupportedEntityTypes() []string
}
Parser is the interface every device model must implement.
type RawPayload ¶
type RawPayload struct {
DeviceEUI string `json:"device_eui"`
FPort int `json:"fport"`
Data string `json:"data"` // Base64-encoded payload
Timestamp time.Time `json:"timestamp"`
RxInfo []GatewayInfo `json:"rx_info"`
Metadata map[string]interface{} `json:"metadata"`
LNSType lns.LNSType `json:"lns_type"`
}
RawPayload represents the incoming device data before parsing.
type TemplateProvider ¶ added in v0.0.5
TemplateProvider is implemented by parsers that can expose bootstrap entity templates.