@@ -17,12 +17,18 @@ class OuraRingConfigurationConverter(
1717 root : JsonNode ,
1818 user : User ,
1919 ): Sequence <Result <TopicData >> {
20- val array = root.get(" data" )
21- ? : return emptySequence()
20+ val array =
21+ root.get(" data" )
22+ ? : return emptySequence()
2223 return array.asSequence()
2324 .mapCatching {
24- val setupTime = OffsetDateTime .parse(it[" set_up_at" ].textValue())
25- val setupTimeInstant = setupTime.toInstant()
25+ val setUpAt = it[" set_up_at" ]
26+ val setupTimeInstant =
27+ setUpAt?.textValue()?.let {
28+ OffsetDateTime .parse(
29+ it,
30+ )
31+ }?.toInstant()
2632 TopicData (
2733 key = user.observationKey,
2834 topic = topic,
@@ -32,9 +38,7 @@ class OuraRingConfigurationConverter(
3238 }
3339 }
3440
35- private fun JsonNode.toRingConfiguration (
36- setupTime : Instant ,
37- ): OuraRingConfiguration {
41+ private fun JsonNode.toRingConfiguration (setupTime : Instant ? ): OuraRingConfiguration {
3842 val data = this
3943 return OuraRingConfiguration .newBuilder().apply {
4044 time = System .currentTimeMillis() / 1000.0
@@ -44,7 +48,7 @@ class OuraRingConfigurationConverter(
4448 design = data.get(" design" ).textValue()?.classifyDesign()
4549 firmwareVersion = data.get(" firmware_version" ).textValue()
4650 hardwareType = data.get(" hardware_type" ).textValue()?.classifyHardware()
47- setUpAt = setupTime.toEpochMilli() / 1000.0
51+ setUpAt = if (setupTime == null ) null else setupTime.toEpochMilli() / 1000.0
4852 size = data.get(" size" ).intValue()
4953 }.build()
5054 }
@@ -77,6 +81,7 @@ class OuraRingConfigurationConverter(
7781 else -> OuraRingHardwareType .UNKNOWN
7882 }
7983 }
84+
8085 companion object {
8186 val logger = LoggerFactory .getLogger(OuraRingConfigurationConverter ::class .java)
8287 }
0 commit comments