Skip to content

Commit 1edb43f

Browse files
Fix available uc scenarios on device removal (#145)
When a device was disconnected, the cache of available scenarios wasn’t properly updated and the entities of the disconnected device still remained being available. This update fixes the issue. In addition some method names where updated to better reflect their functionality
1 parent 82f4b31 commit 1edb43f

File tree

22 files changed

+146
-43
lines changed

22 files changed

+146
-43
lines changed

examples/remote/ucs.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ func (r *Remote) PropagateEvent(
4545
) {
4646
params := make(map[string]interface{}, 2)
4747
params["ski"] = ski
48-
params["device"] = device.Address()
49-
params["entity"] = entity.Address()
48+
if device != nil {
49+
params["device"] = device.Address()
50+
}
51+
if entity != nil {
52+
params["entity"] = entity.Address()
53+
}
5054
for _, conn := range r.connections {
5155
_ = conn.Notify(context.Background(), string(event), params)
5256
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.22.0
44

55
require (
66
github.com/enbility/ship-go v0.0.0-20241118145930-d68708c5f1c0
7-
github.com/enbility/spine-go v0.0.0-20241118145803-0589320ceced
7+
github.com/enbility/spine-go v0.0.0-20241209160856-1aed917e83e7
88
github.com/stretchr/testify v1.9.0
99
golang.org/x/exp/jsonrpc2 v0.0.0-20240909161429-701f63a606c0
1010
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/enbility/go-avahi v0.0.0-20240909195612-d5de6b280d7a h1:foChWb8lhzqa6
66
github.com/enbility/go-avahi v0.0.0-20240909195612-d5de6b280d7a/go.mod h1:H64mhYcAQUGUUnVqMdZQf93kPecH4M79xwH95Lddt3U=
77
github.com/enbility/ship-go v0.0.0-20241118145930-d68708c5f1c0 h1:Z8j/N4DgUL8T8mINkHdq0bUbKcWtwDpno0bsKOGahPo=
88
github.com/enbility/ship-go v0.0.0-20241118145930-d68708c5f1c0/go.mod h1:JJp8EQcJhUhTpZ2LSEU4rpdaM3E2n08tswWFWtmm/wU=
9-
github.com/enbility/spine-go v0.0.0-20241118145803-0589320ceced h1:Z2WrJ+ku7lPZqJ+uzqvIqdMpXqvAZRB3J3xW592pDXI=
10-
github.com/enbility/spine-go v0.0.0-20241118145803-0589320ceced/go.mod h1:ZoI9TaJO/So/677uknrli8sc6iryD7wC5iWhVIre+MI=
9+
github.com/enbility/spine-go v0.0.0-20241209160856-1aed917e83e7 h1:Pq1L3U/aoSg8qQj4CfSEUCh9fxgB3G/skUNQI32zQeg=
10+
github.com/enbility/spine-go v0.0.0-20241209160856-1aed917e83e7/go.mod h1:ZoI9TaJO/So/677uknrli8sc6iryD7wC5iWhVIre+MI=
1111
github.com/enbility/zeroconf/v2 v2.0.0-20240920094356-be1cae74fda6 h1:XOYvxKtT1oxT37w/5oEiRLuPbm9FuJPt3fiYhX0h8Po=
1212
github.com/enbility/zeroconf/v2 v2.0.0-20240920094356-be1cae74fda6/go.mod h1:BszP9qFV14mPXgyIREbgIdQtWxbAj3OKqvK02HihMoM=
1313
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=

service/service_hub.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ import (
77
var _ shipapi.HubReaderInterface = (*Service)(nil)
88

99
// report a connection to a SKI
10+
//
11+
// is triggered whenever a SHIP connected was successful completed
1012
func (s *Service) RemoteSKIConnected(ski string) {
1113
s.serviceHandler.RemoteSKIConnected(s, ski)
1214
}
1315

1416
// report a disconnection to a SKI
17+
//
18+
// is triggered whenever a SHIP connect was closed, is also triggered when the SHIP
19+
// process wasn't successfully completed
20+
//
21+
// NOTE: The connection may not have been reported as connected before!
1522
func (s *Service) RemoteSKIDisconnected(ski string) {
1623
if s.spineLocalDevice != nil {
1724
s.spineLocalDevice.RemoveRemoteDeviceConnection(ski)

usecases/cem/cevc/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (e *CEVC) HandleEvent(payload spineapi.EventPayload) {
1717
return
1818
}
1919

20-
if internal.IsEntityConnected(payload) {
20+
if internal.IsEntityAdded(payload) {
2121
e.evConnected(payload.Entity)
2222
return
2323
}

usecases/cem/evcc/events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ func (e *EVCC) HandleEvent(payload spineapi.EventPayload) {
1717
return
1818
}
1919

20-
if internal.IsEntityConnected(payload) {
20+
if internal.IsEntityAdded(payload) {
2121
e.evConnected(payload)
2222
return
23-
} else if internal.IsEntityDisconnected(payload) {
23+
} else if internal.IsEntityRemoved(payload) {
2424
e.evDisconnected(payload)
2525
return
2626
}

usecases/cem/evcem/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (e *EVCEM) HandleEvent(payload spineapi.EventPayload) {
1717
return
1818
}
1919

20-
if internal.IsEntityConnected(payload) {
20+
if internal.IsEntityAdded(payload) {
2121
e.evConnected(payload.Entity)
2222
return
2323
}

usecases/cem/evsecc/events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ func (e *EVSECC) HandleEvent(payload spineapi.EventPayload) {
1515
return
1616
}
1717

18-
if internal.IsEntityConnected(payload) {
18+
if internal.IsEntityAdded(payload) {
1919
e.evseConnected(payload)
2020
return
21-
} else if internal.IsEntityDisconnected(payload) {
21+
} else if internal.IsEntityRemoved(payload) {
2222
e.evseDisconnected(payload)
2323
return
2424
}

usecases/cem/evsoc/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (e *EVSOC) HandleEvent(payload spineapi.EventPayload) {
1616
return
1717
}
1818

19-
if internal.IsEntityConnected(payload) {
19+
if internal.IsEntityAdded(payload) {
2020
e.evConnected(payload.Entity)
2121
return
2222
}

usecases/cem/opev/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (e *OPEV) HandleEvent(payload spineapi.EventPayload) {
1717
return
1818
}
1919

20-
if internal.IsEntityConnected(payload) {
20+
if internal.IsEntityAdded(payload) {
2121
e.evConnected(payload.Entity)
2222
return
2323
}

0 commit comments

Comments
 (0)