Resolves #283 Add possibility to restrat HA
This commit is contained in:
parent
e06b66c523
commit
93680c981c
105
lib/configuration.page.dart
Normal file
105
lib/configuration.page.dart
Normal file
@ -0,0 +1,105 @@
|
||||
part of 'main.dart';
|
||||
|
||||
class ConfigurationPage extends StatefulWidget {
|
||||
ConfigurationPage({Key key, this.title}) : super(key: key);
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
_ConfigurationPageState createState() => new _ConfigurationPageState();
|
||||
}
|
||||
|
||||
class ConfigurationItem {
|
||||
ConfigurationItem({ this.isExpanded: false, this.header, this.body });
|
||||
|
||||
bool isExpanded;
|
||||
final String header;
|
||||
final Widget body;
|
||||
}
|
||||
|
||||
class _ConfigurationPageState extends State<ConfigurationPage> {
|
||||
|
||||
List<ConfigurationItem> _items;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_items = <ConfigurationItem>[
|
||||
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>[
|
||||
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>[
|
||||
FlatServiceButton(
|
||||
text: "Restart",
|
||||
serviceName: "restart",
|
||||
serviceDomain: "homeassistant",
|
||||
entityId: null,
|
||||
),
|
||||
FlatServiceButton(
|
||||
text: "Stop",
|
||||
serviceName: "stop",
|
||||
serviceDomain: "homeassistant",
|
||||
entityId: null,
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return new Scaffold(
|
||||
appBar: new AppBar(
|
||||
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
|
||||
Navigator.pop(context);
|
||||
}),
|
||||
title: new Text(widget.title),
|
||||
),
|
||||
body: 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(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@ class AutomationEntity extends Entity {
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
FlatServiceButton(
|
||||
serviceDomain: domain,
|
||||
entityId: entityId,
|
||||
text: "TRIGGER",
|
||||
serviceName: "trigger",
|
||||
)
|
||||
|
@ -6,6 +6,9 @@ class ButtonEntity extends Entity {
|
||||
@override
|
||||
Widget _buildStatePart(BuildContext context) {
|
||||
return FlatServiceButton(
|
||||
entityId: entityId,
|
||||
serviceDomain: domain,
|
||||
serviceName: 'turn_on',
|
||||
text: "EXECUTE",
|
||||
);
|
||||
}
|
||||
|
@ -4,29 +4,30 @@ class FlatServiceButton extends StatelessWidget {
|
||||
|
||||
final String serviceDomain;
|
||||
final String serviceName;
|
||||
final String entityId;
|
||||
final String text;
|
||||
final double fontSize;
|
||||
|
||||
FlatServiceButton({
|
||||
Key key,
|
||||
this.serviceDomain,
|
||||
this.serviceName: "turn_on",
|
||||
@required this.serviceDomain,
|
||||
@required this.serviceName,
|
||||
@required this.entityId,
|
||||
@required this.text,
|
||||
this.fontSize: Sizes.stateFontSize
|
||||
}) : super(key: key);
|
||||
|
||||
void _setNewState(Entity entity) {
|
||||
eventBus.fire(new ServiceCallEvent(serviceDomain ?? entity.domain, serviceName, entity.entityId, null));
|
||||
void _setNewState() {
|
||||
eventBus.fire(new ServiceCallEvent(serviceDomain, serviceName, entityId, null));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final entityModel = EntityModel.of(context);
|
||||
return SizedBox(
|
||||
height: fontSize*2.5,
|
||||
child: FlatButton(
|
||||
onPressed: (() {
|
||||
_setNewState(entityModel.entityWrapper.entity);
|
||||
_setNewState();
|
||||
}),
|
||||
child: Text(
|
||||
text,
|
||||
|
@ -75,6 +75,7 @@ part 'entity_widgets/controls/fan_controls.dart';
|
||||
part 'entity_widgets/controls/alarm_control_panel_controls.dart';
|
||||
part 'entity_widgets/controls/camera_controls.dart';
|
||||
part 'settings.page.dart';
|
||||
part 'configuration.page.dart';
|
||||
part 'home_assistant.class.dart';
|
||||
part 'log.page.dart';
|
||||
part 'entity.page.dart';
|
||||
@ -129,6 +130,7 @@ class HAClientApp extends StatelessWidget {
|
||||
routes: {
|
||||
"/": (context) => MainPage(title: 'HA Client'),
|
||||
"/connection-settings": (context) => ConnectionSettingsPage(title: "Settings"),
|
||||
"/configuration": (context) => ConfigurationPage(title: "Configuration"),
|
||||
"/log-view": (context) => LogViewPage(title: "Log")
|
||||
},
|
||||
);
|
||||
@ -339,6 +341,14 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||
]);
|
||||
} else {
|
||||
menuItems.addAll([
|
||||
new ListTile(
|
||||
leading: Icon(Icons.settings),
|
||||
title: Text("Configuration"),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed('/configuration');
|
||||
},
|
||||
),
|
||||
new ListTile(
|
||||
leading: Icon(Icons.insert_drive_file),
|
||||
title: Text("Log"),
|
||||
|
Reference in New Issue
Block a user