Skip to content

Commit

Permalink
add welcome and presence api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
navybk committed Jul 25, 2018
1 parent bfbd066 commit 8d1608a
Show file tree
Hide file tree
Showing 30 changed files with 995 additions and 43 deletions.
7 changes: 7 additions & 0 deletions src/main/java/io/rudolph/netatmo/Extension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.rudolph.netatmo

import io.rudolph.netatmo.executable.Executable
import retrofit2.Call

val <T> Call<T>.executable: Executable<T>
get() = Executable(this)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.rudolph.netatmo.api.common.transform
package io.rudolph.netatmo

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
Expand All @@ -7,13 +7,16 @@ import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import io.rudolph.netatmo.api.common.model.DeviceType
import io.rudolph.netatmo.api.common.model.Scale
import io.rudolph.netatmo.api.common.model.ScaleType
import io.rudolph.netatmo.api.common.transform.*
import io.rudolph.netatmo.api.energy.model.TemperatureType
import io.rudolph.netatmo.api.energy.model.ThermMode
import io.rudolph.netatmo.api.energy.model.ZoneType
import io.rudolph.netatmo.api.energy.model.transform.TemperaturTypeDeserializer
import io.rudolph.netatmo.api.energy.model.transform.ThermModeDeserializer
import io.rudolph.netatmo.api.energy.model.transform.ZoneTypeDeserializer
import io.rudolph.netatmo.api.energy.model.transform.ZoneTypeSerializer
import io.rudolph.netatmo.api.presence.model.EventType
import io.rudolph.netatmo.api.presence.transform.EventTypeDeserializer
import io.rudolph.netatmo.api.weather.model.Measure
import io.rudolph.netatmo.api.weather.model.transform.MeasureDeserializer
import io.rudolph.netatmo.oauth2.model.Scope
Expand All @@ -35,6 +38,7 @@ internal object JacksonTransform {
addDeserializer(Measure::class.java, MeasureDeserializer())
addDeserializer(Scale::class.java, ScaleDeserializer())
addDeserializer(ScaleType::class.java, ScaleTypeDeserializer())
addDeserializer(EventType::class.java, EventTypeDeserializer())

addSerializer(DeviceType::class.java, DeviceTypeSerializer())
addSerializer(ZoneType::class.java, ZoneTypeSerializer())
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/io/rudolph/netatmo/NetatmoApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package io.rudolph.netatmo

import com.jakewharton.retrofit2.adapter.kotlin.coroutines.experimental.CoroutineCallAdapterFactory
import io.rudolph.netatmo.api.aircare.AirCareConnector
import io.rudolph.netatmo.api.common.transform.JacksonTransform
import io.rudolph.netatmo.api.energy.EnergyConnector
import io.rudolph.netatmo.api.presence.PresenceConnector
import io.rudolph.netatmo.api.weather.WeatherConnector
import io.rudolph.netatmo.api.welcome.WelcomeConnector
import io.rudolph.netatmo.oauth2.TokenStorage
import io.rudolph.netatmo.oauth2.model.Scope
import io.rudolph.netatmo.oauth2.networkinterceptor.AuthInterceptor
Expand Down Expand Up @@ -107,4 +108,6 @@ class NetatmoApi(userMail: String? = null,
val energyApiConnector = EnergyConnector(api)
val weatherApiConnector = WeatherConnector(api)
val airCareConnector = AirCareConnector(api)
val presenceConnector = PresenceConnector(api)
val welcomeConnector = WelcomeConnector(api)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.rudolph.netatmo.api.aircare.model.AirCareBody
import io.rudolph.netatmo.api.aircare.service.AirCareService
import io.rudolph.netatmo.api.common.CommonConnector
import io.rudolph.netatmo.api.energy.model.TypedBaseResult
import io.rudolph.netatmo.executable
import io.rudolph.netatmo.executable.Executable
import retrofit2.Retrofit

Expand All @@ -25,10 +26,7 @@ class AirCareConnector(api: Retrofit) : CommonConnector(api) {
return airCareService.getPublicData(
"Empty",
deviceId// will be replaced in Chain.proceed(accessToken: String)
)
.let {
Executable(it)
}
).executable
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.rudolph.netatmo.api.common.model.Scale
import io.rudolph.netatmo.api.common.model.ScaleType
import io.rudolph.netatmo.api.common.service.CommonService
import io.rudolph.netatmo.api.energy.model.TypedBaseResult
import io.rudolph.netatmo.executable
import io.rudolph.netatmo.executable.Executable
import io.rudolph.netatmo.oauth2.toTimestamp
import retrofit2.Retrofit
Expand Down Expand Up @@ -54,8 +55,6 @@ abstract class CommonConnector(api: Retrofit) {
limit = limit,
optimize = optimize,
realTime = realTime
).let {
Executable(it)
}
).executable
}
}
37 changes: 10 additions & 27 deletions src/main/java/io/rudolph/netatmo/api/energy/EnergyConnector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.rudolph.netatmo.api.common.CommonConnector
import io.rudolph.netatmo.api.common.model.DeviceType
import io.rudolph.netatmo.api.energy.model.*
import io.rudolph.netatmo.api.energy.service.EnergyService
import io.rudolph.netatmo.executable
import io.rudolph.netatmo.executable.Executable
import io.rudolph.netatmo.oauth2.toTimestamp
import retrofit2.Retrofit
Expand All @@ -27,9 +28,7 @@ class EnergyConnector(api: Retrofit) : CommonConnector(api) {
fun getHomesData(homeId: String? = null,
gatewayTypes: List<DeviceType>? = null): Executable<TypedBaseResult<HomesDataBody>> {
return energyService.getHomeData(homeId, gatewayTypes?.toMutableList())
.let {
Executable(it)
}
.executable
}

/**
Expand All @@ -46,9 +45,7 @@ class EnergyConnector(api: Retrofit) : CommonConnector(api) {
fun getHomeStatus(homeId: String,
deviceTypes: List<DeviceType>? = null): Executable<TypedBaseResult<HomeStatusBody>> {
return energyService.getHomeStatus(homeId, deviceTypes?.toMutableList())
.let {
Executable(it)
}
.executable
}

/**
Expand Down Expand Up @@ -87,9 +84,7 @@ class EnergyConnector(api: Retrofit) : CommonConnector(api) {
limit,
optimize,
realTime)
.let {
Executable(it)
}
.executable
}

/**
Expand All @@ -110,9 +105,7 @@ class EnergyConnector(api: Retrofit) : CommonConnector(api) {
return energyService.setRoomThermMode(homeId,
thermMode,
endTime.toTimestamp())
.let {
Executable(it)
}
.executable
}

/**
Expand All @@ -139,9 +132,7 @@ class EnergyConnector(api: Retrofit) : CommonConnector(api) {
mode,
temperature,
endTime.toTimestamp())
.let {
Executable(it)
}
.executable
}

/**
Expand Down Expand Up @@ -193,9 +184,7 @@ class EnergyConnector(api: Retrofit) : CommonConnector(api) {
hgTemp,
awayTemp)
return energyService.setSyncHomeSchedule(body)
.let {
Executable(it)
}
.executable
}

/**
Expand All @@ -213,9 +202,7 @@ class EnergyConnector(api: Retrofit) : CommonConnector(api) {
fun renameHomeSchedule(scheduleId: String,
name: String,
homeId: String): Executable<BaseResult> {
return energyService.postRenameHomeSchedule(scheduleId, name, homeId).let {
Executable(it)
}
return energyService.postRenameHomeSchedule(scheduleId, name, homeId).executable
}

/**
Expand All @@ -231,9 +218,7 @@ class EnergyConnector(api: Retrofit) : CommonConnector(api) {
*/
fun deleteHomeSchedule(scheduleId: String,
homeId: String): Executable<BaseResult> {
return energyService.deleteHomeSchedule(scheduleId, homeId).let {
Executable(it)
}
return energyService.deleteHomeSchedule(scheduleId, homeId).executable
}

/**
Expand Down Expand Up @@ -264,9 +249,7 @@ class EnergyConnector(api: Retrofit) : CommonConnector(api) {
hgTemp,
awayTemp)
return energyService.createNewHomeSchedule(body)
.let {
Executable(it)
}
.executable
}


Expand Down
Loading

0 comments on commit 8d1608a

Please sign in to comment.