mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-05 23:15:07 -06:00
refactor: rename files into common naming, rename GetId to NextId, document function
This commit is contained in:
2
app.go
2
app.go
@@ -370,7 +370,7 @@ func (a *App) Start() {
|
|||||||
go runIntervals(a)
|
go runIntervals(a)
|
||||||
|
|
||||||
// subscribe to state_changed events
|
// subscribe to state_changed events
|
||||||
id := internal.GetId()
|
id := internal.NextId()
|
||||||
ws.SubscribeToStateChangedEvents(id, a.wsWriter, a.ctx)
|
ws.SubscribeToStateChangedEvents(id, a.wsWriter, a.ctx)
|
||||||
a.entityListenersId = id
|
a.entityListenersId = id
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ var (
|
|||||||
id atomic.Int64 // default value is 0
|
id atomic.Int64 // default value is 0
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetId() int64 {
|
// NextId returns a unique integer (for the given process), often used for providing a uniquely identifiable
|
||||||
|
// id for a request. This function is thread-safe.
|
||||||
|
func NextId() int64 {
|
||||||
return id.Add(1)
|
return id.Add(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ type FireEventRequest struct {
|
|||||||
// as `event_data`.
|
// as `event_data`.
|
||||||
func (e Event) Fire(eventType string, eventData ...map[string]any) error {
|
func (e Event) Fire(eventType string, eventData ...map[string]any) error {
|
||||||
req := FireEventRequest{
|
req := FireEventRequest{
|
||||||
Id: internal.GetId(),
|
Id: internal.NextId(),
|
||||||
Type: "fire_event",
|
Type: "fire_event",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ type BaseServiceRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewBaseServiceRequest(entityId string) BaseServiceRequest {
|
func NewBaseServiceRequest(entityId string) BaseServiceRequest {
|
||||||
id := internal.GetId()
|
|
||||||
bsr := BaseServiceRequest{
|
bsr := BaseServiceRequest{
|
||||||
|
id := internal.NextId()
|
||||||
Id: id,
|
Id: id,
|
||||||
RequestType: "call_service",
|
RequestType: "call_service",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ func SubscribeToStateChangedEvents(id int64, conn *WebsocketWriter, ctx context.
|
|||||||
func SubscribeToEventType(eventType string, conn *WebsocketWriter, ctx context.Context, id ...int64) {
|
func SubscribeToEventType(eventType string, conn *WebsocketWriter, ctx context.Context, id ...int64) {
|
||||||
var finalId int64
|
var finalId int64
|
||||||
if len(id) == 0 {
|
if len(id) == 0 {
|
||||||
finalId = internal.GetId()
|
finalId = internal.NextId()
|
||||||
} else {
|
} else {
|
||||||
finalId = id[0]
|
finalId = id[0]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user