mirror of
https://github.com/home-assistant/android
synced 2024-10-06 16:19:38 +00:00
Send IP address of Matter device for on network commissioning (#4069)
* [WIP] Send IP of device during commissioning * Add version check for IP address in commission_on_network * Update minimal
This commit is contained in:
parent
1162a82c48
commit
f1fcabb0c9
|
@ -58,7 +58,7 @@ class MatterCommissioningService : Service(), CommissioningService.Callback {
|
||||||
commissioningServiceDelegate.sendCommissioningError(CommissioningError.OTHER)
|
commissioningServiceDelegate.sendCommissioningError(CommissioningError.OTHER)
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
val result = matterManager.commissionOnNetworkDevice(metadata.passcode, serverId)
|
val result = matterManager.commissionOnNetworkDevice(metadata.passcode, metadata.networkLocation.formattedIpAddress, serverId)
|
||||||
Log.d(TAG, "Server commissioning was ${if (result?.success == true) "successful" else "not successful (${result?.errorCode})"}")
|
Log.d(TAG, "Server commissioning was ${if (result?.success == true) "successful" else "not successful (${result?.errorCode})"}")
|
||||||
|
|
||||||
if (result?.success == true) {
|
if (result?.success == true) {
|
||||||
|
|
|
@ -63,9 +63,9 @@ class MatterManagerImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun commissionOnNetworkDevice(pin: Long, serverId: Int): MatterCommissionResponse? {
|
override suspend fun commissionOnNetworkDevice(pin: Long, ip: String, serverId: Int): MatterCommissionResponse? {
|
||||||
return try {
|
return try {
|
||||||
serverManager.webSocketRepository(serverId).commissionMatterDeviceOnNetwork(pin)
|
serverManager.webSocketRepository(serverId).commissionMatterDeviceOnNetwork(pin, ip)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error while executing server commissioning request", e)
|
Log.e(TAG, "Error while executing server commissioning request", e)
|
||||||
null
|
null
|
||||||
|
|
|
@ -42,5 +42,5 @@ interface MatterManager {
|
||||||
* Send a request to the server to commission an "on network" Matter device
|
* Send a request to the server to commission an "on network" Matter device
|
||||||
* @return [MatterCommissionResponse], or `null` if it wasn't possible to complete the request
|
* @return [MatterCommissionResponse], or `null` if it wasn't possible to complete the request
|
||||||
*/
|
*/
|
||||||
suspend fun commissionOnNetworkDevice(pin: Long, serverId: Int): MatterCommissionResponse?
|
suspend fun commissionOnNetworkDevice(pin: Long, ip: String, serverId: Int): MatterCommissionResponse?
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,5 +28,5 @@ class MatterManagerImpl @Inject constructor() : MatterManager {
|
||||||
|
|
||||||
override suspend fun commissionDevice(code: String, serverId: Int): MatterCommissionResponse? = null
|
override suspend fun commissionDevice(code: String, serverId: Int): MatterCommissionResponse? = null
|
||||||
|
|
||||||
override suspend fun commissionOnNetworkDevice(pin: Long, serverId: Int): MatterCommissionResponse? = null
|
override suspend fun commissionOnNetworkDevice(pin: Long, ip: String, serverId: Int): MatterCommissionResponse? = null
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ interface WebSocketRepository {
|
||||||
* @return [MatterCommissionResponse] detailing the server's response, or `null` if the server
|
* @return [MatterCommissionResponse] detailing the server's response, or `null` if the server
|
||||||
* did not return a response.
|
* did not return a response.
|
||||||
*/
|
*/
|
||||||
suspend fun commissionMatterDeviceOnNetwork(pin: Long): MatterCommissionResponse?
|
suspend fun commissionMatterDeviceOnNetwork(pin: Long, ip: String): MatterCommissionResponse?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a list of all Thread datasets known to the server.
|
* Return a list of all Thread datasets known to the server.
|
||||||
|
|
|
@ -473,13 +473,14 @@ class WebSocketRepositoryImpl @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun commissionMatterDeviceOnNetwork(pin: Long): MatterCommissionResponse? {
|
override suspend fun commissionMatterDeviceOnNetwork(pin: Long, ip: String): MatterCommissionResponse? {
|
||||||
|
val data = mapOf(
|
||||||
|
"type" to "matter/commission_on_network",
|
||||||
|
"pin" to pin
|
||||||
|
)
|
||||||
val response = sendMessage(
|
val response = sendMessage(
|
||||||
WebSocketRequest(
|
WebSocketRequest(
|
||||||
message = mapOf(
|
message = if (server?.version?.isAtLeast(2024, 1) == true) data.plus("ip_addr" to ip) else data,
|
||||||
"type" to "matter/commission_on_network",
|
|
||||||
"pin" to pin
|
|
||||||
),
|
|
||||||
timeout = 120000L // Matter commissioning takes at least 60 seconds + interview
|
timeout = 120000L // Matter commissioning takes at least 60 seconds + interview
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue