-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- and again clean up
- Loading branch information
Showing
29 changed files
with
274 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/io/rudolph/netatmo/api/common/CommonConnector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.rudolph.netatmo.api.common | ||
|
||
import io.rudolph.netatmo.api.common.model.MeasureRequestResponse | ||
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.Executable | ||
import io.rudolph.netatmo.oauth2.toTimestamp | ||
import retrofit2.Retrofit | ||
import java.time.LocalDateTime | ||
|
||
|
||
abstract class CommonConnector(api: Retrofit) { | ||
private val apiService = api.create(CommonService::class.java) | ||
|
||
/** | ||
* Retrieve data from a device or module (Weather station and Thermostat only). | ||
* | ||
* required scope: read_station read_thermostat | ||
* | ||
* @see [Netatmo Api Reference] (https://dev.netatmo.com/resources/technical/reference/common/getmeasure) | ||
* | ||
* @param moduleId Mac address of the module you’re interested in. If not specified, returns data of the device. If specified, returns data from the specified module. | ||
* @param deviceId Mac address of the device (can be found via getuser) | ||
* @param scale Timelapse between two measurements | ||
* @param type Measures you are interested in. Data you can request depends on the scale. See full details | ||
* @param dateBegin Timestamp of the first measure to retrieve. Default is null. | ||
* @param dateEnd Timestamp of the last measure to retrieve (default and max are 1024). Default is null. | ||
* @param limit Maximum number of measurements (default and max are 1024) | ||
* @param optimize Determines the format of the answer. Default is true. For mobile apps we recommend True and False if bandwidth isn't an issue as it is easier to parse. | ||
* @param realTime If scale different than max, timestamps are by default offset + scale/2. To get exact timestamps, use true. Default is false. | ||
* @return an executable object to obtain the [MeasureRequestResponse] | ||
*/ | ||
fun getMeasure( | ||
moduleId: String, | ||
deviceId: String, | ||
scale: Scale, | ||
type: ScaleType, | ||
dateBegin: LocalDateTime? = null, | ||
dateEnd: LocalDateTime? = null, | ||
limit: Int? = null, | ||
optimize: Boolean? = null, | ||
realTime: String? = null | ||
): Executable<TypedBaseResult<List<MeasureRequestResponse>>> { | ||
return apiService.getMeasure( | ||
accessToken = "empty", | ||
moduleId = moduleId, | ||
deviceId = deviceId, | ||
scale = scale.value, | ||
type = type.value, | ||
dateBegin = dateBegin.toTimestamp(), | ||
dateEnd = dateEnd.toTimestamp(), | ||
limit = limit, | ||
optimize = optimize, | ||
realTime = realTime | ||
).let { | ||
Executable(it) | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...olph/netatmo/api/misc/model/DeviceType.kt → ...ph/netatmo/api/common/model/DeviceType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/io/rudolph/netatmo/api/common/model/MeasureRequestResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.rudolph.netatmo.api.common.model | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import java.time.LocalDateTime | ||
|
||
data class MeasureRequestResponse( | ||
@JsonProperty("beg_time") | ||
val begTime: LocalDateTime, | ||
|
||
@JsonProperty("step_time") | ||
val stepTime: LocalDateTime, | ||
|
||
@JsonProperty("value") | ||
val value: MutableList<MutableList<Float>>?= mutableListOf<MutableList<Float>>() | ||
) |
20 changes: 20 additions & 0 deletions
20
src/main/java/io/rudolph/netatmo/api/common/model/Scale.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.rudolph.netatmo.api.common.model | ||
|
||
enum class Scale(val value: String) { | ||
MAX("max"), | ||
|
||
HALFHOUR("30min"), | ||
|
||
HOUR("1hour"), | ||
|
||
THREEHOURS("3hours"), | ||
|
||
DAY("1day"), | ||
|
||
WEEK("1week"), | ||
|
||
MONTH("1month"), | ||
|
||
UNKNOWN("unknown") | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/io/rudolph/netatmo/api/common/model/ScaleType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.rudolph.netatmo.api.common.model | ||
|
||
enum class ScaleType(val value: String, val unit: String = "") { | ||
TEMPERATURE("Temperature", "°C"), | ||
CO2("CO2 ", "ppm"), | ||
HUMIDITY("Humidity ", "%"), | ||
PRESSURE("Pressure ", "mbar"), | ||
NOISE("Noise ", "db"), | ||
RAIN("Rain ", "mm"), | ||
WINDSTRENGTH("WindStrength ", "km/h"), | ||
WINDANGLE("WindAngle ", "angles"), | ||
GUSTSTRENGTH("Guststrength ", "km/h"), | ||
GUSTANGLE("GustAngle ", "angles"), | ||
MIN_TEMP("min_temp"), | ||
MAX_TEMP("max_temp"), | ||
MIN_HUM("min_hum"), | ||
MAX_HUM("max_hum"), | ||
MAX_PRESSURE("max_pressure"), | ||
SUM_RAIN("sum_rain"), | ||
DATE_MAX_HUM("date_max_hum"), | ||
MIN_PRESSURE("min_pressure"), | ||
DATE_MIN_PRESSURE("date_min_pressure"), | ||
DATE_MAX_PRESSURE("date_max_pressure"), | ||
MIN_NOISE("min_noise"), | ||
DATE_MIN_NOISE("date_min_noise"), | ||
MAX_NOISE("max_noise"), | ||
DATE_MAX_NOISE("date_max_noise"), | ||
DATE_MIN_CO2("date_min_co2"), | ||
DATE_MAX_CO2("date_max_co2"), | ||
DATE_MAX_GUST("date_max_gust"), | ||
UNKNOWN("unknown") | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/io/rudolph/netatmo/api/common/service/CommonService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.rudolph.netatmo.api.common.service | ||
|
||
import io.rudolph.netatmo.api.common.model.MeasureRequestResponse | ||
import io.rudolph.netatmo.api.energy.model.TypedBaseResult | ||
import retrofit2.Call | ||
import retrofit2.http.GET | ||
import retrofit2.http.Headers | ||
import retrofit2.http.Query | ||
|
||
interface CommonService { | ||
|
||
@Headers("Content-Type:text/plain") | ||
@GET("getmeasure") | ||
fun getMeasure( | ||
@Query("access_token") accessToken: String, | ||
@Query("device_id") deviceId: String, | ||
@Query("module_id") moduleId: String, | ||
@Query("scale") scale: String, | ||
@Query("type") type: String, | ||
@Query("date_begin") dateBegin: Long? = null, | ||
@Query("date_end") dateEnd: Long? = null, | ||
@Query("limit") limit: Int? = null, | ||
@Query("optimize") optimize: Boolean? = null, | ||
@Query("real_time") realTime: String? = null | ||
): Call<TypedBaseResult<List<MeasureRequestResponse>>> | ||
} |
4 changes: 2 additions & 2 deletions
4
.../misc/transform/DeviceTypeDeserializer.kt → ...ommon/transform/DeviceTypeDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...pi/misc/transform/DeviceTypeSerializer.kt → .../common/transform/DeviceTypeSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mo/transform/LocalDateTimeDeserializer.kt → ...on/transform/LocalDateTimeDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...transform/LocalDateTimeKeyDeserializer.kt → ...transform/LocalDateTimeKeyDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...atmo/transform/LocalDateTimeSerializer.kt → ...mmon/transform/LocalDateTimeSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/io/rudolph/netatmo/api/common/transform/ScaleDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.rudolph.netatmo.api.common.transform | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import io.rudolph.netatmo.api.common.model.Scale | ||
|
||
|
||
class ScaleDeserializer : JsonDeserializer<Scale>() { | ||
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): Scale { | ||
return p?.valueAsString?.let { name -> | ||
Scale.values().find { | ||
it.value == name | ||
} | ||
} ?: Scale.UNKNOWN | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/io/rudolph/netatmo/api/common/transform/ScaleSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.rudolph.netatmo.api.common.transform | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator | ||
import com.fasterxml.jackson.databind.JsonSerializer | ||
import com.fasterxml.jackson.databind.SerializerProvider | ||
import io.rudolph.netatmo.api.common.model.Scale | ||
|
||
|
||
class ScaleSerializer : JsonSerializer<Scale>() { | ||
override fun serialize(value: Scale, gen: JsonGenerator, serializers: SerializerProvider?) { | ||
gen.writeString(value.value) | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/io/rudolph/netatmo/api/common/transform/ScaleTypeDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.rudolph.netatmo.api.common.transform | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import io.rudolph.netatmo.api.common.model.ScaleType | ||
|
||
|
||
class ScaleTypeDeserializer : JsonDeserializer<ScaleType>() { | ||
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): ScaleType { | ||
return p?.valueAsString?.let { name -> | ||
ScaleType.values().find { | ||
it.value == name | ||
} | ||
} ?: ScaleType.UNKNOWN | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/io/rudolph/netatmo/api/common/transform/ScaleTypeSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.rudolph.netatmo.api.common.transform | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator | ||
import com.fasterxml.jackson.databind.JsonSerializer | ||
import com.fasterxml.jackson.databind.SerializerProvider | ||
import io.rudolph.netatmo.api.common.model.ScaleType | ||
|
||
|
||
class ScaleTypeSerializer : JsonSerializer<ScaleType>() { | ||
override fun serialize(value: ScaleType, gen: JsonGenerator, serializers: SerializerProvider?) { | ||
gen.writeString(value.value) | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...ph/netatmo/transform/ScopeDeserializer.kt → ...api/common/transform/ScopeDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/main/java/io/rudolph/netatmo/api/energy/EnergyConnector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/io/rudolph/netatmo/api/energy/model/HomeStatusModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/java/io/rudolph/netatmo/api/energy/service/EnergyService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.