Error handling improvements
This commit is contained in:
		
							
								
								
									
										51
									
								
								lib/entity_class/media_player_entity.class.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								lib/entity_class/media_player_entity.class.dart
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | ||||
| part of '../main.dart'; | ||||
|  | ||||
| class MediaPlayerEntity extends Entity { | ||||
|  | ||||
|   static const SUPPORT_PAUSE = 1; | ||||
|   static const SUPPORT_SEEK = 2; | ||||
|   static const SUPPORT_VOLUME_SET = 4; | ||||
|   static const SUPPORT_VOLUME_MUTE = 8; | ||||
|   static const SUPPORT_PREVIOUS_TRACK = 16; | ||||
|   static const SUPPORT_NEXT_TRACK = 32; | ||||
|  | ||||
|   static const SUPPORT_TURN_ON = 128; | ||||
|   static const SUPPORT_TURN_OFF = 256; | ||||
|   static const SUPPORT_PLAY_MEDIA = 512; | ||||
|   static const SUPPORT_VOLUME_STEP = 1024; | ||||
|   static const SUPPORT_SELECT_SOURCE = 2048; | ||||
|   static const SUPPORT_STOP = 4096; | ||||
|   static const SUPPORT_CLEAR_PLAYLIST = 8192; | ||||
|   static const SUPPORT_PLAY = 16384; | ||||
|   static const SUPPORT_SHUFFLE_SET = 32768; | ||||
|   static const SUPPORT_SELECT_SOUND_MODE = 65536; | ||||
|  | ||||
|   MediaPlayerEntity(Map rawData) : super(rawData); | ||||
|  | ||||
|   bool get supportPause => ((attributes["supported_features"] & | ||||
|   MediaPlayerEntity.SUPPORT_PAUSE) == | ||||
|       MediaPlayerEntity.SUPPORT_PAUSE); | ||||
|   bool get supportSeek => ((attributes["supported_features"] & | ||||
|   MediaPlayerEntity.SUPPORT_SEEK) == | ||||
|       MediaPlayerEntity.SUPPORT_SEEK); | ||||
|   bool get supportVolumeSet => ((attributes["supported_features"] & | ||||
|   MediaPlayerEntity.SUPPORT_VOLUME_SET) == | ||||
|       MediaPlayerEntity.SUPPORT_VOLUME_SET); | ||||
|   bool get supportVolumeMute => ((attributes["supported_features"] & | ||||
|   MediaPlayerEntity.SUPPORT_VOLUME_MUTE) == | ||||
|       MediaPlayerEntity.SUPPORT_VOLUME_MUTE); | ||||
|   bool get supportPreviousTrack => ((attributes["supported_features"] & | ||||
|   MediaPlayerEntity.SUPPORT_PREVIOUS_TRACK) == | ||||
|       MediaPlayerEntity.SUPPORT_PREVIOUS_TRACK); | ||||
|   bool get supportNextTrack => ((attributes["supported_features"] & | ||||
|   MediaPlayerEntity.SUPPORT_NEXT_TRACK) == | ||||
|       MediaPlayerEntity.SUPPORT_NEXT_TRACK); | ||||
|  | ||||
|   bool get supportTurnOn => ((attributes["supported_features"] & | ||||
|   MediaPlayerEntity.SUPPORT_TURN_ON) == | ||||
|       MediaPlayerEntity.SUPPORT_TURN_ON); | ||||
|   bool get supportTurnOff => ((attributes["supported_features"] & | ||||
|   MediaPlayerEntity.SUPPORT_TURN_OFF) == | ||||
|       MediaPlayerEntity.SUPPORT_TURN_OFF); | ||||
|  | ||||
| } | ||||
| @@ -195,7 +195,12 @@ class HomeAssistant { | ||||
|         _connectionCompleter.complete(); | ||||
|       } | ||||
|     } else if (error != null) { | ||||
|       eventBus.fire(ShowErrorEvent(error["errorMessage"], error["errorCode"])); | ||||
|       if (error is Error) { | ||||
|         eventBus.fire(ShowErrorEvent(error.toString(), 12)); | ||||
|       } else { | ||||
|         eventBus.fire(ShowErrorEvent(error["errorMessage"], error["errorCode"])); | ||||
|       } | ||||
|  | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -26,6 +26,7 @@ part 'entity_class/light_entity.class.dart'; | ||||
| part 'entity_class/select_entity.class.dart'; | ||||
| part 'entity_class/other_entity.class.dart'; | ||||
| part 'entity_class/slider_entity.dart'; | ||||
| part 'entity_class/media_player_entity.class.dart'; | ||||
| part 'entity_widgets/badge.dart'; | ||||
| part 'entity_widgets/model_widgets.dart'; | ||||
| part 'entity_widgets/default_entity_container.dart'; | ||||
| @@ -267,10 +268,19 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|     setState(() { | ||||
|       _isLoading = 2; | ||||
|     }); | ||||
|     _showErrorSnackBar( | ||||
|         message: e != null ? e["errorMessage"] ?? "$e" : "Unknown error", | ||||
|         errorCode: e["errorCode"] != null ? e["errorCode"] : 99 | ||||
|     ); | ||||
|     if (e is Error) { | ||||
|       TheLogger.error(e.toString()); | ||||
|       TheLogger.error("${e.stackTrace}"); | ||||
|       _showErrorSnackBar( | ||||
|           message: "There was some error", | ||||
|           errorCode: 13 | ||||
|       ); | ||||
|     } else { | ||||
|       _showErrorSnackBar( | ||||
|           message: e != null ? e["errorMessage"] ?? "$e" : "Unknown error", | ||||
|           errorCode: e["errorCode"] != null ? e["errorCode"] : 99 | ||||
|       ); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   void _callService(String domain, String service, String entityId, Map<String, dynamic> additionalParams) { | ||||
| @@ -477,6 +487,17 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|           ); | ||||
|           break; | ||||
|         } | ||||
|  | ||||
|         default: { | ||||
|           action = SnackBarAction( | ||||
|             label: "Reload", | ||||
|             onPressed: () { | ||||
|               _scaffoldKey?.currentState?.hideCurrentSnackBar(); | ||||
|               _refreshData(); | ||||
|             }, | ||||
|           ); | ||||
|           break; | ||||
|         } | ||||
|       } | ||||
|       _scaffoldKey.currentState.hideCurrentSnackBar(); | ||||
|       _scaffoldKey.currentState.showSnackBar( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user