Make integration work with HA < 0.104

This commit is contained in:
Yegor Vialov 2020-05-06 16:40:19 +00:00
parent 17ec73b176
commit 8cd5776bc6
2 changed files with 12 additions and 2 deletions

View File

@ -19,6 +19,7 @@ class ConnectionManager {
String _tempToken;
String oauthUrl;
String webhookId;
double haVersion;
String mobileAppDeviceName;
bool settingsLoaded = false;
int appIntegrationVersion;
@ -154,7 +155,12 @@ class ConnectionManager {
if (!connecting.isCompleted) connecting.completeError(e);
});
} else if (data["type"] == "auth_ok") {
Logger.d("[Received] <== ${data.toString()}");
String v = data["ha_version"];
if (v != null && v.isNotEmpty) {
haVersion = double.tryParse(v.replaceFirst('0.','')) ?? 0;
}
Logger.d("Home assistant version: $v ($haVersion)");
Crashlytics.instance.setString('ha_version', v);
Logger.d("[Connection] Subscribing to events");
sendSocketMessage(
type: "subscribe_events",

View File

@ -31,12 +31,16 @@ class MobileAppIntegrationManager {
Logger.d("Mobile app was not registered yet. Registering...");
var registrationData = Map.from(_appRegistrationData);
registrationData.addAll({
"device_id": "${DeviceInfoManager().unicDeviceId}",
"app_id": "ha_client",
"app_name": "$appName",
"os_name": DeviceInfoManager().osName,
"supports_encryption": false,
});
if (ConnectionManager().haVersion >= 104) {
registrationData.addAll({
"device_id": "${DeviceInfoManager().unicDeviceId}"
});
}
ConnectionManager().sendHTTPPost(
endPoint: "/api/mobile_app/registrations",
includeAuthHeader: true,