-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitchBotRepository.kt
45 lines (43 loc) · 1.52 KB
/
SwitchBotRepository.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.atria.wear_os_test.presentation
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
class SwitchBotRepository {
suspend fun turnOff(){
val moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://api.switch-bot.com/v1.0/devices/*ここにデバイスID*/")
.addConverterFactory(MoshiConverterFactory.create(moshi))
.build()
val service = retrofit.create(SwitchBotAPI::class.java)
service.turn(
token = "",
params = SwitchBotAPI.Params(
command ="turnOff",
parameter = "default",
commandType = "command",
)
)
}
suspend fun turnOn(){
val moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://api.switch-bot.com/v1.0/devices/*ここにデバイスID*/")
.addConverterFactory(MoshiConverterFactory.create(moshi))
.build()
val service = retrofit.create(SwitchBotAPI::class.java)
service.turn(
token = "",
params = SwitchBotAPI.Params(
command ="turnOn",
parameter = "default",
commandType = "command",
)
)
}
}