feat: make PowerOn a plain GET request without auth and add custom trigger app launcher icon
@@ -6,9 +6,9 @@
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@android:drawable/sym_def_app_icon"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@android:drawable/sym_def_app_icon"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.ExpApp">
|
||||
<activity
|
||||
|
||||
@@ -23,21 +23,34 @@ class TriggerClient(
|
||||
private val jsonMediaType = "application/json; charset=utf-8".toMediaType()
|
||||
|
||||
fun buildRequest(device: DeviceConfig, action: TriggerAction): Request {
|
||||
val targetUrl = when (action) {
|
||||
TriggerAction.POWER_ON -> device.powerOnUrl
|
||||
TriggerAction.POWER_OFF -> device.powerOffUrl
|
||||
TriggerAction.REBOOT -> device.rebootUrl
|
||||
return when (action) {
|
||||
TriggerAction.POWER_ON -> {
|
||||
Request.Builder()
|
||||
.url(device.powerOnUrl)
|
||||
.get()
|
||||
.build()
|
||||
}
|
||||
TriggerAction.POWER_OFF -> {
|
||||
val jsonPayload = """{"node":"${device.node}"}"""
|
||||
val body = jsonPayload.toRequestBody(jsonMediaType)
|
||||
Request.Builder()
|
||||
.url(device.powerOffUrl)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.addHeader("X-Secret-Key", device.secretKey)
|
||||
.post(body)
|
||||
.build()
|
||||
}
|
||||
TriggerAction.REBOOT -> {
|
||||
val jsonPayload = """{"node":"${device.node}"}"""
|
||||
val body = jsonPayload.toRequestBody(jsonMediaType)
|
||||
Request.Builder()
|
||||
.url(device.rebootUrl)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.addHeader("X-Secret-Key", device.secretKey)
|
||||
.post(body)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
val jsonPayload = """{"node":"${device.node}"}"""
|
||||
val body = jsonPayload.toRequestBody(jsonMediaType)
|
||||
|
||||
return Request.Builder()
|
||||
.url(targetUrl)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.addHeader("X-Secret-Key", device.secretKey)
|
||||
.post(body)
|
||||
.build()
|
||||
}
|
||||
|
||||
fun sendTrigger(
|
||||
|
||||
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
@@ -64,12 +64,13 @@ class TriggerClientTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun buildRequest_powerOn_usesPowerOnUrl() {
|
||||
fun buildRequest_powerOn_usesGetMethodWithoutSecretKey() {
|
||||
val request = client.buildRequest(sampleDevice, TriggerAction.POWER_ON)
|
||||
|
||||
assertEquals("POST", request.method)
|
||||
assertEquals("GET", request.method)
|
||||
assertEquals("https://cosmos.linuxguy.space/poweron", request.url.toString())
|
||||
assertEquals("Carbon@12", request.header("X-Secret-Key"))
|
||||
org.junit.Assert.assertNull(request.header("X-Secret-Key"))
|
||||
org.junit.Assert.assertNull(request.body)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||