Make integration work with HA < 0.104
This commit is contained in:
@ -19,6 +19,7 @@ class ConnectionManager {
|
|||||||
String _tempToken;
|
String _tempToken;
|
||||||
String oauthUrl;
|
String oauthUrl;
|
||||||
String webhookId;
|
String webhookId;
|
||||||
|
double haVersion;
|
||||||
String mobileAppDeviceName;
|
String mobileAppDeviceName;
|
||||||
bool settingsLoaded = false;
|
bool settingsLoaded = false;
|
||||||
int appIntegrationVersion;
|
int appIntegrationVersion;
|
||||||
@ -154,7 +155,12 @@ class ConnectionManager {
|
|||||||
if (!connecting.isCompleted) connecting.completeError(e);
|
if (!connecting.isCompleted) connecting.completeError(e);
|
||||||
});
|
});
|
||||||
} else if (data["type"] == "auth_ok") {
|
} 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");
|
Logger.d("[Connection] Subscribing to events");
|
||||||
sendSocketMessage(
|
sendSocketMessage(
|
||||||
type: "subscribe_events",
|
type: "subscribe_events",
|
||||||
|
@ -31,12 +31,16 @@ class MobileAppIntegrationManager {
|
|||||||
Logger.d("Mobile app was not registered yet. Registering...");
|
Logger.d("Mobile app was not registered yet. Registering...");
|
||||||
var registrationData = Map.from(_appRegistrationData);
|
var registrationData = Map.from(_appRegistrationData);
|
||||||
registrationData.addAll({
|
registrationData.addAll({
|
||||||
"device_id": "${DeviceInfoManager().unicDeviceId}",
|
|
||||||
"app_id": "ha_client",
|
"app_id": "ha_client",
|
||||||
"app_name": "$appName",
|
"app_name": "$appName",
|
||||||
"os_name": DeviceInfoManager().osName,
|
"os_name": DeviceInfoManager().osName,
|
||||||
"supports_encryption": false,
|
"supports_encryption": false,
|
||||||
});
|
});
|
||||||
|
if (ConnectionManager().haVersion >= 104) {
|
||||||
|
registrationData.addAll({
|
||||||
|
"device_id": "${DeviceInfoManager().unicDeviceId}"
|
||||||
|
});
|
||||||
|
}
|
||||||
ConnectionManager().sendHTTPPost(
|
ConnectionManager().sendHTTPPost(
|
||||||
endPoint: "/api/mobile_app/registrations",
|
endPoint: "/api/mobile_app/registrations",
|
||||||
includeAuthHeader: true,
|
includeAuthHeader: true,
|
||||||
|
Reference in New Issue
Block a user