Error reporting: HomeAssistant class
This commit is contained in:
parent
8a180c4c0e
commit
101569d6ee
@ -139,37 +139,41 @@ class HomeAssistant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future _getConfig(SharedPreferences sharedPrefs) async {
|
Future _getConfig(SharedPreferences sharedPrefs) async {
|
||||||
|
_instanceConfig?.clear();
|
||||||
if (sharedPrefs != null) {
|
if (sharedPrefs != null) {
|
||||||
try {
|
try {
|
||||||
var data = json.decode(sharedPrefs.getString('cached_config'));
|
var data = json.decode(sharedPrefs.getString('cached_config') ?? '{}');
|
||||||
_parseConfig(data);
|
_parseConfig(data);
|
||||||
} catch (e) {
|
} catch (e, stacktrace) {
|
||||||
|
Crashlytics.instance.recordError('Error gettong config from cache: $e', stacktrace);
|
||||||
throw HACException("Error getting config: $e");
|
throw HACException("Error getting config: $e");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await ConnectionManager().sendSocketMessage(type: "get_config").then((data) => _parseConfig(data)).catchError((e) {
|
await ConnectionManager().sendSocketMessage(type: "get_config").then((data) => _parseConfig(data)).catchError((e) {
|
||||||
|
Crashlytics.instance.recordError('get_config error: $e', null);
|
||||||
throw HACException("Error getting config: $e");
|
throw HACException("Error getting config: $e");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _parseConfig(data) {
|
void _parseConfig(data) {
|
||||||
_instanceConfig = Map.from(data);
|
_instanceConfig = data;
|
||||||
Logger.d('stream: ${_instanceConfig['components'].contains('stream')}');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _getStates(SharedPreferences sharedPrefs) async {
|
Future _getStates(SharedPreferences sharedPrefs) async {
|
||||||
if (sharedPrefs != null) {
|
if (sharedPrefs != null) {
|
||||||
try {
|
try {
|
||||||
var data = json.decode(sharedPrefs.getString('cached_states'));
|
var data = json.decode(sharedPrefs.getString('cached_states') ?? '[]');
|
||||||
_parseStates(data);
|
_parseStates(data);
|
||||||
} catch (e) {
|
} catch (e, stacktrace) {
|
||||||
|
Crashlytics.instance.recordError('Error getting cached states: $e', stacktrace);
|
||||||
throw HACException("Error getting states: $e");
|
throw HACException("Error getting states: $e");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await ConnectionManager().sendSocketMessage(type: "get_states").then(
|
await ConnectionManager().sendSocketMessage(type: "get_states").then(
|
||||||
(data) => _parseStates(data)
|
(data) => _parseStates(data)
|
||||||
).catchError((e) {
|
).catchError((e) {
|
||||||
|
Crashlytics.instance.recordError('get_states error: $e', null);
|
||||||
throw HACException("Error getting states: $e");
|
throw HACException("Error getting states: $e");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -183,7 +187,7 @@ class HomeAssistant {
|
|||||||
Future _getLovelace(SharedPreferences sharedPrefs) {
|
Future _getLovelace(SharedPreferences sharedPrefs) {
|
||||||
if (sharedPrefs != null) {
|
if (sharedPrefs != null) {
|
||||||
try {
|
try {
|
||||||
var data = json.decode(sharedPrefs.getString('cached_lovelace'));
|
var data = json.decode(sharedPrefs.getString('cached_lovelace') ?? '{}');
|
||||||
_rawLovelaceData = data;
|
_rawLovelaceData = data;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
autoUi = true;
|
autoUi = true;
|
||||||
@ -204,11 +208,12 @@ class HomeAssistant {
|
|||||||
_rawLovelaceData = data;
|
_rawLovelaceData = data;
|
||||||
completer.complete();
|
completer.complete();
|
||||||
}).catchError((e) {
|
}).catchError((e) {
|
||||||
if ("$e" == "config_not_found") {
|
if ("$e".contains("config_not_found")) {
|
||||||
autoUi = true;
|
autoUi = true;
|
||||||
_rawLovelaceData = null;
|
_rawLovelaceData = null;
|
||||||
completer.complete();
|
completer.complete();
|
||||||
} else {
|
} else {
|
||||||
|
Crashlytics.instance.recordError('lovelace/config error: $e', null);
|
||||||
completer.completeError(HACException("Error getting lovelace config: $e"));
|
completer.completeError(HACException("Error getting lovelace config: $e"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -216,17 +221,18 @@ class HomeAssistant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _getServices(SharedPreferences prefs) async {
|
Future _getServices(SharedPreferences prefs) async {
|
||||||
|
services?.clear();
|
||||||
if (prefs != null) {
|
if (prefs != null) {
|
||||||
try {
|
try {
|
||||||
var data = json.decode(prefs.getString('cached_services'));
|
var data = json.decode(prefs.getString('cached_services') ?? '{}');
|
||||||
_parseServices(data);
|
_parseServices(data);
|
||||||
} catch (e) {
|
} catch (e, stacktrace) {
|
||||||
Logger.w("Can't get services: $e");
|
Crashlytics.instance.recordError(e, stacktrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await ConnectionManager().sendSocketMessage(type: "get_services").then((data) => _parseServices(data)).catchError((e) {
|
await ConnectionManager().sendSocketMessage(type: "get_services").then((data) => _parseServices(data)).catchError((e) {
|
||||||
Logger.w("Can't get services: $e");
|
Crashlytics.instance.recordError('get_services error: $e', null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,7 +243,7 @@ class HomeAssistant {
|
|||||||
Future _getUserInfo(SharedPreferences sharedPrefs) async {
|
Future _getUserInfo(SharedPreferences sharedPrefs) async {
|
||||||
_userName = null;
|
_userName = null;
|
||||||
await ConnectionManager().sendSocketMessage(type: "auth/current_user").then((data) => _parseUserInfo(data)).catchError((e) {
|
await ConnectionManager().sendSocketMessage(type: "auth/current_user").then((data) => _parseUserInfo(data)).catchError((e) {
|
||||||
Logger.w("Can't get user info: $e");
|
Crashlytics.instance.recordError('auth/current_user error: $e', null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,18 +253,17 @@ class HomeAssistant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future _getPanels(SharedPreferences sharedPrefs) async {
|
Future _getPanels(SharedPreferences sharedPrefs) async {
|
||||||
|
panels.clear();
|
||||||
if (sharedPrefs != null) {
|
if (sharedPrefs != null) {
|
||||||
try {
|
try {
|
||||||
var data = json.decode(sharedPrefs.getString('cached_panels') ?? '{}');
|
var data = json.decode(sharedPrefs.getString('cached_panels') ?? '{}');
|
||||||
_parsePanels(data);
|
_parsePanels(data);
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stacktrace) {
|
||||||
Crashlytics.instance.recordError(e, stacktrace);
|
Crashlytics.instance.recordError(e, stacktrace);
|
||||||
panels.clear();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await ConnectionManager().sendSocketMessage(type: "get_panels").then((data) => _parsePanels(data)).catchError((e, stacktrace) {
|
await ConnectionManager().sendSocketMessage(type: "get_panels").then((data) => _parsePanels(data)).catchError((e, stacktrace) {
|
||||||
panels.clear();
|
Crashlytics.instance.recordError('get_panels error: $e', stacktrace);
|
||||||
Crashlytics.instance.recordError(e, stacktrace);
|
|
||||||
throw HACException('Can\'t get panles: $e');
|
throw HACException('Can\'t get panles: $e');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -266,7 +271,6 @@ class HomeAssistant {
|
|||||||
|
|
||||||
void _parsePanels(data) {
|
void _parsePanels(data) {
|
||||||
_rawPanels = data;
|
_rawPanels = data;
|
||||||
panels.clear();
|
|
||||||
List<Panel> dashboards = [];
|
List<Panel> dashboards = [];
|
||||||
data.forEach((k,v) {
|
data.forEach((k,v) {
|
||||||
String title = v['title'] == null ? "${k[0].toUpperCase()}${k.substring(1)}" : "${v['title'][0].toUpperCase()}${v['title'].substring(1)}";
|
String title = v['title'] == null ? "${k[0].toUpperCase()}${k.substring(1)}" : "${v['title'][0].toUpperCase()}${v['title'].substring(1)}";
|
||||||
@ -319,7 +323,6 @@ class HomeAssistant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleEntityStateChange(Map eventData) {
|
void _handleEntityStateChange(Map eventData) {
|
||||||
//TheLogger.debug( "New state for ${eventData['entity_id']}");
|
|
||||||
if (_fetchCompleter != null && _fetchCompleter.isCompleted) {
|
if (_fetchCompleter != null && _fetchCompleter.isCompleted) {
|
||||||
Map data = Map.from(eventData);
|
Map data = Map.from(eventData);
|
||||||
eventBus.fire(new StateChangedEvent(
|
eventBus.fire(new StateChangedEvent(
|
||||||
@ -338,57 +341,5 @@ class HomeAssistant {
|
|||||||
void _createUI() {
|
void _createUI() {
|
||||||
Logger.d("Creating Lovelace UI");
|
Logger.d("Creating Lovelace UI");
|
||||||
ui = HomeAssistantUI(rawLovelaceConfig: _rawLovelaceData);
|
ui = HomeAssistantUI(rawLovelaceConfig: _rawLovelaceData);
|
||||||
/*if (isServiceExist('zha_map')) {
|
|
||||||
panels.add(
|
|
||||||
Panel(
|
|
||||||
id: 'haclient_zha',
|
|
||||||
componentName: 'haclient_zha',
|
|
||||||
title: 'ZHA',
|
|
||||||
urlPath: '/haclient_zha',
|
|
||||||
icon: 'mdi:zigbee'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
class SendMessageQueue {
|
|
||||||
int _messageTimeout;
|
|
||||||
List<HAMessage> _queue = [];
|
|
||||||
|
|
||||||
SendMessageQueue(this._messageTimeout);
|
|
||||||
|
|
||||||
void add(String message) {
|
|
||||||
_queue.add(HAMessage(_messageTimeout, message));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> getActualMessages() {
|
|
||||||
_queue.removeWhere((item) => item.isExpired());
|
|
||||||
List<String> result = [];
|
|
||||||
_queue.forEach((haMessage){
|
|
||||||
result.add(haMessage.message);
|
|
||||||
});
|
|
||||||
this.clear();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear() {
|
|
||||||
_queue.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class HAMessage {
|
|
||||||
DateTime _timeStamp;
|
|
||||||
int _messageTimeout;
|
|
||||||
String message;
|
|
||||||
|
|
||||||
HAMessage(this._messageTimeout, this.message) {
|
|
||||||
_timeStamp = DateTime.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isExpired() {
|
|
||||||
return DateTime.now().difference(_timeStamp).inSeconds > _messageTimeout;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
Reference in New Issue
Block a user