enum class SetMowerWorkMode {
Stop, // -> fftf -> 0
Work, // -> tfff -> 1
Home, // -> ftff -> 2
Edge, // -> ffft -> 4
}
@Serializable(with = MowerMode.Serializer::class)
sealed class MowerMode {
@Serializable
@PolymorphicSerializerId(0)
// aka idle 0
object InStopping : MowerMode()
@Serializable
@PolymorphicSerializerId(1)
// aka working 1
object InWorking : MowerMode()
@Serializable
@PolymorphicSerializerId(2)
// aka backhome 2
object InBacking : MowerMode()
@Serializable
@PolymorphicSerializerId(3)
// 3
object InCharging : MowerMode()
@Serializable
@PolymorphicSerializerId(4)
// 4 --> Work Mode Edge? As not handled in response
object Error : MowerMode()
@Serializable
@PolymorphicSerializerId(5)
// 5
object InputPassword : MowerMode()
@Serializable
@PolymorphicSerializerId(6)
// 6
object OtaUpdate : MowerMode()
@Serializable
@PolymorphicSerializerId(7)
// 7
object Edge : MowerMode()
object Serializer : EnumAsNumberSerializer<MowerMode>(MowerMode::class)
}
sealed class MowerDto {
@Serializable(with = PolymorphicMowerDto.Serializer::class)
sealed class PolymorphicMowerDto : MowerDto() {
object Serializer :
PolymorphicSerializer<PolymorphicMowerDto>(PolymorphicMowerDto::class) {
override fun deserializePolymorphicId(element: JsonElement): Pair<JsonElement, Int> {
val elementAsMap = element.jsonObject.toMutableMap()
val type = elementAsMap["cmd"]?.jsonPrimitive?.int ?: error("Could not find 'cmd'")
elementAsMap.remove("cmd")
return JsonObject(elementAsMap) to type
}
override fun serializePolymorphicId(element: JsonElement, id: Int): JsonElement {
val elementAsMap = element.jsonObject.toMutableMap()
elementAsMap["cmd"] = JsonPrimitive(id)
return JsonObject(elementAsMap)
}
}
}
// -> 500 response
@Serializable
@PolymorphicSerializerId(200)
object GetAllDeviceInfoRequest : PolymorphicMowerDto()
// -> 514 response
@Serializable
@PolymorphicSerializerId(214)
object GetDeviceFunctionInfoRequest : PolymorphicMowerDto()
// -> 508 response
@Serializable
@PolymorphicSerializerId(208)
object GetDeviceInfoRequest : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(203)
object GetScheduleRequest : PolymorphicMowerDto()
// -> 507 response
@Serializable
@PolymorphicSerializerId(207)
object GetDeviceZonesRequest : PolymorphicMowerDto()
// -> 505 response
@Serializable
@PolymorphicSerializerId(205)
object GetDeviceRainRequest : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(202)
object GetSomeInfoAfterSetDeviceName : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(215)
object SomeOtaRequest : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(212)
object BatteryInfoRequest : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(101)
data class SetWorkModeRequest(
// See SetWorkMode
val mode: Int,
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(500)
data class AllInfoResponse(
val mode: MowerMode,
@SerialName("power")
val batteryPower: Int,
val station: Boolean,
val name: String,
@SerialName("rain_en")
val rainEnabled: Boolean,
@SerialName("rain_status")
val rainStatus: Int,
@SerialName("rain_delay_set")
val rainDelaySet: Int,
@SerialName("rain_delay_left")
val rainDelayLeft: Int,
// val language: Int,
val model: String,
val version: Int,
@SerialName("sn")
val serialNumber: String,
@SerialName("avail")
val availability: String,
@SerialName("bat_type")
val batteryType: String,
@SerialName("bat_id")
val batteryId: Int,
@SerialName("bat_ctimes")
val batteryChargeTimes: Int,
@SerialName("bat_dtimes")
val batteryDechargeTimes: Int,
// Extra start
@SerialName("wifi_lv")
val wifiLevel: Int = -1,
@SerialName("errortype")
val error: Int = -1, // -1 is default, no error?
@SerialName("bat_change")
val batChange: Int = -1,
@SerialName("on_min")
val onMin: Int = -1,
@SerialName("total_min")
val totalMin: Int = -1,
@SerialName("cur_min")
val curMin: Int = -1,
@SerialName("on_area")
val onArea: Int = 0,
@SerialName("cur_area")
val curArea: Int = 0,
@SerialName("led_en")
val ledEnabled: Boolean = false,
@SerialName("ultra_en")
val ultrasonicEnabled: Boolean = false,
// Extra end
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(201)
data class MachineStatusResponse(
val mode: Int,
@SerialName("power")
val batteryPower: Int,
@SerialName("errortype")
val error: Int = -1, // -1 is default, no error?
@SerialName("wifi_lv")
val wifiLevel: Int = -1,
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(400)
data class ResultResponse(
val command: Int,
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(507)
data class MultiAreasResponse(
@SerialName("mul_auto")
val multizoneAuto: Boolean,
@SerialName("mul_en")
val multizoneEnabled: Boolean,
@SerialName("mul_zon1")
val multizone1: Int,
@SerialName("mul_zon2")
val multizone2: Int,
@SerialName("mul_zon3")
val multizone3: Int,
@SerialName("mul_zon4")
val multizone4: Int,
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(508)
data class DeviceInfoResponse(
val model: String,
val version: Long,
val name: String,
@SerialName("sn")
val serialNumber: String,
@SerialName("avail")
val availability: String,
@SerialName("mb")
val mainBoard: DeviceInfoBoardInfoResponse,
@SerialName("bb")
val borderBoard: DeviceInfoBoardInfoResponse,
@SerialName("db")
val displayBoard: DeviceInfoBoardInfoResponse,
@SerialName("lb")
val ledBoard: DeviceInfoBoardInfoResponse,
@SerialName("btl")
val bootloader: DeviceInfoBootloaderResponse,
) : PolymorphicMowerDto()
@Serializable
data class DeviceInfoBoardInfoResponse(
@SerialName("hv")
val hardwareVersion: Int,
@SerialName("sv")
val softwareVersion: Int,
)
@Serializable
data class DeviceInfoBootloaderResponse(
@SerialName("sv")
val softwareVersion: Int,
)
@Serializable
@PolymorphicSerializerId(501)
data class WorkStatusResponse(
val mode: Int,
@SerialName("power")
val batteryPower: Int,
val station: Boolean,
@SerialName("errortype")
val error: Int = -1, // -1 is default, no error?
@SerialName("on_min")
val onMin: Int = -1,
@SerialName("total_min")
val totalMin: Int = 0,
@SerialName("cur_min")
val curMin: Int = 0,
@SerialName("on_area")
val onArea: Int = 0,
@SerialName("cur_area")
val curArea: Int = 0,
@SerialName("wifi_lv")
val wifiLevel: Int = 0,
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(502)
data class SetDeviceNameResponse(
val name: String,
) : PolymorphicMowerDto()
@Serializable
data class ScheduleDetailResponse(
val start: Int,
val end: Int,
)
@Serializable
data class ScheduleDayResponse(
@SerialName("Trimming")
val trimming: Boolean,
val slice: List<ScheduleDetailResponse>
)
@Serializable
@PolymorphicSerializerId(503)
data class ScheduleResponse(
val auto: Boolean,
// Day will be null if there is no schedule for it
@SerialName("Mon")
val mon: ScheduleDayResponse? = null,
@SerialName("Tue")
val tue: ScheduleDayResponse? = null,
@SerialName("Wed")
val wed: ScheduleDayResponse? = null,
@SerialName("Thu")
val thu: ScheduleDayResponse? = null,
@SerialName("Fri")
val fri: ScheduleDayResponse? = null,
@SerialName("Sat")
val sat: ScheduleDayResponse? = null,
@SerialName("Sun")
val sun: ScheduleDayResponse? = null,
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(504)
data class SetPasswordResponse(
@SerialName("passwd_res")
val response: Boolean,
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(505)
data class RainResultResponse(
@SerialName("rain_en")
val rainEnabled: Boolean,
@SerialName("rain_status")
val rainStatus: Int,
@SerialName("rain_delay_set")
val rainDelaySet: Int,
@SerialName("rain_delay_left")
val rainDelayLeft: Int,
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(512)
data class BatteryInfoResponse(
@SerialName("bat_type")
val batteryType: String,
@SerialName("bat_id")
val batteryId: Int,
@SerialName("bat_ctimes")
val batteryChargeTimes: Int,
@SerialName("bat_dtimes")
val batteryDechargeTimes: Int,
@SerialName("bat_change")
val batteryChange: String,
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(513)
object DeviceUpdateResponse : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(514)
data class EnableResponse(
val gps: Int,
val iot: Int,
val led: Int,
@SerialName("multizone")
val multiZone: Int,
val rain: Int,
val schedule: Int,
@SerialName("ultra")
val ultrasonic: Int,
val map: Int,
@SerialName("info_stat")
val infoStat: Int,
// From actual response
val language: Int,
val password: Int,
val sp: Int,
val region: Int,
val service: Int,
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(522)
data class UnknownResponse(
val ver: Int,
val area: Int,
) : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(10100)
object StopResponse : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(10101)
object WorkResponse : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(10102)
object HomeResponse : PolymorphicMowerDto()
@Serializable
@PolymorphicSerializerId(107)
data class SetDeviceNameRequest(
@SerialName("rename")
val name: String,
) : PolymorphicMowerDto()
data class SetWorkResponse(val result: Boolean) : MowerDto()
data class SetFileInfoResponse(val result: Boolean) : MowerDto()
data class DownloadResponse(val result: Boolean) : MowerDto()
}