File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,10 @@ class GatewayModel extends Model {
50
50
}
51
51
52
52
setThing ( thingId , description ) {
53
- if ( ! this . thingModels . has ( thingId ) ) {
53
+ if ( this . thingModels . has ( thingId ) ) {
54
+ const thingModel = this . thingModels . get ( thingId ) ;
55
+ thingModel . updateFromDescription ( description ) ;
56
+ } else {
54
57
const thingModel = new ThingModel ( description , this . ws ) ;
55
58
thingModel . subscribe (
56
59
Constants . DELETE_THING ,
Original file line number Diff line number Diff line change @@ -15,11 +15,22 @@ const Constants = require('../constants');
15
15
class ThingModel extends Model {
16
16
constructor ( description , ws ) {
17
17
super ( ) ;
18
- this . title = description . title ;
19
18
this . properties = { } ;
20
19
this . events = [ ] ;
21
20
this . connected = false ;
22
21
22
+ this . updateFromDescription ( description ) ;
23
+
24
+ this . initWebSocket ( ws ) ;
25
+
26
+ this . updateEvents ( ) ;
27
+
28
+ return this ;
29
+ }
30
+
31
+ updateFromDescription ( description ) {
32
+ this . title = description . title ;
33
+
23
34
// Parse base URL of Thing
24
35
if ( description . href ) {
25
36
this . href = new URL ( description . href , App . ORIGIN ) ;
@@ -57,12 +68,6 @@ class ThingModel extends Model {
57
68
this . eventDescriptions [ eventName ] = event ;
58
69
}
59
70
}
60
-
61
- this . initWebSocket ( ws ) ;
62
-
63
- this . updateEvents ( ) ;
64
-
65
- return this ;
66
71
}
67
72
68
73
/**
You can’t perform that action at this time.
0 commit comments