Documentation
¶
Index ¶
- type DeviceLocationMessage
- type Event
- type EventData
- type EventDetail
- type EventRule
- type EventRuleRequest
- type EventRuleResponse
- type EventRulesListResponse
- type EventType
- type EventsListResponse
- type LocationCoordinates
- type MatchedEvent
- type OrgDiscoveryRequest
- type OrgDiscoveryResponse
- type OrgEvent
- type OrgEventPayload
- type OrgEventType
- type OrgInfo
- type State
- type StateAttributes
- type StateChangeRequest
- type StateDetailResponse
- type StateHistoryResponse
- type StatesMeta
- type TelemetryDevice
- type TelemetryEntity
- type TelemetryPayload
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeviceLocationMessage ¶
type DeviceLocationMessage struct {
DeviceID string `json:"device_id"`
Location LocationCoordinates `json:"location"`
Timestamp string `json:"timestamp"`
Space string `json:"space_slug"`
Organization string `json:"organization"`
Source string `json:"source"`
Metadata map[string]any `json:"metadata"`
}
DeviceLocationMessage represents the transformed device location message from RabbitMQ
func (*DeviceLocationMessage) ToTelemetryPayload ¶
func (m *DeviceLocationMessage) ToTelemetryPayload() *TelemetryPayload
ToTelemetryPayload converts DeviceLocationMessage to TelemetryPayload for entity_states storage
type Event ¶
type Event struct {
EventID int64 `json:"event_id" db:"event_id"`
EventTypeID int `json:"event_type_id" db:"event_type_id"`
DataID *int64 `json:"data_id,omitempty" db:"data_id"`
EventLevel *string `json:"event_level,omitempty" db:"event_level"` // manufacturer, system, automation
EventRuleID *string `json:"event_rule_id,omitempty" db:"event_rule_id"`
SpaceSlug string `json:"space_slug,omitempty" db:"space_slug"`
EntityID *string `json:"entity_id,omitempty" db:"entity_id"`
StateID *int64 `json:"state_id,omitempty" db:"state_id"`
TriggerID *string `json:"trigger_id,omitempty" db:"trigger_id"`
TimeFiredTs int64 `json:"time_fired_ts" db:"time_fired_ts"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
// Joined fields
EventType string `json:"event_type,omitempty" db:"event_type"`
}
Event represents an event occurrence
func (*Event) ParseEventData ¶
ParseEventData parses the shared_data JSON into a map
type EventData ¶
type EventData struct {
DataID int64 `json:"data_id" db:"data_id"`
Hash int64 `json:"hash" db:"hash"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
EventData represents shared event data (deduplicated by hash)
func (*EventData) SetSharedData ¶
SetSharedData sets the shared_data from a map
type EventDetail ¶
type EventDetail struct {
EventID int64 `json:"event_id"`
EventType string `json:"event_type"`
LevelEventID *string `json:"level_event_id,omitempty"`
EventRuleID *string `json:"event_rule_id,omitempty"`
SpaceSlug string `json:"space_slug,omitempty"`
EntityID *string `json:"entity_id,omitempty"`
StateID *int64 `json:"state_id,omitempty"`
TriggerID *string `json:"trigger_id,omitempty"`
TimeFired time.Time `json:"time_fired"`
EventData map[string]interface{} `json:"event_data,omitempty"`
ContextID []byte `json:"context_id,omitempty"`
// Joined fields
EventRule *EventRule `json:"event_rule,omitempty"`
}
EventDetail represents a full event with its type and data
type EventRule ¶
type EventRule struct {
EventRuleID string `json:"event_rule_id" db:"event_rule_id"`
DeviceID *string `json:"device_id,omitempty" db:"device_id"`
RuleKey *string `json:"rule_key,omitempty" db:"rule_key"` // e.g., 'battery_low', 'temperature_low'
Operator *string `json:"operator,omitempty" db:"operator"` // eq, ne, gt, lt, gte, lte,...
Operand string `json:"operand" db:"operand"`
IsActive *bool `json:"is_active,omitempty" db:"is_active"`
StartTime *time.Time `json:"start_time,omitempty" db:"start_time"`
EndTime *time.Time `json:"end_time,omitempty" db:"end_time"`
AllowNewEvent *bool `json:"allow_new_event,omitempty" db:"allow_new_event"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
EventRule represents an automation rule for triggering events based on conditions
type EventRuleRequest ¶
type EventRuleRequest struct {
DeviceID *string `json:"device_id,omitempty" validate:"required,uuid"`
RuleKey *string `json:"rule_key,omitempty" validate:"required"`
Operator *string `json:"operator,omitempty" validate:"omitempty,oneof=eq ne gt lt gte lte contains"`
Operand string `json:"operand" validate:"required"`
IsActive *bool `json:"is_active,omitempty"`
AllowNewEvent *bool `json:"allow_new_event,omitempty"`
StartTime *string `json:"start_time,omitempty" validate:"omitempty,datetime=2006-01-02T15:04:05Z07:00"`
EndTime *string `json:"end_time,omitempty" validate:"omitempty,datetime=2006-01-02T15:04:05Z07:00"`
}
EventRuleRequest represents a request to create or update an event rule
type EventRuleResponse ¶
type EventRuleResponse struct {
EventRuleID string `json:"event_rule_id"`
DeviceID *string `json:"device_id,omitempty"`
RuleKey *string `json:"rule_key,omitempty"`
Operator *string `json:"operator,omitempty"`
Operand string `json:"operand"`
IsActive *bool `json:"is_active,omitempty"`
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
EventRuleResponse represents an event rule response
type EventRulesListResponse ¶
type EventRulesListResponse struct {
Rules []EventRule `json:"rules"`
TotalCount int `json:"total_count"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
EventRulesListResponse represents a paginated list of event rules
type EventType ¶
type EventType struct {
EventTypeID int `json:"event_type_id" db:"event_type_id"`
EventType string `json:"event_type" db:"event_type"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
EventType represents a type of event (e.g., "state_changed", "service_call")
type EventsListResponse ¶
type EventsListResponse struct {
Events []Event `json:"events"`
TotalCount int `json:"total_count"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
EventsListResponse represents paginated events
type LocationCoordinates ¶
type LocationCoordinates struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Accuracy float64 `json:"accuracy"`
Direction *string `json:"direction,omitempty"`
}
LocationCoordinates represents geographic coordinates with accuracy
type MatchedEvent ¶
type MatchedEvent struct {
EntityID string `json:"entity_id"`
EntityType string `json:"entity_type"`
RuleKey string `json:"rule_key"`
EventType string `json:"event_type"`
EventLevel string `json:"event_level"`
Description string `json:"description"`
Value float64 `json:"value"`
Threshold float64 `json:"threshold"`
Operator string `json:"operator"`
Timestamp int64 `json:"timestamp"` // Unix timestamp in milliseconds
EventRuleID *string `json:"event_rule_id,omitempty"`
StateID *string `json:"state_id,omitempty"`
}
MatchedEvent represents an event rule that matched evaluation
type OrgDiscoveryRequest ¶
type OrgDiscoveryRequest struct {
EventType OrgEventType `json:"event_type"`
EventID string `json:"event_id"`
Timestamp time.Time `json:"timestamp"`
ServiceName string `json:"service_name"`
ReplyTo string `json:"reply_to"`
}
OrgDiscoveryRequest is sent to discover active organizations
type OrgDiscoveryResponse ¶
type OrgDiscoveryResponse struct {
EventType OrgEventType `json:"event_type"`
EventID string `json:"event_id"`
Timestamp time.Time `json:"timestamp"`
Spaces []OrgInfo `json:"spaces"`
TotalCount int `json:"total_count"`
}
OrgDiscoveryResponse contains all active organizations
type OrgEvent ¶
type OrgEvent struct {
EventType OrgEventType `json:"event_type"`
EventID string `json:"event_id"`
Timestamp time.Time `json:"timestamp"`
Payload OrgEventPayload `json:"payload"`
}
OrgEvent represents an organization lifecycle event
type OrgEventPayload ¶
type OrgEventPayload struct {
ID string `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
Vhost string `json:"vhost,omitempty"`
Exchange string `json:"exchange,omitempty"`
TransformerQueue string `json:"transformer_queue,omitempty"`
TelemetryQueue string `json:"telemetry_queue,omitempty"`
IsActive bool `json:"is_active"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
OrgEventPayload contains organization details
type OrgEventType ¶
type OrgEventType string
OrgEventType represents the type of organization event
const ( // OrgCreated is emitted when a new organization is created OrgCreated OrgEventType = "org.created" // OrgUpdated is emitted when an organization is updated OrgUpdated OrgEventType = "org.updated" // OrgDeleted is emitted when an organization is deleted OrgDeleted OrgEventType = "org.deleted" // OrgDeactivated is emitted when an organization is deactivated OrgDeactivated OrgEventType = "org.deactivated" // OrgActivated is emitted when an organization is activated OrgActivated OrgEventType = "org.activated" // OrgDiscoveryReq is emitted when requesting active orgs OrgDiscoveryReq OrgEventType = "org.discovery.request" // OrgDiscoveryResp is the response with active orgs OrgDiscoveryResp OrgEventType = "org.discovery.response" )
type OrgInfo ¶
type OrgInfo struct {
Slug string `json:"slug"`
Name string `json:"name"`
Vhost string `json:"vhost"`
IsActive bool `json:"is_active"`
}
OrgInfo contains basic organization information
type State ¶
type State struct {
StateID int64 `json:"state_id" db:"state_id"`
MetadataID int `json:"metadata_id" db:"metadata_id"`
State string `json:"state" db:"state"`
AttributesID *int `json:"attributes_id,omitempty" db:"attributes_id"`
EventID *int64 `json:"event_id,omitempty" db:"event_id"`
LastChangedTs int64 `json:"last_changed_ts" db:"last_changed_ts"`
LastUpdatedTs int64 `json:"last_updated_ts" db:"last_updated_ts"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
// Joined fields
EntityID string `json:"entity_id,omitempty" db:"entity_id"`
}
State represents an entity state with event linkage
func (*State) LastChangedTime ¶
TimestampsToTime converts timestamp fields to time.Time
func (*State) LastUpdatedTime ¶
LastUpdatedTime converts the last_updated_ts to time.Time
func (*State) ParseAttributes ¶
ParseAttributes parses the shared_attrs JSON into a map
type StateAttributes ¶
type StateAttributes struct {
AttributesID int `json:"attributes_id" db:"attributes_id"`
Hash int64 `json:"hash" db:"hash"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
StateAttributes represents shared state attributes (deduplicated by hash)
func (*StateAttributes) SetSharedAttrs ¶
func (s *StateAttributes) SetSharedAttrs(attrs map[string]interface{}) error
SetSharedAttrs sets the shared_attrs from a map
type StateChangeRequest ¶
type StateChangeRequest struct {
EntityID string `json:"entity_id"`
SpaceSlug string `json:"space_slug,omitempty"` // optional, will be resolved from headers if not provided
NewState string `json:"new_state"`
OldState string `json:"old_state,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
EventType string `json:"event_type,omitempty"` // defaults to "state_changed"
TimeFiredTs *int64 `json:"time_fired_ts,omitempty"`
ContextID []byte `json:"context_id,omitempty"`
TriggerID *string `json:"trigger_id,omitempty"` // for future automations reference
}
StateChangeRequest represents a request to record a state change
type StateDetailResponse ¶
type StateDetailResponse struct {
StateID int64 `json:"state_id"`
EntityID string `json:"entity_id"`
State string `json:"state"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
LastChanged time.Time `json:"last_changed"`
LastUpdated time.Time `json:"last_updated"`
TriggeringEvent *EventDetail `json:"triggering_event,omitempty"`
}
StateDetailResponse combines state with metadata and attributes
type StateHistoryResponse ¶
type StateHistoryResponse struct {
EntityID string `json:"entity_id"`
State string `json:"state"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
LastChanged time.Time `json:"last_changed"`
LastUpdated time.Time `json:"last_updated"`
EventID *int64 `json:"event_id,omitempty"`
}
StateHistoryResponse represents historical state data for an entity
type StatesMeta ¶
type StatesMeta struct {
MetadataID int `json:"metadata_id" db:"metadata_id"`
EntityID string `json:"entity_id" db:"entity_id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
StatesMeta represents metadata about entity states
type TelemetryDevice ¶
type TelemetryDevice struct {
Identifiers []string `json:"identifiers"`
Name string `json:"name"`
Manufacturer string `json:"manufacturer"`
Model string `json:"model"`
ModelID string `json:"model_id"`
}
TelemetryDevice holds basic device metadata.
type TelemetryEntity ¶
type TelemetryEntity struct {
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 any `json:"state"`
DisplayType []string `json:"display_type,omitempty"`
Attributes map[string]any `json:"attributes,omitempty"`
UnitOfMeas string `json:"unit_of_measurement,omitempty"`
Icon string `json:"icon,omitempty"`
Timestamp string `json:"timestamp"`
StateID *string `json:"state_id,omitempty"`
}
TelemetryEntity describes a single entity in telemetry payloads.
type TelemetryPayload ¶
type TelemetryPayload struct {
Organization string `json:"organization"`
DeviceEUI string `json:"device_eui"`
DeviceID string `json:"device_id,omitempty"`
SpaceSlug string `json:"space_slug,omitempty"`
DeviceInfo TelemetryDevice `json:"device_info"`
Entities []TelemetryEntity `json:"entities"`
Timestamp string `json:"timestamp"`
Source string `json:"source"`
Metadata map[string]any `json:"metadata,omitempty"`
}
TelemetryPayload represents the entity-centric telemetry emitted by transformer-service.