Skip to content

Commit 8e23e02

Browse files
committed
bugfixes and tests
- failing scope permissions fix in interceptor - fixes models fpr presences - adds new test for presence
1 parent 901bec6 commit 8e23e02

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ plugins {
1515
}
1616

1717
group 'io.rudolph.netatmo'
18-
version '0.3.1'
18+
version '0.3.2'
1919

2020
repositories {
2121
mavenCentral()

src/main/java/io/rudolph/netatmo/api/presence/model/PresenceHome.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package io.rudolph.netatmo.api.presence.model
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
34
import com.fasterxml.jackson.annotation.JsonProperty
45
import io.rudolph.netatmo.api.aircare.model.Place
56

6-
7+
@JsonIgnoreProperties(ignoreUnknown = true)
78
data class PresenceHome(
89
@JsonProperty("cameras")
910
val cameras: List<Camera>? = null,
1011

1112
@JsonProperty("persons")
1213
val persons: List<Person>? = null,
1314

15+
/**
16+
* comming soon
17+
@JsonProperty("smokedetectors")
18+
val detector: Unit,
19+
*/
20+
1421
@JsonProperty("name")
1522
val name: String? = null,
1623

src/main/java/io/rudolph/netatmo/api/presence/model/User.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ data class User(
1111
val lang: String? = null,
1212

1313
@JsonProperty("country")
14-
val country: String? = null
14+
val country: String? = null,
15+
16+
@JsonProperty("mail")
17+
val mail: String
1518
)

src/main/java/io/rudolph/netatmo/oauth2/networkinterceptor/AuthInterceptor.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,21 @@ internal class AuthInterceptor(private val userMail: String?,
9696
}
9797

9898
private fun proceedAuthRequest(chain: Interceptor.Chain, request: Request): String? {
99-
return chain.proceed(request)?.body()?.string()?.let {
100-
JacksonTransform.deserialize<AuthResponse>(it)
99+
return chain.proceed(request)?.let {
100+
if (!it.isSuccessful) {
101+
return@let null
102+
}
103+
it.body()
104+
?.string()
101105
?.let {
102-
if (!(it.scope.sortedBy { it.value }.toTypedArray() contentEquals tokenStore.scope.sortedBy { it.value }.toTypedArray())) {
103-
logger.warn("Scope from response does not match requested scope")
104-
}
105-
tokenStore.setTokens(it.accessToken, it.refreshToken, it.scope)
106-
it.accessToken
106+
JacksonTransform.deserialize<AuthResponse>(it)
107+
?.let {
108+
if (!(it.scope.sortedBy { it.value }.toTypedArray() contentEquals tokenStore.scope.sortedBy { it.value }.toTypedArray())) {
109+
logger.warn("Scope from response does not match requested scope")
110+
}
111+
tokenStore.setTokens(it.accessToken, it.refreshToken, it.scope)
112+
it.accessToken
113+
}
107114
}
108115
}
109116
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package apitest
2+
3+
import io.rudolph.netatmo.oauth2.model.Scope
4+
import org.junit.Test
5+
6+
class PresenceTest : BaseTest(listOf(Scope.READ_CAMERA, Scope.ACCESS_CAMERA, Scope.READ_PRESENCE, Scope.ACCESS_PRESENCE)) {
7+
8+
val connector = api.presenceApi
9+
10+
@Test
11+
fun getPublicData() {
12+
connector.getHomeData().executeSync().apply {
13+
assert(this != null)
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)