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,
|
mainAxisSize: MainAxisSize.max,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
FlatServiceButton(
|
FlatServiceButton(
|
||||||
|
serviceDomain: domain,
|
||||||
|
entityId: entityId,
|
||||||
text: "TRIGGER",
|
text: "TRIGGER",
|
||||||
serviceName: "trigger",
|
serviceName: "trigger",
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,9 @@ class ButtonEntity extends Entity {
|
|||||||
@override
|
@override
|
||||||
Widget _buildStatePart(BuildContext context) {
|
Widget _buildStatePart(BuildContext context) {
|
||||||
return FlatServiceButton(
|
return FlatServiceButton(
|
||||||
|
entityId: entityId,
|
||||||
|
serviceDomain: domain,
|
||||||
|
serviceName: 'turn_on',
|
||||||
text: "EXECUTE",
|
text: "EXECUTE",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,29 +4,30 @@ class FlatServiceButton extends StatelessWidget {
|
|||||||
|
|
||||||
final String serviceDomain;
|
final String serviceDomain;
|
||||||
final String serviceName;
|
final String serviceName;
|
||||||
|
final String entityId;
|
||||||
final String text;
|
final String text;
|
||||||
final double fontSize;
|
final double fontSize;
|
||||||
|
|
||||||
FlatServiceButton({
|
FlatServiceButton({
|
||||||
Key key,
|
Key key,
|
||||||
this.serviceDomain,
|
@required this.serviceDomain,
|
||||||
this.serviceName: "turn_on",
|
@required this.serviceName,
|
||||||
|
@required this.entityId,
|
||||||
@required this.text,
|
@required this.text,
|
||||||
this.fontSize: Sizes.stateFontSize
|
this.fontSize: Sizes.stateFontSize
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
void _setNewState(Entity entity) {
|
void _setNewState() {
|
||||||
eventBus.fire(new ServiceCallEvent(serviceDomain ?? entity.domain, serviceName, entity.entityId, null));
|
eventBus.fire(new ServiceCallEvent(serviceDomain, serviceName, entityId, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final entityModel = EntityModel.of(context);
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: fontSize*2.5,
|
height: fontSize*2.5,
|
||||||
child: FlatButton(
|
child: FlatButton(
|
||||||
onPressed: (() {
|
onPressed: (() {
|
||||||
_setNewState(entityModel.entityWrapper.entity);
|
_setNewState();
|
||||||
}),
|
}),
|
||||||
child: Text(
|
child: Text(
|
||||||
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/alarm_control_panel_controls.dart';
|
||||||
part 'entity_widgets/controls/camera_controls.dart';
|
part 'entity_widgets/controls/camera_controls.dart';
|
||||||
part 'settings.page.dart';
|
part 'settings.page.dart';
|
||||||
|
part 'configuration.page.dart';
|
||||||
part 'home_assistant.class.dart';
|
part 'home_assistant.class.dart';
|
||||||
part 'log.page.dart';
|
part 'log.page.dart';
|
||||||
part 'entity.page.dart';
|
part 'entity.page.dart';
|
||||||
@ -129,6 +130,7 @@ class HAClientApp extends StatelessWidget {
|
|||||||
routes: {
|
routes: {
|
||||||
"/": (context) => MainPage(title: 'HA Client'),
|
"/": (context) => MainPage(title: 'HA Client'),
|
||||||
"/connection-settings": (context) => ConnectionSettingsPage(title: "Settings"),
|
"/connection-settings": (context) => ConnectionSettingsPage(title: "Settings"),
|
||||||
|
"/configuration": (context) => ConfigurationPage(title: "Configuration"),
|
||||||
"/log-view": (context) => LogViewPage(title: "Log")
|
"/log-view": (context) => LogViewPage(title: "Log")
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -339,6 +341,14 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
menuItems.addAll([
|
menuItems.addAll([
|
||||||
|
new ListTile(
|
||||||
|
leading: Icon(Icons.settings),
|
||||||
|
title: Text("Configuration"),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
Navigator.of(context).pushNamed('/configuration');
|
||||||
|
},
|
||||||
|
),
|
||||||
new ListTile(
|
new ListTile(
|
||||||
leading: Icon(Icons.insert_drive_file),
|
leading: Icon(Icons.insert_drive_file),
|
||||||
title: Text("Log"),
|
title: Text("Log"),
|
||||||
|
Reference in New Issue
Block a user