Documentation
¶
Index ¶
- type AdapterOfflineEvent
- type AdapterOnlineEvent
- type Attribute
- type Bus
- func (b *Bus) Close()
- func (b *Bus) Publish(ctx context.Context, evt Event) error
- func (b *Bus) PublishAdapterOffline(ctx context.Context, reason string) error
- func (b *Bus) PublishAdapterOnline(ctx context.Context) error
- func (b *Bus) PublishDeviceJoined(ctx context.Context, event DeviceJoinedEvent) error
- func (b *Bus) PublishDeviceLeft(ctx context.Context, event DeviceLeftEvent) error
- func (b *Bus) PublishDeviceStateChange(ctx context.Context, event DeviceStateChangeEvent) error
- func (b *Bus) PublishSensorReport(ctx context.Context, event SensorReportEvent) error
- func (b *Bus) PublishSync(ctx context.Context, evt Event) (int, error)
- func (b *Bus) Subscribe(_ context.Context, filter func(Event) bool) (<-chan Event, func())
- func (b *Bus) SubscribeTo(ctx context.Context, eventTypes ...Type) (<-chan Event, func())
- func (b *Bus) SubscribersCount() map[Type]int
- type DeviceJoinedEvent
- type DeviceLeftEvent
- type DeviceStateChangeEvent
- type DeviceUpdatedEvent
- type Event
- type NetworkChangedEvent
- type SensorReportEvent
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdapterOfflineEvent ¶
type AdapterOfflineEvent struct {
Reason string `json:"reason,omitempty"`
OfflineAt time.Time `json:"offline_at"`
}
AdapterOfflineEvent is emitted when the adapter goes offline.
type AdapterOnlineEvent ¶
AdapterOnlineEvent is emitted when the adapter comes online.
type Attribute ¶
type Attribute struct {
ID uint16 `json:"id"`
Value interface{} `json:"value"`
}
Attribute represents a single attribute value.
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is a publish-subscribe event bus. It allows multiple components to subscribe to events and publish events asynchronously.
func (*Bus) Close ¶
func (b *Bus) Close()
Close stops the event bus and closes all subscriber channels.
func (*Bus) Publish ¶
Publish sends an event to all matching subscribers. Returns an error if the context is canceled.
func (*Bus) PublishAdapterOffline ¶
PublishAdapterOffline publishes an AdapterOfflineEvent.
func (*Bus) PublishAdapterOnline ¶
PublishAdapterOnline publishes an AdapterOnlineEvent.
func (*Bus) PublishDeviceJoined ¶
func (b *Bus) PublishDeviceJoined(ctx context.Context, event DeviceJoinedEvent) error
PublishDeviceJoined publishes a DeviceJoinedEvent.
func (*Bus) PublishDeviceLeft ¶
func (b *Bus) PublishDeviceLeft(ctx context.Context, event DeviceLeftEvent) error
PublishDeviceLeft publishes a DeviceLeftEvent.
func (*Bus) PublishDeviceStateChange ¶
func (b *Bus) PublishDeviceStateChange(ctx context.Context, event DeviceStateChangeEvent) error
PublishDeviceStateChange publishes a DeviceStateChangeEvent.
func (*Bus) PublishSensorReport ¶
func (b *Bus) PublishSensorReport(ctx context.Context, event SensorReportEvent) error
PublishSensorReport publishes a SensorReportEvent.
func (*Bus) PublishSync ¶
PublishSync publishes an event synchronously, waiting for all subscribers to receive it. This is useful for critical events where you need to ensure delivery. Returns the number of subscribers that received the event.
func (*Bus) Subscribe ¶
Subscribe returns a channel for receiving events. The channel is buffered and will be closed when the bus is closed or Unsubscribe is called.
The filter function is optional. If provided, only events matching the filter will be sent.
Example:
ch, unsubscribe := bus.Subscribe(nil, EventDeviceStateChange)
defer unsubscribe()
for evt := range ch {
stateChange := evt.Data.(DeviceStateChangeEvent)
// Handle event
}
func (*Bus) SubscribeTo ¶
SubscribeTo returns a channel for receiving specific event types.
func (*Bus) SubscribersCount ¶
SubscribersCount returns the number of active subscribers for each event type.
type DeviceJoinedEvent ¶
type DeviceJoinedEvent struct {
IEEEAddr string `json:"ieee_addr"`
NwkAddr string `json:"nwk_addr"`
Name string `json:"name,omitempty"`
Model string `json:"model,omitempty"`
JoinedAt time.Time `json:"joined_at"`
}
DeviceJoinedEvent is emitted when a device joins the network.
type DeviceLeftEvent ¶
type DeviceLeftEvent struct {
IEEEAddr string `json:"ieee_addr"`
Name string `json:"name,omitempty"`
LeftAt time.Time `json:"left_at"`
}
DeviceLeftEvent is emitted when a device leaves the network.
type DeviceStateChangeEvent ¶
type DeviceStateChangeEvent struct {
IEEEAddr string `json:"ieee_addr"`
Slug string `json:"slug,omitempty"`
ClusterID uint16 `json:"cluster_id"`
AttrID uint16 `json:"attr_id"`
OldValue interface{} `json:"old_value,omitempty"`
NewValue interface{} `json:"new_value"`
ChangedAt time.Time `json:"changed_at"`
}
DeviceStateChangeEvent is emitted when a device's state changes.
type DeviceUpdatedEvent ¶
type DeviceUpdatedEvent struct {
IEEEAddr string `json:"ieee_addr"`
Slug string `json:"slug,omitempty"`
UpdateType string `json:"update_type"` // "name", "endpoints", "capabilities"
OldValue string `json:"old_value,omitempty"`
NewValue string `json:"new_value,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
}
DeviceUpdatedEvent is emitted when a device's metadata is updated.
type Event ¶
type Event struct {
Type Type `json:"type"`
Timestamp time.Time `json:"timestamp"`
Data interface{} `json:"data"`
}
Event represents a generic event.
type NetworkChangedEvent ¶
type NetworkChangedEvent struct {
ChangeType string `json:"change_type"` // "formed", "reformed", "channel", "pan_id"
Details map[string]interface{} `json:"details,omitempty"`
ChangedAt time.Time `json:"changed_at"`
}
NetworkChangedEvent is emitted when network configuration changes.
type SensorReportEvent ¶
type SensorReportEvent struct {
IEEEAddr string `json:"ieee_addr"`
Slug string `json:"slug,omitempty"`
ClusterID uint16 `json:"cluster_id"`
Attributes []Attribute `json:"attributes"`
ReceivedAt time.Time `json:"received_at"`
}
SensorReportEvent is emitted when a device sends sensor data.
type Type ¶ added in v0.4.0
type Type string
Type represents the type of event.
const ( // DeviceLifecycle events EventDeviceJoined Type = "device.joined" EventDeviceLeft Type = "device.left" EventDeviceUpdated Type = "device.updated" // State events EventDeviceStateChange Type = "device.state_change" // Sensor events EventSensorReport Type = "sensor.report" // Adapter events EventAdapterOnline Type = "adapter.online" EventAdapterOffline Type = "adapter.offline" // Network events EventNetworkChanged Type = "network.changed" )