Component detection

This commit is contained in:
Yegor Vialov 2020-04-15 14:03:31 +00:00
parent 6afbd37d71
commit 291f12ba97
3 changed files with 9 additions and 6 deletions

View File

@ -36,7 +36,7 @@ class _CameraStreamViewState extends State<CameraStreamView> {
.of(context)
.entityWrapper
.entity;
if (_entity.supportStream) {
if (_entity.supportStream && HomeAssistant().isComponentEnabled('stream')) {
HomeAssistant().getCameraStream(_entity.entityId)
.then((data) {
_jsMessageChannelName = 'HA_${_entity.entityId.replaceAll('.', '_')}';

View File

@ -46,7 +46,6 @@ class HomeAssistant {
String get userAvatarText => userName.length > 0 ? userName[0] : "";
bool get isNoEntities => entities == null || entities.isEmpty;
bool get isNoViews => ui == null || ui.isEmpty;
bool get isMobileAppEnabled => _instanceConfig["components"] != null && (_instanceConfig["components"] as List).contains("mobile_app");
HomeAssistant._internal() {
ConnectionManager().onStateChangeCallback = _handleEntityStateChange;
@ -75,7 +74,7 @@ class HomeAssistant {
futures.add(_getLovelace(null));
}
Future.wait(futures).then((_) {
if (isMobileAppEnabled) {
if (isComponentEnabled('mobile_app')) {
_createUI();
_fetchCompleter.complete();
if (!uiOnly) MobileAppIntegrationManager.checkAppRegistration();
@ -103,7 +102,7 @@ class HomeAssistant {
_getUserInfo(prefs);
_getPanels(prefs);
_getServices(prefs);
if (isMobileAppEnabled) {
if (isComponentEnabled('mobile_app')) {
_createUI();
}
} catch (e) {
@ -156,6 +155,7 @@ class HomeAssistant {
void _parseConfig(data) {
_instanceConfig = Map.from(data);
Logger.d('stream: ${_instanceConfig['components'].contains('stream')}');
}
Future _getStates(SharedPreferences sharedPrefs) async {
@ -305,6 +305,10 @@ class HomeAssistant {
return completer.future;
}
bool isComponentEnabled(String name) {
return _instanceConfig["components"] != null && (_instanceConfig["components"] as List).contains("$name");
}
void _handleLovelaceUpdate() {
if (_fetchCompleter != null && _fetchCompleter.isCompleted) {
eventBus.fire(new LovelaceChangedEvent());

View File

@ -57,8 +57,7 @@ class _PlayMediaPageState extends State<PlayMediaPage> {
_loaded = false;
});
} else {
_isMediaExtractorExist = HomeAssistant().isServiceExist("media_extractor");
//_useMediaExtractor = _isMediaExtractorExist;
_isMediaExtractorExist = HomeAssistant().isComponentEnabled("media_extractor");
_players = HomeAssistant().entities.getByDomains(includeDomains: ["media_player"]);
setState(() {
if (_players.isNotEmpty) {