-
-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial proof-of-concept: sharing Session over data layer * Add initial onboarding and login flow In onboarding, the home assistant urls are received from connected devices. If the user clicks on it, the authentication flow starts. The user can alter the login details and proceed to login. The authentication uses the "auth/login_flow" api, instead of the normal authentication api, since there is no support for webview on wear os. * Clean up wear and app communication Clean up * Add proof of authentication on home. And add logout button on home * Update onboarding list * Add loading views and error messages * Move startup logic to HomeActivity to hopefully save some resources * Add manual setup option and improve UI * Cleanup * Passing ktLintCheck * Passing ktLintCheck after rebase * Fix building after build.gradle changes during rebase * Process review comments Remove multiple product flavors Remove unnecessary log Replace margin with additional header
- Loading branch information
1 parent
d5ae97e
commit 5f904b9
Showing
65 changed files
with
1,853 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ google-services.json | |
.idea/ | ||
.gradle/ | ||
build/ | ||
*.keystore |
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
10 changes: 10 additions & 0 deletions
10
...rc/main/java/io/homeassistant/companion/android/onboarding/OnboardingListenerComponent.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,10 @@ | ||
package io.homeassistant.companion.android.onboarding | ||
|
||
import dagger.Component | ||
import io.homeassistant.companion.android.common.dagger.AppComponent | ||
|
||
@Component(dependencies = [AppComponent::class]) | ||
interface OnboardingListenerComponent { | ||
|
||
fun inject(listener: WearOnboardingListener) | ||
} |
57 changes: 57 additions & 0 deletions
57
app/src/main/java/io/homeassistant/companion/android/onboarding/WearOnboardingListener.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,57 @@ | ||
package io.homeassistant.companion.android.onboarding | ||
|
||
import android.util.Log | ||
import com.google.android.gms.wearable.MessageEvent | ||
import com.google.android.gms.wearable.PutDataMapRequest | ||
import com.google.android.gms.wearable.PutDataRequest | ||
import com.google.android.gms.wearable.Wearable | ||
import com.google.android.gms.wearable.WearableListenerService | ||
import io.homeassistant.companion.android.common.dagger.GraphComponentAccessor | ||
import io.homeassistant.companion.android.common.data.authentication.AuthenticationRepository | ||
import io.homeassistant.companion.android.common.data.url.UrlRepository | ||
import kotlinx.coroutines.runBlocking | ||
import javax.inject.Inject | ||
|
||
class WearOnboardingListener : WearableListenerService() { | ||
|
||
@Inject | ||
lateinit var authenticationUseCase: AuthenticationRepository | ||
|
||
@Inject | ||
lateinit var urlUseCase: UrlRepository | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
DaggerOnboardingListenerComponent.builder() | ||
.appComponent((applicationContext.applicationContext as GraphComponentAccessor).appComponent) | ||
.build() | ||
.inject(this) | ||
} | ||
|
||
override fun onMessageReceived(event: MessageEvent) { | ||
Log.d("WearOnboardingListener", "onMessageReceived: $event") | ||
|
||
if (event.path == "/request_home_assistant_instance") { | ||
val nodeId = event.sourceNodeId | ||
sendHomeAssistantInstance(nodeId) | ||
} | ||
} | ||
|
||
private fun sendHomeAssistantInstance(nodeId: String) = runBlocking { | ||
Log.d("WearOnboardingListener", "sendHomeAssistantInstance: $nodeId") | ||
// Retrieve current instance | ||
val url = urlUseCase.getUrl() | ||
|
||
// Put as DataMap in data layer | ||
val putDataReq: PutDataRequest = PutDataMapRequest.create("/home_assistant_instance").run { | ||
dataMap.putString("name", url?.host.toString()) | ||
dataMap.putString("url", url.toString()) | ||
setUrgent() | ||
asPutDataRequest() | ||
} | ||
Wearable.getDataClient(this@WearOnboardingListener).putDataItem(putDataReq).apply { | ||
addOnSuccessListener { Log.d("WearOnboardingListener", "sendHomeAssistantInstance: success") } | ||
addOnFailureListener { Log.d("WearOnboardingListener", "sendHomeAssistantInstance: failed") } | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources xmlns:tools="http://schemas.android.com/tools" | ||
tools:keep="@array/android_wear_capabilities"> | ||
<string-array name="android_wear_capabilities"> | ||
<item>request_authentication_token</item> | ||
<item>request_home_assistant_instance</item> | ||
</string-array> | ||
</resources> |
6 changes: 6 additions & 0 deletions
6
...io/homeassistant/companion/android/common/data/authentication/AuthenticationRepository.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
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
12 changes: 12 additions & 0 deletions
12
...ant/companion/android/common/data/authentication/impl/entities/LoginFlowAuthentication.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,12 @@ | ||
package io.homeassistant.companion.android.common.data.authentication.impl.entities | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class LoginFlowAuthentication( | ||
@JsonProperty("client_id") | ||
val clientId: String, | ||
@JsonProperty("username") | ||
val userName: String, | ||
@JsonProperty("password") | ||
val password: String | ||
) |
14 changes: 14 additions & 0 deletions
14
...istant/companion/android/common/data/authentication/impl/entities/LoginFlowCreateEntry.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.homeassistant.companion.android.common.data.authentication.impl.entities | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class LoginFlowCreateEntry( | ||
@JsonProperty("version") | ||
val version: Int, | ||
@JsonProperty("type") | ||
val type: String, | ||
@JsonProperty("flow_id") | ||
val flowId: String, | ||
@JsonProperty("result") | ||
val result: String | ||
) |
14 changes: 14 additions & 0 deletions
14
...homeassistant/companion/android/common/data/authentication/impl/entities/LoginFlowInit.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.homeassistant.companion.android.common.data.authentication.impl.entities | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class LoginFlowInit( | ||
@JsonProperty("type") | ||
val type: String, | ||
@JsonProperty("flow_id") | ||
val flowId: String, | ||
@JsonProperty("step_id") | ||
val stepId: String, | ||
@JsonProperty("errors") | ||
val errors: Map<String, String> | ||
) |
12 changes: 12 additions & 0 deletions
12
...eassistant/companion/android/common/data/authentication/impl/entities/LoginFlowRequest.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,12 @@ | ||
package io.homeassistant.companion.android.common.data.authentication.impl.entities | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class LoginFlowRequest( | ||
@JsonProperty("client_id") | ||
val clientId: String, | ||
@JsonProperty("redirect_uri") | ||
val redirectUri: String, | ||
@JsonProperty("handler") | ||
val handler: List<String?> | ||
) |
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
15 changes: 0 additions & 15 deletions
15
wear/src/main/java/io/homeassistant/companion/android/Home.kt
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
wear/src/main/java/io/homeassistant/companion/android/HomeAssistantApplication.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.homeassistant.companion.android | ||
|
||
import android.app.Application | ||
import io.homeassistant.companion.android.common.dagger.AppComponent | ||
import io.homeassistant.companion.android.common.dagger.Graph | ||
import io.homeassistant.companion.android.common.dagger.GraphComponentAccessor | ||
|
||
open class HomeAssistantApplication : Application(), GraphComponentAccessor { | ||
|
||
lateinit var graph: Graph | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
graph = Graph(this, 0) | ||
} | ||
|
||
override val appComponent: AppComponent | ||
get() = graph.appComponent | ||
} |
Oops, something went wrong.