Skip to content

Commit

Permalink
Changed App type value
Browse files Browse the repository at this point in the history
  • Loading branch information
navybk committed Aug 13, 2018
1 parent 6cb6004 commit 901bec6
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 66 deletions.
3 changes: 3 additions & 0 deletions src/main/java/io/rudolph/netatmo/JacksonTransform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ 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.*
import io.rudolph.netatmo.api.presence.model.AppType
import io.rudolph.netatmo.api.presence.model.EventType
import io.rudolph.netatmo.api.presence.transform.AppTypeDeserializer
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
Expand All @@ -36,6 +38,7 @@ internal object JacksonTransform {
addDeserializer(Scale::class.java, ScaleDeserializer())
addDeserializer(ScaleType::class.java, ScaleTypeDeserializer())
addDeserializer(EventType::class.java, EventTypeDeserializer())
addDeserializer(AppType::class.java, AppTypeDeserializer())

addSerializer(ThermMode::class.java, ThermModeSerializer())
addSerializer(DeviceType::class.java, DeviceTypeSerializer())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.rudolph.netatmo.api.presence.model

enum class AppType(val value: String = "unknown") {
CAMERA("app_camera"),
UNKNOWN
}
13 changes: 13 additions & 0 deletions src/main/java/io/rudolph/netatmo/api/presence/model/BaseEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.rudolph.netatmo.api.presence.model

import com.fasterxml.jackson.annotation.JsonAlias
import com.fasterxml.jackson.annotation.JsonProperty

data class BaseEvent(
/**
* Identifier of the event
*/
@JsonProperty("id")
@JsonAlias("id", "event_id")
override val id: String? = null)
: Event()
121 changes: 62 additions & 59 deletions src/main/java/io/rudolph/netatmo/api/presence/model/Event.kt
Original file line number Diff line number Diff line change
@@ -1,74 +1,77 @@
package io.rudolph.netatmo.api.presence.model

import com.fasterxml.jackson.annotation.JsonAlias
import com.fasterxml.jackson.annotation.JsonProperty


data class Event(
/**
* Subtypes of SD and Alim events. Go to Cameras page for further details.
*
* TODO change type to [EventSubType]
*/
@JsonProperty("sub_type")
val subType: String? = null,
abstract class Event {
/**
* Subtypes of SD and Alim events. Go to Cameras page for further details.
*
* TODO change type to [EventSubType]
*/
@JsonProperty("sub_type")
val subType: EventType? = null

/**
* Camera that detected the event
*/
@JsonProperty("camera_id")
val cameraId: String? = null,
/**
* Camera that detected the event
*/
@JsonProperty("camera_id")
val cameraId: String? = null

/**
* Status of the video (recording, deleted or available)
*/
@JsonProperty("video_status")
val videoStatus: String? = null,
/**
* Status of the video (recording deleted or available)
*/
@JsonProperty("video_status")
val videoStatus: String? = null

/**
* Identifier of the event
*/
@JsonProperty("id")
val id: String? = null,
/**
* Identifier of the event
*/
@JsonProperty("id")
@JsonAlias("id", "event_id")
open val id: String? = null

/**
* Time of occurence of event
*/
@JsonProperty("time")
val time: Int? = null,
/**
* Time of occurence of event
*/
@JsonProperty("time")
val time: Int? = null

/**
* Type of events.
*/
@JsonProperty("type")
val type: EventType? = null,
/**
* Type of events.
*/
@JsonProperty("type")
@JsonAlias("event_type", "type")
val type: EventType? = null

/**
* User facing event description
*/
@JsonProperty("message")
val message: String? = null,
/**
* User facing event description
*/
@JsonProperty("message")
val message: String? = null

/**
* If person was considered "away" before being seen during this event
*/
@JsonProperty("is_arrival")
val isArrival: Boolean? = null,
/**
* If person was considered "away" before being seen during this event
*/
@JsonProperty("is_arrival")
val isArrival: Boolean? = null

/**
* Snapshot id, version and key. (Used in [io.rudolph.netatmo.api.presence.PresenceConnector.getCameraPicture])
*/
@JsonProperty("snapshot")
val snapshot: Snapshot? = null,
/**
* Snapshot id version and key. (Used in [io.rudolph.netatmo.api.presence.PresenceConnector.getCameraPicture])
*/
@JsonProperty("snapshot")
val snapshot: Snapshot? = null

/**
* Id of the person the event is about (if any)
*/
@JsonProperty("person_id")
val personId: String? = null,
/**
* Id of the person the event is about (if any)
*/
@JsonProperty("person_id")
val personId: String? = null

/**
* Identifier of the video
*/
@JsonProperty("video_id")
val videoId: String? = null
)
/**
* Identifier of the video
*/
@JsonProperty("video_id")
val videoId: String? = null
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import com.fasterxml.jackson.annotation.JsonProperty

data class Events(
@JsonProperty("events_list")
val eventsList: List<Event>? = null
val eventsList: List<BaseEvent>? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.rudolph.netatmo.api.presence.model

import com.fasterxml.jackson.annotation.JsonProperty

data class PersonsEvent(

@JsonProperty("app_type")
val appType: AppType,

@JsonProperty("persons")
val persons: List<PersonsEventPerson> = mutableListOf(),

@JsonProperty("snapshot_id")
val snapshotId: String?,

@JsonProperty("snapshot_key")
val snapshotKey: String?,

@JsonProperty("home_id")
val homeId: String,

@JsonProperty("home_name")
val homeName: String
) : Event()
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.rudolph.netatmo.api.presence.model

import com.fasterxml.jackson.annotation.JsonProperty

data class PersonsEventPerson(
@JsonProperty("id")
val id: String,

@JsonProperty("face_id")
val faceId: String,

@JsonProperty("face_key")
val faceKey: String,

@JsonProperty("is_known")
val isKnown: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ data class PresenceHome(
val place: Place? = null,

@JsonProperty("events")
val events: List<Event>? = null,
val events: List<BaseEvent>? = null,

@JsonProperty("modules")
val modules: List<PresenceModule>? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.rudolph.netatmo.api.presence.transform

import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import io.rudolph.netatmo.api.presence.model.AppType


class AppTypeDeserializer : JsonDeserializer<AppType>() {
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): AppType {
return p?.valueAsString?.let { name ->
AppType.values().find {
it.value == name
}
} ?: AppType.UNKNOWN
}
}
11 changes: 11 additions & 0 deletions src/main/java/io/rudolph/netatmo/api/welcome/WelcomeConnector.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.rudolph.netatmo.api.welcome

import io.rudolph.netatmo.JacksonTransform
import io.rudolph.netatmo.api.energy.model.BaseResult
import io.rudolph.netatmo.api.presence.PresenceConnector
import io.rudolph.netatmo.api.presence.model.Events
import io.rudolph.netatmo.api.presence.model.PersonsEvent
import io.rudolph.netatmo.api.welcome.service.WelcomeService
import io.rudolph.netatmo.executable
import io.rudolph.netatmo.executable.BodyResultExecutable
Expand Down Expand Up @@ -87,4 +89,13 @@ class WelcomeConnector(api: Retrofit) : PresenceConnector(api) {
return setPersonsHome(homeId, listOf(personId))
}

fun onExternalCameraEvent(jsonString: String): PersonsEvent? {
return try {
JacksonTransform.deserialize<PersonsEvent>(jsonString)
} catch (e: Exception) {
e.printStackTrace()
null
}
}

}

0 comments on commit 901bec6

Please sign in to comment.