Skip to content

Commit

Permalink
Add explanation to online state
Browse files Browse the repository at this point in the history
  • Loading branch information
kimble committed Jun 26, 2024
1 parent 2a1c189 commit b0cbb22
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions adapter-protobuf-java/src/main/proto/adapter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ message ThingState {

OnlineStatus online_status = 3;

// Short one-liner saying something about how
// it knows that the thing is online or not.
string explanation = 4;

enum OnlineStatus {
// Some systems don't support tracking online status, but they have
// a regular ping. By looking at last_seen we can guess the online status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ object ProtobufParser {
Instant.parse(serializedState.online.lastSeen)
} else {
null
}
},
explanation = serializedState.online.explanation.ifBlank { null }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ object ProtobufSerializer {
if (state.lastSeen != null) {
onlineBuilder.setLastSeen(state.lastSeen.toString())
}
if (state.explanation != null) {
onlineBuilder.setExplanation(state.explanation)
}

Adapter.ThingState.newBuilder()
.setLastUpdate(state.timestamp.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ sealed class ThingState {
override val timestamp: Instant,
override val thingId: ThingId,
val status : Status,
val lastSeen: Instant?
val lastSeen: Instant?,
val explanation: String?
) : ThingState() {

override val key = Key(thingId, "thing.${thingId.value}.online")
Expand Down

0 comments on commit b0cbb22

Please sign in to comment.