2019-08-30 21:45:34 +03:00
part of ' ../main.dart ' ;
class ConfigPanelWidget extends StatefulWidget {
ConfigPanelWidget ( { Key key } ) : super ( key: key ) ;
@ override
_ConfigPanelWidgetState createState ( ) = > new _ConfigPanelWidgetState ( ) ;
}
class _ConfigPanelWidgetState extends State < ConfigPanelWidget > {
2019-08-31 23:09:30 +03:00
int _locationInterval = LocationManager ( ) . defaultUpdateIntervalMinutes ;
bool _locationTrackingEnabled = false ;
bool _needToRestartLocationTracking = false ;
2019-08-30 21:45:34 +03:00
@ override
void initState ( ) {
super . initState ( ) ;
_loadSettings ( ) ;
}
_loadSettings ( ) async {
SharedPreferences prefs = await SharedPreferences . getInstance ( ) ;
await prefs . reload ( ) ;
SharedPreferences . getInstance ( ) . then ( ( prefs ) {
setState ( ( ) {
2019-08-31 23:09:30 +03:00
_locationTrackingEnabled = prefs . getBool ( " location-enabled " ) ? ? false ;
_locationInterval = prefs . getInt ( " location-interval " ) ? ? LocationManager ( ) . defaultUpdateIntervalMinutes ;
2019-08-30 21:45:34 +03:00
} ) ;
} ) ;
}
void incLocationInterval ( ) {
2019-08-31 23:09:30 +03:00
_needToRestartLocationTracking = true ;
if ( _locationInterval < 720 ) {
2019-08-30 21:45:34 +03:00
setState ( ( ) {
2019-08-31 23:09:30 +03:00
_locationInterval = _locationInterval + 1 ;
2019-08-30 21:45:34 +03:00
} ) ;
2019-08-31 23:09:30 +03:00
SharedPreferences . getInstance ( ) . then ( ( prefs ) = > prefs . setInt ( " location-interval " , _locationInterval ) ) ;
2019-08-30 21:45:34 +03:00
}
}
void decLocationInterval ( ) {
2019-08-31 23:09:30 +03:00
_needToRestartLocationTracking = true ;
if ( _locationInterval > 1 ) {
2019-08-30 21:45:34 +03:00
setState ( ( ) {
2019-08-31 23:09:30 +03:00
_locationInterval = _locationInterval - 1 ;
2019-08-30 21:45:34 +03:00
} ) ;
SharedPreferences . getInstance ( ) . then ( ( prefs ) {
2019-08-31 23:09:30 +03:00
prefs . setInt ( " location-interval " , _locationInterval ) ;
2019-08-30 21:45:34 +03:00
} ) ;
}
}
restart ( ) {
eventBus . fire ( ShowPopupDialogEvent (
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: ( ) {
2019-08-31 22:10:07 +03:00
ConnectionManager ( ) . callService ( domain: " homeassistant " , service: " restart " , entityId: null ) ;
2019-08-30 21:45:34 +03:00
} ,
) ) ;
}
stop ( ) {
eventBus . fire ( ShowPopupDialogEvent (
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: ( ) {
2019-08-31 22:10:07 +03:00
ConnectionManager ( ) . callService ( domain: " homeassistant " , service: " stop " , entityId: null ) ;
2019-08-30 21:45:34 +03:00
} ,
) ) ;
}
updateRegistration ( ) {
2019-08-31 22:06:52 +03:00
MobileAppIntegrationManager . checkAppRegistration ( showOkDialog: true ) ;
2019-08-30 21:45:34 +03:00
}
resetRegistration ( ) {
eventBus . fire ( ShowPopupDialogEvent (
title: " Waaaait " ,
body: " If you don't whant to have duplicate integrations and entities in your HA for your current device, first you need to remove MobileApp integration from Integration settings in HA and restart server. " ,
positiveText: " Done it already " ,
negativeText: " Ok, I will " ,
onPositive: ( ) {
2019-08-31 22:06:52 +03:00
MobileAppIntegrationManager . checkAppRegistration ( showOkDialog: true , forceRegister: true ) ;
2019-08-30 21:45:34 +03:00
} ,
) ) ;
}
@ override
Widget build ( BuildContext context ) {
return ListView (
children: [
Card (
child: Padding (
padding: EdgeInsets . only ( left: Sizes . leftWidgetPadding , right: Sizes . rightWidgetPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: < Widget > [
ListTile (
title: Text ( " Mobile app integration " ,
textAlign: TextAlign . left ,
overflow: TextOverflow . ellipsis ,
style: new TextStyle ( fontWeight: FontWeight . bold , fontSize: Sizes . largeFontSize ) )
) ,
Text ( " Registration " , style: TextStyle ( fontSize: Sizes . largeFontSize - 2 ) ) ,
Container ( height: Sizes . rowPadding , ) ,
2019-08-31 22:10:07 +03:00
Text ( " ${ HomeAssistant ( ) . userName } 's ${ DeviceInfoManager ( ) . model } , ${ DeviceInfoManager ( ) . osName } ${ DeviceInfoManager ( ) . osVersion } " ) ,
2019-08-30 21:45:34 +03:00
Container ( height: 6.0 , ) ,
Text ( " Here you can manually check if HA Client integration with your Home Assistant works fine. As mobileApp integration in Home Assistant is still in development, this is not 100% correct check. " ) ,
//Divider(),
Row (
mainAxisSize: MainAxisSize . max ,
children: < Widget > [
RaisedButton (
color: Colors . blue ,
onPressed: ( ) = > updateRegistration ( ) ,
child: Text ( " Check registration " , style: TextStyle ( color: Colors . white ) )
) ,
Container ( width: 10.0 , ) ,
RaisedButton (
color: Colors . redAccent ,
onPressed: ( ) = > resetRegistration ( ) ,
child: Text ( " Reset registration " , style: TextStyle ( color: Colors . white ) )
)
] ,
) ,
Divider ( ) ,
Text ( " Location tracking " , style: TextStyle ( fontSize: Sizes . largeFontSize - 2 ) ) ,
Container ( height: Sizes . rowPadding , ) ,
2019-08-31 23:09:30 +03:00
Row (
children: < Widget > [
Text ( " Enable device location tracking " ) ,
Switch (
value: _locationTrackingEnabled ,
onChanged: ( value ) {
SharedPreferences . getInstance ( ) . then ( ( prefs ) = > prefs . setBool ( " location-enabled " , value ) ) ;
setState ( ( ) {
_locationTrackingEnabled = value ;
_needToRestartLocationTracking = true ;
} ) ;
} ,
) ,
] ,
) ,
Container ( height: Sizes . rowPadding , ) ,
2019-08-30 21:45:34 +03:00
Text ( " Location update interval in minutes: " ) ,
Row (
mainAxisAlignment: MainAxisAlignment . center ,
mainAxisSize: MainAxisSize . max ,
children: < Widget > [
//Expanded(child: Container(),),
FlatButton (
padding: EdgeInsets . all ( 0.0 ) ,
child: Text ( " + " , style: TextStyle ( fontSize: Sizes . largeFontSize ) ) ,
onPressed: ( ) = > incLocationInterval ( ) ,
) ,
2019-08-31 23:09:30 +03:00
Text ( " $ _locationInterval " , style: TextStyle ( fontSize: Sizes . largeFontSize ) ) ,
2019-08-30 21:45:34 +03:00
FlatButton (
padding: EdgeInsets . all ( 0.0 ) ,
child: Text ( " - " , style: TextStyle ( fontSize: Sizes . largeFontSize ) ) ,
onPressed: ( ) = > decLocationInterval ( ) ,
) ,
] ,
)
] ,
) ,
) ,
) ,
2019-08-31 22:10:07 +03:00
LinkToWebConfig ( name: " Home Assistant Cloud " , url: ConnectionManager ( ) . httpWebHost + " /config/cloud/account " ) ,
2019-08-30 21:45:34 +03:00
Container ( height: 8.0 , ) ,
2019-08-31 22:10:07 +03:00
LinkToWebConfig ( name: " Integrations " , url: ConnectionManager ( ) . httpWebHost + " /config/integrations/dashboard " ) ,
LinkToWebConfig ( name: " Users " , url: ConnectionManager ( ) . httpWebHost + " /config/users/picker " ) ,
2019-08-30 21:45:34 +03:00
Container ( height: 8.0 , ) ,
2019-08-31 22:10:07 +03:00
LinkToWebConfig ( name: " General " , url: ConnectionManager ( ) . httpWebHost + " /config/core " ) ,
LinkToWebConfig ( name: " Server Control " , url: ConnectionManager ( ) . httpWebHost + " /config/server_control " ) ,
LinkToWebConfig ( name: " Persons " , url: ConnectionManager ( ) . httpWebHost + " /config/person " ) ,
LinkToWebConfig ( name: " Entity Registry " , url: ConnectionManager ( ) . httpWebHost + " /config/entity_registry " ) ,
LinkToWebConfig ( name: " Area Registry " , url: ConnectionManager ( ) . httpWebHost + " /config/area_registry " ) ,
LinkToWebConfig ( name: " Automation " , url: ConnectionManager ( ) . httpWebHost + " /config/automation " ) ,
LinkToWebConfig ( name: " Script " , url: ConnectionManager ( ) . httpWebHost + " /config/script " ) ,
LinkToWebConfig ( name: " Customization " , url: ConnectionManager ( ) . httpWebHost + " /config/customize " ) ,
2019-08-30 21:45:34 +03:00
] ,
) ;
}
@ override
void dispose ( ) {
2019-08-31 23:09:30 +03:00
if ( _needToRestartLocationTracking ) {
Logger . d ( " Location tracking settings was changed. Restarting location service... " ) ;
2019-08-31 23:55:32 +03:00
LocationManager ( ) . startLocationService ( ) ;
2019-08-31 23:09:30 +03:00
if ( _locationTrackingEnabled ) {
LocationManager ( ) . updateDeviceLocation ( ) ;
}
2019-08-30 21:45:34 +03:00
}
super . dispose ( ) ;
}
}