2019-03-13 16:39:23 +02:00
part of ' ../main.dart ' ;
2019-02-16 22:04:49 +02:00
2019-03-13 16:39:23 +02:00
class ConfigPanelWidget extends StatefulWidget {
ConfigPanelWidget ( { Key key } ) : super ( key: key ) ;
2019-02-16 22:04:49 +02:00
@ override
2019-03-13 16:39:23 +02:00
_ConfigPanelWidgetState createState ( ) = > new _ConfigPanelWidgetState ( ) ;
2019-02-16 22:04:49 +02:00
}
class ConfigurationItem {
ConfigurationItem ( { this . isExpanded: false , this . header , this . body } ) ;
bool isExpanded ;
final String header ;
final Widget body ;
}
2019-03-13 16:39:23 +02:00
class _ConfigPanelWidgetState extends State < ConfigPanelWidget > {
2019-02-16 22:04:49 +02:00
List < ConfigurationItem > _items ;
@ override
void initState ( ) {
super . initState ( ) ;
_items = < ConfigurationItem > [
2019-06-21 13:33:28 +03:00
ConfigurationItem (
header: ' Home Assistant Cloud ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatButton (
child: Text ( ' Open web version ' , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) {
2019-06-21 21:01:53 +03:00
HAUtils . launchURLInCustomTab ( context: context , url: Connection ( ) . httpWebHost + " /config/cloud/account " ) ;
2019-06-21 13:33:28 +03:00
} ,
)
] ,
) ,
)
) ,
ConfigurationItem (
header: ' Integrations ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatButton (
child: Text ( ' Open web version ' , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) {
2019-06-21 21:01:53 +03:00
HAUtils . launchURLInCustomTab ( context: context , url: Connection ( ) . httpWebHost + " /config/integrations/dashboard " ) ;
2019-06-21 13:33:28 +03:00
} ,
)
] ,
) ,
)
) ,
ConfigurationItem (
header: ' Users ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatButton (
child: Text ( ' Open web version ' , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) {
2019-06-21 21:01:53 +03:00
HAUtils . launchURLInCustomTab ( context: context , url: Connection ( ) . httpWebHost + " /config/users/picker " ) ;
2019-06-21 13:33:28 +03:00
} ,
)
] ,
) ,
)
) ,
2019-02-16 22:04:49 +02:00
ConfigurationItem (
header: ' General ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
2019-06-21 13:33:28 +03:00
FlatButton (
child: Text ( ' Open web version ' , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) {
2019-06-21 21:01:53 +03:00
HAUtils . launchURLInCustomTab ( context: context , url: Connection ( ) . httpWebHost + " /config/core " ) ;
2019-06-21 13:33:28 +03:00
} ,
) ,
Container ( height: Sizes . rowPadding , ) ,
2019-02-16 22:04:49 +02:00
Text ( " Server management " , style: TextStyle ( fontSize: Sizes . largeFontSize ) ) ,
Container ( height: Sizes . rowPadding , ) ,
Text ( " Control your Home Assistant server from HA Client. " ) ,
Divider ( ) ,
Row (
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
2019-06-21 12:53:03 +03:00
FlatButton (
child: Text ( ' Restart ' , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) = > restart ( ) ,
2019-02-16 22:04:49 +02:00
) ,
2019-06-21 12:53:03 +03:00
FlatButton (
child: Text ( " Stop " , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) = > stop ( ) ,
2019-02-16 22:04:49 +02:00
) ,
] ,
)
] ,
) ,
)
2019-06-21 13:33:28 +03:00
) ,
ConfigurationItem (
header: ' Persons ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatButton (
child: Text ( ' Open web version ' , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) {
2019-06-21 21:01:53 +03:00
HAUtils . launchURLInCustomTab ( context: context , url: Connection ( ) . httpWebHost + " /config/person " ) ;
2019-06-21 13:33:28 +03:00
} ,
)
] ,
) ,
)
) ,
ConfigurationItem (
header: ' Entity Registry ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatButton (
child: Text ( ' Open web version ' , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) {
2019-06-21 21:01:53 +03:00
HAUtils . launchURLInCustomTab ( context: context , url: Connection ( ) . httpWebHost + " /config/entity_registry " ) ;
2019-06-21 13:33:28 +03:00
} ,
)
] ,
) ,
)
) ,
ConfigurationItem (
header: ' Area Registry ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatButton (
child: Text ( ' Open web version ' , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) {
2019-06-21 21:01:53 +03:00
HAUtils . launchURLInCustomTab ( context: context , url: Connection ( ) . httpWebHost + " /config/area_registry " ) ;
2019-06-21 13:33:28 +03:00
} ,
)
] ,
) ,
)
) ,
ConfigurationItem (
header: ' Automation ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatButton (
child: Text ( ' Open web version ' , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) {
2019-06-21 21:01:53 +03:00
HAUtils . launchURLInCustomTab ( context: context , url: Connection ( ) . httpWebHost + " /config/automation " ) ;
2019-06-21 13:33:28 +03:00
} ,
)
] ,
) ,
)
) ,
ConfigurationItem (
header: ' Script ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatButton (
child: Text ( ' Open web version ' , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) {
2019-06-21 21:01:53 +03:00
HAUtils . launchURLInCustomTab ( context: context , url: Connection ( ) . httpWebHost + " /config/script " ) ;
2019-06-21 13:33:28 +03:00
} ,
)
] ,
) ,
)
) ,
ConfigurationItem (
header: ' Customization ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatButton (
child: Text ( ' Open web version ' , style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) {
2019-06-21 21:01:53 +03:00
HAUtils . launchURLInCustomTab ( context: context , url: Connection ( ) . httpWebHost + " /config/customize " ) ;
2019-06-21 13:33:28 +03:00
} ,
)
] ,
) ,
)
2019-06-15 18:07:11 +03:00
) ,
ConfigurationItem (
header: ' Mobile app ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
Text ( " Registration " , style: TextStyle ( fontSize: Sizes . largeFontSize ) ) ,
Container ( height: Sizes . rowPadding , ) ,
Text ( " ${ HomeAssistant ( ) . userName } 's ${ Device ( ) . model } , ${ Device ( ) . osName } ${ Device ( ) . osVersion } " ) ,
Container ( height: 6.0 , ) ,
2019-06-21 12:53:03 +03:00
Text ( " Here you can manually check if HA Client integration with your Home Assistant works fine. " ) ,
2019-06-15 18:07:11 +03:00
Divider ( ) ,
Row (
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatButton (
onPressed: ( ) = > updateRegistration ( ) ,
2019-06-21 12:53:03 +03:00
child: Text ( " Check registration " , style: TextStyle ( color: Colors . blue ) )
2019-06-15 18:07:11 +03:00
)
] ,
)
] ,
) ,
)
2019-02-16 22:04:49 +02:00
)
] ;
}
2019-06-21 12:53:03 +03:00
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 ) ;
} ,
) ) ;
2019-06-15 18:07:11 +03:00
}
updateRegistration ( ) {
2019-06-21 12:53:03 +03:00
HomeAssistant ( ) . checkAppRegistration ( ) ;
2019-06-15 18:07:11 +03:00
}
2019-02-16 22:04:49 +02:00
@ override
Widget build ( BuildContext context ) {
2019-03-13 16:39:23 +02:00
return ListView (
children: [
new ExpansionPanelList (
expansionCallback: ( int index , bool isExpanded ) {
setState ( ( ) {
_items [ index ] . isExpanded = ! _items [ index ] . isExpanded ;
} ) ;
} ,
children: _items . map ( ( ConfigurationItem item ) {
return new ExpansionPanel (
headerBuilder: ( BuildContext context , bool isExpanded ) {
return CardHeaderWidget (
name: item . header ,
) ;
} ,
isExpanded: item . isExpanded ,
body: new Container (
child: item . body ,
) ,
) ;
} ) . toList ( ) ,
) ,
] ,
2019-02-16 22:04:49 +02:00
) ;
}
@ override
void dispose ( ) {
super . dispose ( ) ;
}
}