Skip to content

Commit

Permalink
Thing can declare how often it will send a message
Browse files Browse the repository at this point in the history
  • Loading branch information
kimble committed Jun 27, 2024
1 parent b0cbb22 commit e1aa6b8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions adapter-protobuf-java/src/main/proto/adapter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ message AdapterManifest {
// Optional.
string uri = 7;

// Some things will ping every n seconds allowing us to trigger
// an alert if we don't hear from the thing for n+m seconds.
//
// Optional, set to 0 if not relevant / supported
int32 seconds_without_message_before_alert = 8;

}

// Examples:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import com.github.oslokommune.oslonokkelen.adapter.thing.ThingId
import com.github.oslokommune.oslonokkelen.adapter.thing.ThingState
import com.github.oslokommune.oslonokkelen.adapter.thing.ThingStateSnapshot
import com.nimbusds.jwt.JWTClaimsSet
import java.net.URI
import java.time.Duration
import java.time.Instant
import java.time.ZonedDateTime
import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.collections.immutable.toPersistentHashMap
import kotlinx.collections.immutable.toPersistentList
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.net.URI
import java.time.Duration
import java.time.Instant
import java.time.ZonedDateTime

object ProtobufParser {

Expand Down Expand Up @@ -191,6 +191,11 @@ object ProtobufParser {
URI.create(serializedThing.uri)
} else {
null
},
secondsWithoutMessageBeforeAlert = if (serializedThing.secondsWithoutMessageBeforeAlert > 0) {
Duration.ofSeconds(serializedThing.secondsWithoutMessageBeforeAlert.toLong())
} else {
null
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ object ProtobufSerializer {
if (thing.link != null) {
thingBuilder.setUri(thing.link.toString())
}
if (thing.secondsWithoutMessageBeforeAlert != null) {
thingBuilder.setSecondsWithoutMessageBeforeAlert(thing.secondsWithoutMessageBeforeAlert.toSeconds().toInt())
}

thingBuilder.build()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.github.oslokommune.oslonokkelen.adapter.thing

import java.net.URI
import java.time.Duration


data class ThingDescription(
val id: ThingId,
val description: String,
val adminRole: String,
val tags: Set<String> = emptySet(),
val link: URI? = null
val link: URI? = null,
val secondsWithoutMessageBeforeAlert: Duration? = null
)

0 comments on commit e1aa6b8

Please sign in to comment.