From 3417c38426db1f78829d5272c668d04bdf79c44b Mon Sep 17 00:00:00 2001 From: estevez-dev Date: Fri, 21 Jun 2019 12:53:03 +0300 Subject: [PATCH] Resolves #386 --- lib/home_assistant.class.dart | 4 +- lib/ui_widgets/config_panel_widget.dart | 72 +++++++++++-------------- 2 files changed, 33 insertions(+), 43 deletions(-) diff --git a/lib/home_assistant.class.dart b/lib/home_assistant.class.dart index 7f9eb22..0f7dd20 100644 --- a/lib/home_assistant.class.dart +++ b/lib/home_assistant.class.dart @@ -122,8 +122,8 @@ class HomeAssistant { Connection().webhookId = responseObject["webhook_id"]; completer.complete(); eventBus.fire(ShowDialogEvent( - title: "App was registered with your Home Assistant", - body: "To start using notifications you need to restart your Home Assistant", + title: "Mobile app Integration was created", + body: "HA Client was registered as MobileApp in your Home Assistant. To start using notifications you need to restart your Home Assistant", positiveText: "Restart now", negativeText: "Later", onPositive: () { diff --git a/lib/ui_widgets/config_panel_widget.dart b/lib/ui_widgets/config_panel_widget.dart index 1ed8046..f59f670 100644 --- a/lib/ui_widgets/config_panel_widget.dart +++ b/lib/ui_widgets/config_panel_widget.dart @@ -38,17 +38,13 @@ class _ConfigPanelWidgetState extends State { Row( mainAxisSize: MainAxisSize.min, children: [ - FlatServiceButton( - text: "Restart", - serviceName: "restart", - serviceDomain: "homeassistant", - entityId: null, + FlatButton( + child: Text('Restart', style: TextStyle(color: Colors.blue)), + onPressed: () => restart(), ), - FlatServiceButton( - text: "Stop", - serviceName: "stop", - serviceDomain: "homeassistant", - entityId: null, + FlatButton( + child: Text("Stop", style: TextStyle(color: Colors.blue)), + onPressed: () => stop(), ), ], ) @@ -68,18 +64,14 @@ class _ConfigPanelWidgetState extends State { Container(height: Sizes.rowPadding,), Text("${HomeAssistant().userName}'s ${Device().model}, ${Device().osName} ${Device().osVersion}"), Container(height: 6.0,), - Text("Reseting mobile app registration will not remove integration from Home Assistant but creates a new one with different device. If you want to reset mobile app registration completally you need to remove MobileApp from Configuretion -> Integrations of your Home Assistant."), + Text("Here you can manually check if HA Client integration with your Home Assistant works fine."), Divider(), Row( mainAxisSize: MainAxisSize.min, children: [ - FlatButton( - onPressed: () => resetRegistration(), - child: Text("Reset registration") - ), FlatButton( onPressed: () => updateRegistration(), - child: Text("Update registration") + child: Text("Check registration", style: TextStyle(color: Colors.blue)) ) ], ) @@ -90,34 +82,32 @@ class _ConfigPanelWidgetState extends State { ]; } - resetRegistration() { - HomeAssistant().checkAppRegistration(forceRegister: true).then((_) { - Navigator.of(context).pop(); - eventBus.fire(ShowDialogEvent( - title: "App registered", - body: "To start using notifications you need to restart your Home Assistant", - positiveText: "Restart now", - negativeText: "Later", - onPositive: () { - Connection().callService(domain: "homeassistant", service: "restart", entityId: null); - }, - )); - }); + restart() { + eventBus.fire(ShowDialogEvent( + title: "Are you sure you want to restart Home Assistant?", + body: "This will restart your Home Assistant server.", + positiveText: "Sure. Make it so", + negativeText: "What?? No!", + onPositive: () { + Connection().callService(domain: "homeassistant", service: "restart", entityId: null); + }, + )); + } + + stop() { + eventBus.fire(ShowDialogEvent( + title: "Are you sure you wanr to STOP Home Assistant?", + body: "This will STOP your Home Assistant server. It means that your web interface as well as HA Client will not work untill you'll find a way to start your server using ssh or something.", + positiveText: "Sure. Make it so", + negativeText: "What?? No!", + onPositive: () { + Connection().callService(domain: "homeassistant", service: "stop", entityId: null); + }, + )); } updateRegistration() { - HomeAssistant().checkAppRegistration().then((_) { - //Navigator.of(context).pop(); - /*eventBus.fire(ShowDialogEvent( - title: "App registration updated", - body: "To start using notifications you need to restart your Home Assistant", - positiveText: "Restart now", - negativeText: "Later", - onPositive: () { - Connection().callService(domain: "homeassistant", service: "restart", entityId: null); - }, - ));*/ - }); + HomeAssistant().checkAppRegistration(); } @override