Don't handle state change if fetch is in progress

This commit is contained in:
estevez-dev
2019-04-19 14:38:02 +03:00
parent a916ddfa50
commit 19c85d9c16

View File

@ -25,6 +25,7 @@ class HomeAssistant {
String get userAvatarText => userName.length > 0 ? userName[0] : ""; String get userAvatarText => userName.length > 0 ? userName[0] : "";
bool get isNoEntities => entities == null || entities.isEmpty; bool get isNoEntities => entities == null || entities.isEmpty;
bool get isNoViews => ui == null || ui.isEmpty; bool get isNoViews => ui == null || ui.isEmpty;
bool get isMobileAppEnabled => _instanceConfig["components"] != null && (_instanceConfig["components"] as List).contains("mobile_app");
HomeAssistant() { HomeAssistant() {
Connection().onStateChangeCallback = _handleEntityStateChange; Connection().onStateChangeCallback = _handleEntityStateChange;
@ -48,12 +49,12 @@ class HomeAssistant {
futures.add(_getServices()); futures.add(_getServices());
futures.add(_getUserInfo()); futures.add(_getUserInfo());
futures.add(_getPanels()); futures.add(_getPanels());
Future.wait(futures).then((_) { futures.add(Connection().sendSocketMessage(
_createUI();
Connection().sendSocketMessage(
type: "subscribe_events", type: "subscribe_events",
additionalData: {"event_type": "state_changed"}, additionalData: {"event_type": "state_changed"},
); ));
Future.wait(futures).then((_) {
_createUI();
_fetchCompleter.complete(); _fetchCompleter.complete();
}).catchError((e) { }).catchError((e) {
_fetchCompleter.completeError(e); _fetchCompleter.completeError(e);
@ -127,12 +128,14 @@ class HomeAssistant {
void _handleEntityStateChange(Map eventData) { void _handleEntityStateChange(Map eventData) {
//TheLogger.debug( "New state for ${eventData['entity_id']}"); //TheLogger.debug( "New state for ${eventData['entity_id']}");
if (_fetchCompleter == null || _fetchCompleter.isCompleted) {
Map data = Map.from(eventData); Map data = Map.from(eventData);
eventBus.fire(new StateChangedEvent( eventBus.fire(new StateChangedEvent(
entityId: data["entity_id"], entityId: data["entity_id"],
needToRebuildUI: entities.updateState(data) needToRebuildUI: entities.updateState(data)
)); ));
} }
}
void _parseLovelace() { void _parseLovelace() {
Logger.d("--Title: ${_rawLovelaceData["title"]}"); Logger.d("--Title: ${_rawLovelaceData["title"]}");