-
-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support websocket message coalescing (#2829)
- Add support for the new feature where core might combine multiple responses in to one single websocket message if it's faster. This might return a JSON array of objects instead of a single object. - Adjust logging for websocket, no longer prints entire result on non-debug builds.
- Loading branch information
Showing
4 changed files
with
76 additions
and
28 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
common/src/main/java/io/homeassistant/companion/android/common/data/HomeAssistantVersion.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,29 @@ | ||
package io.homeassistant.companion.android.common.data | ||
|
||
import java.util.regex.Pattern | ||
|
||
data class HomeAssistantVersion( | ||
val year: Int, | ||
val month: Int, | ||
val release: Int | ||
) { | ||
|
||
companion object { | ||
private val VERSION_PATTERN = Pattern.compile("([0-9]{4})\\.([0-9]{1,2})\\.([0-9]{1,2}).*") | ||
|
||
fun fromString(versionString: String): HomeAssistantVersion? { | ||
val matches = VERSION_PATTERN.matcher(versionString) | ||
return if (matches.find() && matches.matches()) { | ||
val coreYear = matches.group(1)?.toIntOrNull() ?: 0 | ||
val coreMonth = matches.group(2)?.toIntOrNull() ?: 0 | ||
val coreRelease = matches.group(3)?.toIntOrNull() ?: 0 | ||
HomeAssistantVersion(coreYear, coreMonth, coreRelease) | ||
} else { // Invalid version | ||
null | ||
} | ||
} | ||
} | ||
|
||
fun isAtLeast(minYear: Int, minMonth: Int, minRelease: Int = 0): Boolean = | ||
year > minYear || (year == minYear && (month > minMonth || (month == minMonth && release >= minRelease))) | ||
} |
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