Compare commits
	
		
			3 Commits
		
	
	
		
			v0.0.12-al
			...
			v0.1.0-alp
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 739e659a81 | ||
|  | 2fb8d8e26b | ||
|  | 2db432ccd2 | 
| @@ -39,8 +39,8 @@ android { | ||||
|         applicationId "com.keyboardcrumbs.haclient" | ||||
|         minSdkVersion 21 | ||||
|         targetSdkVersion 27 | ||||
|         versionCode 17 | ||||
|         versionName "0.0.12-alpha" | ||||
|         versionCode 18 | ||||
|         versionName "0.1.0-alpha" | ||||
|         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -17,7 +17,7 @@ class HassioDataModel { | ||||
|   String _hassioPassword; | ||||
|   String _hassioAuthType; | ||||
|   IOWebSocketChannel _hassioChannel; | ||||
|   int _currentMssageId = 0; | ||||
|   int _currentMessageId = 0; | ||||
|   int _statesMessageId = 0; | ||||
|   int _servicesMessageId = 0; | ||||
|   int _subscriptionMessageId = 0; | ||||
| @@ -128,8 +128,8 @@ class HassioDataModel { | ||||
|         _parseEntities(data); | ||||
|       } else if (data["id"] == _servicesMessageId) { | ||||
|         _parseServices(data); | ||||
|       } else if (data["id"] == _currentMssageId) { | ||||
|         debugPrint("Request id:$_currentMssageId was successful"); | ||||
|       } else if (data["id"] == _currentMessageId) { | ||||
|         debugPrint("Request id:$_currentMessageId was successful"); | ||||
|       } else { | ||||
|         debugPrint("Skipped message due to messageId:"); | ||||
|         debugPrint(message); | ||||
| @@ -150,14 +150,14 @@ class HassioDataModel { | ||||
|  | ||||
|   void _sendSubscribe() { | ||||
|     _incrementMessageId(); | ||||
|     _subscriptionMessageId = _currentMssageId; | ||||
|     _subscriptionMessageId = _currentMessageId; | ||||
|     _sendMessageRaw('{"id": $_subscriptionMessageId, "type": "subscribe_events", "event_type": "state_changed"}'); | ||||
|   } | ||||
|  | ||||
|   Future _getConfig() { | ||||
|     _configCompleter = new Completer(); | ||||
|     _incrementMessageId(); | ||||
|     _configMessageId = _currentMssageId; | ||||
|     _configMessageId = _currentMessageId; | ||||
|     _sendMessageRaw('{"id": $_configMessageId, "type": "get_config"}'); | ||||
|  | ||||
|     return _configCompleter.future; | ||||
| @@ -166,7 +166,7 @@ class HassioDataModel { | ||||
|   Future _getStates() { | ||||
|     _statesCompleter = new Completer(); | ||||
|     _incrementMessageId(); | ||||
|     _statesMessageId = _currentMssageId; | ||||
|     _statesMessageId = _currentMessageId; | ||||
|     _sendMessageRaw('{"id": $_statesMessageId, "type": "get_states"}'); | ||||
|  | ||||
|     return _statesCompleter.future; | ||||
| @@ -175,14 +175,14 @@ class HassioDataModel { | ||||
|   Future _getServices() { | ||||
|     _servicesCompleter = new Completer(); | ||||
|     _incrementMessageId(); | ||||
|     _servicesMessageId = _currentMssageId; | ||||
|     _servicesMessageId = _currentMessageId; | ||||
|     _sendMessageRaw('{"id": $_servicesMessageId, "type": "get_services"}'); | ||||
|  | ||||
|     return _servicesCompleter.future; | ||||
|   } | ||||
|  | ||||
|   _incrementMessageId() { | ||||
|     _currentMssageId += 1; | ||||
|     _currentMessageId += 1; | ||||
|   } | ||||
|  | ||||
|   _sendMessageRaw(message) { | ||||
| @@ -245,14 +245,6 @@ class HassioDataModel { | ||||
|       composedEntity["display_name"] = "${entity["attributes"]!=null ? entity["attributes"]["friendly_name"] ?? entity["attributes"]["name"] : "_"}"; | ||||
|       composedEntity["domain"] = entityDomain; | ||||
|  | ||||
|       if ((entityDomain == "automation") || (entityDomain == "switch") || (entityDomain == "light")) { | ||||
|         composedEntity["actionType"] = "switch"; | ||||
|       } else if ((entityDomain == "script") || (entityDomain == "scene")) { | ||||
|         composedEntity["actionType"] = "statelessIcon"; | ||||
|       } else { | ||||
|         composedEntity["actionType"] = "stateText"; | ||||
|       } | ||||
|  | ||||
|       if (composedEntity["attributes"] != null) { | ||||
|         if ((entityDomain == "group")&&(composedEntity["attributes"]["view"] == true)) { | ||||
|           uiGroups.add(entityId); | ||||
| @@ -278,7 +270,6 @@ class HassioDataModel { | ||||
|       var viewGroup = _entitiesData[viewId]; | ||||
|       Map viewGroupStructure = {}; | ||||
|       if (viewGroup != null) { | ||||
|         viewGroupStructure["standalone"] = {}; | ||||
|         viewGroupStructure["groups"] = {}; | ||||
|         viewGroupStructure["state"] = "on"; | ||||
|         viewGroupStructure["entity_id"] = viewGroup["entity_id"]; | ||||
| @@ -334,7 +325,7 @@ class HassioDataModel { | ||||
|     }); | ||||
|     _reConnectSocket().then((r) { | ||||
|       _incrementMessageId(); | ||||
|       _sendMessageRaw('{"id": $_currentMssageId, "type": "call_service", "domain": "$domain", "service": "$service", "service_data": {"entity_id": "$entity_id"}}'); | ||||
|       _sendMessageRaw('{"id": $_currentMessageId, "type": "call_service", "domain": "$domain", "service": "$service", "service_data": {"entity_id": "$entity_id"}}'); | ||||
|       _sendTimer.cancel(); | ||||
|       sendCompleter.complete(); | ||||
|     }).catchError((e){ | ||||
|   | ||||
| @@ -14,7 +14,7 @@ part 'data_model.dart'; | ||||
|  | ||||
| EventBus eventBus = new EventBus(); | ||||
| const String appName = "HA Client"; | ||||
| const appVersion = "0.0.12-alpha"; | ||||
| const appVersion = "0.1.0-alpha"; | ||||
|  | ||||
| String homeAssistantWebHost; | ||||
|  | ||||
| @@ -59,13 +59,17 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|   StreamSubscription _stateSubscription; | ||||
|   StreamSubscription _settingsSubscription; | ||||
|   bool _isLoading = true; | ||||
|   Map _stateIconColors = { | ||||
|   Map<String, Color> _stateIconColors = { | ||||
|     "on": Colors.amber, | ||||
|     "off": Colors.blueGrey, | ||||
|     "off": Color.fromRGBO(68, 115, 158, 1.0), | ||||
|     "unavailable": Colors.black12, | ||||
|     "unknown": Colors.black12, | ||||
|     "playing": Colors.amber | ||||
|   }; | ||||
|   Map<String, Color> _badgeColors = { | ||||
|     "default": Color.fromRGBO(223, 76, 30, 1.0), | ||||
|     "binary_sensor": Color.fromRGBO(3, 155, 229, 1.0) | ||||
|   }; | ||||
|  | ||||
|   @override | ||||
|   void initState() { | ||||
| @@ -220,11 +224,21 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|   } | ||||
|  | ||||
|   Widget _buildSingleBadge(data) { | ||||
|     double iconSize = 26.0; | ||||
|     Widget badgeIcon; | ||||
|     String badgeTextValue; | ||||
|     Color iconColor = _badgeColors[data["domain"]] ?? _badgeColors["default"]; | ||||
|     switch (data["domain"]) { | ||||
|       case "sun": { | ||||
|         badgeIcon = data["state"] == "below_horizon" ? Icon(MaterialDesignIcons.createIconDataFromIconCode(0xf0dc)) : Icon(MaterialDesignIcons.createIconDataFromIconCode(0xf5a8)); | ||||
|         badgeIcon = data["state"] == "below_horizon" ? | ||||
|           Icon( | ||||
|             MaterialDesignIcons.createIconDataFromIconCode(0xf0dc), | ||||
|             size: iconSize, | ||||
|           ) : | ||||
|           Icon( | ||||
|             MaterialDesignIcons.createIconDataFromIconCode(0xf5a8), | ||||
|             size: iconSize, | ||||
|           ); | ||||
|         break; | ||||
|       } | ||||
|       case "sensor": { | ||||
| @@ -241,12 +255,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|         break; | ||||
|       } | ||||
|       case "device_tracker": { | ||||
|         badgeIcon = MaterialDesignIcons.createIconFromEntityData(data, 50.0,Colors.black); | ||||
|         badgeIcon = MaterialDesignIcons.createIconFromEntityData(data, iconSize,Colors.black); | ||||
|         badgeTextValue = data["state"]; | ||||
|         break; | ||||
|       } | ||||
|       default: { | ||||
|        badgeIcon = MaterialDesignIcons.createIconFromEntityData(data, 50.0,Colors.black); | ||||
|        badgeIcon = MaterialDesignIcons.createIconFromEntityData(data, iconSize,Colors.black); | ||||
|       } | ||||
|     } | ||||
|     Widget badgeText; | ||||
| @@ -261,7 +275,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|           decoration: new BoxDecoration( | ||||
|             // Circle shape | ||||
|             //shape: BoxShape.circle, | ||||
|             color: Colors.redAccent, | ||||
|             color: iconColor, | ||||
|             borderRadius: BorderRadius.circular(9.0), | ||||
|           ) | ||||
|       ); | ||||
| @@ -279,7 +293,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|             // The border you want | ||||
|             border: new Border.all( | ||||
|               width: 2.0, | ||||
|               color: Colors.redAccent, | ||||
|               color: iconColor, | ||||
|             ), | ||||
|           ), | ||||
|           child: Stack( | ||||
| @@ -355,7 +369,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|         entities.add(new ListTile( | ||||
|           leading: MaterialDesignIcons.createIconFromEntityData(data, 28.0, _stateIconColors[data["state"]] ?? Colors.blueGrey), | ||||
|           //subtitle: Text("${data['entity_id']}"), | ||||
|           trailing: _buildEntityStateWidget(data), | ||||
|           trailing: _buildEntityActionWidget(data), | ||||
|           title: Text( | ||||
|             "${data["display_name"]}", | ||||
|             overflow: TextOverflow.fade, | ||||
| @@ -367,10 +381,13 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|     return entities; | ||||
|   } | ||||
|  | ||||
|   Widget _buildEntityStateWidget(data) { | ||||
|   Widget _buildEntityActionWidget(data) { | ||||
|     String entityId = data["entity_id"]; | ||||
|     Widget result; | ||||
|     if (data["actionType"] == "switch") { | ||||
|     switch (data["domain"]) { | ||||
|       case "automation": | ||||
|       case "switch": | ||||
|       case "light": { | ||||
|         result = Switch( | ||||
|           value: (data["state"] == "on"), | ||||
|           onChanged: ((state) { | ||||
| @@ -381,7 +398,11 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|             }); | ||||
|           }), | ||||
|         ); | ||||
|     } else if (data["actionType"] == "statelessIcon") { | ||||
|         break; | ||||
|       } | ||||
|  | ||||
|       case "script": | ||||
|       case "scene": { | ||||
|         result = SizedBox( | ||||
|           width: 60.0, | ||||
|           child: FlatButton( | ||||
| @@ -393,8 +414,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|               textAlign: TextAlign.right, | ||||
|               style: new TextStyle(fontSize: 16.0, color: Colors.blue), | ||||
|             ), | ||||
|           )); | ||||
|     } else { | ||||
|           ) | ||||
|         ); | ||||
|         break; | ||||
|       } | ||||
|  | ||||
|       default: { | ||||
|         result = Padding( | ||||
|           padding: EdgeInsets.fromLTRB(0.0, 0.0, 16.0, 0.0), | ||||
|           child: Text( | ||||
| @@ -402,8 +427,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|             textAlign: TextAlign.right, | ||||
|             style: new TextStyle( | ||||
|               fontSize: 16.0, | ||||
|               ))); | ||||
|             ) | ||||
|           ) | ||||
|         ); | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     /*return SizedBox( | ||||
|       width: 60.0, | ||||
|       // height: double.infinity, | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| name: hass_client | ||||
| description: Home Assistant Android Client | ||||
|  | ||||
| version: 0.0.12-alpha | ||||
| version: 0.1.0-alpha | ||||
|  | ||||
| environment: | ||||
|   sdk: ">=2.0.0-dev.68.0 <3.0.0" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user