diff --git a/lib/configuration.page.dart b/lib/configuration.page.dart new file mode 100644 index 0000000..25c19cf --- /dev/null +++ b/lib/configuration.page.dart @@ -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 { + + List _items; + + @override + void initState() { + super.initState(); + _items = [ + 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: [ + 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: [ + 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(); + } +} diff --git a/lib/entity_class/automation_entity.dart b/lib/entity_class/automation_entity.dart index 25207af..6862be4 100644 --- a/lib/entity_class/automation_entity.dart +++ b/lib/entity_class/automation_entity.dart @@ -15,6 +15,8 @@ class AutomationEntity extends Entity { mainAxisSize: MainAxisSize.max, children: [ FlatServiceButton( + serviceDomain: domain, + entityId: entityId, text: "TRIGGER", serviceName: "trigger", ) diff --git a/lib/entity_class/button_entity.class.dart b/lib/entity_class/button_entity.class.dart index c726910..832b029 100644 --- a/lib/entity_class/button_entity.class.dart +++ b/lib/entity_class/button_entity.class.dart @@ -6,6 +6,9 @@ class ButtonEntity extends Entity { @override Widget _buildStatePart(BuildContext context) { return FlatServiceButton( + entityId: entityId, + serviceDomain: domain, + serviceName: 'turn_on', text: "EXECUTE", ); } diff --git a/lib/entity_widgets/common/flat_service_button.dart b/lib/entity_widgets/common/flat_service_button.dart index ccda992..405d6a1 100644 --- a/lib/entity_widgets/common/flat_service_button.dart +++ b/lib/entity_widgets/common/flat_service_button.dart @@ -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, diff --git a/lib/main.dart b/lib/main.dart index e9a228f..b50a9ce 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 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"),