2018-09-29 16:19:01 +03:00
|
|
|
part of 'main.dart';
|
|
|
|
|
|
|
|
class EntityViewPage extends StatefulWidget {
|
2018-10-07 23:06:06 +03:00
|
|
|
EntityViewPage({Key key, @required this.entity, @required this.homeAssistant }) : super(key: key);
|
2018-09-29 16:19:01 +03:00
|
|
|
|
2018-10-02 00:41:40 +03:00
|
|
|
final Entity entity;
|
2018-10-07 23:06:06 +03:00
|
|
|
final HomeAssistant homeAssistant;
|
2018-09-29 16:19:01 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
_EntityViewPageState createState() => new _EntityViewPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _EntityViewPageState extends State<EntityViewPage> {
|
|
|
|
String _title;
|
2018-09-29 17:59:38 +03:00
|
|
|
StreamSubscription _stateSubscription;
|
2018-09-29 16:19:01 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2018-09-29 17:59:38 +03:00
|
|
|
if (_stateSubscription != null) _stateSubscription.cancel();
|
|
|
|
_stateSubscription = eventBus.on<StateChangedEvent>().listen((event) {
|
2018-10-07 23:06:06 +03:00
|
|
|
if (event.entityId == widget.entity.entityId) {
|
2018-09-30 01:07:02 +03:00
|
|
|
setState(() {});
|
|
|
|
}
|
2018-09-29 17:59:38 +03:00
|
|
|
});
|
2018-09-29 16:19:01 +03:00
|
|
|
_prepareData();
|
2018-10-07 23:06:06 +03:00
|
|
|
_getHistory();
|
2018-09-29 16:19:01 +03:00
|
|
|
}
|
|
|
|
|
2018-10-07 23:06:06 +03:00
|
|
|
void _prepareData() async {
|
|
|
|
_title = widget.entity.displayName;
|
2018-09-29 16:19:01 +03:00
|
|
|
}
|
|
|
|
|
2018-10-07 23:06:06 +03:00
|
|
|
void _getHistory() {
|
2018-10-08 23:11:56 +03:00
|
|
|
/* widget.homeAssistant.getHistory(widget.entity.entityId).then((List history) {
|
2018-10-07 23:06:06 +03:00
|
|
|
if (history != null) {
|
|
|
|
|
|
|
|
}
|
2018-10-08 23:11:56 +03:00
|
|
|
});*/
|
2018-10-07 23:06:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-29 16:19:01 +03:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return new Scaffold(
|
|
|
|
appBar: new AppBar(
|
|
|
|
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
|
|
|
|
Navigator.pop(context);
|
|
|
|
}),
|
|
|
|
// Here we take the value from the MyHomePage object that was created by
|
|
|
|
// the App.build method, and use it to set our appbar title.
|
|
|
|
title: new Text(_title),
|
|
|
|
),
|
|
|
|
body: Padding(
|
|
|
|
padding: EdgeInsets.all(10.0),
|
2018-10-07 23:06:06 +03:00
|
|
|
child: widget.entity.buildWidget(context, EntityWidgetType.extended)
|
2018-09-29 16:19:01 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2018-09-29 17:59:38 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose(){
|
|
|
|
if (_stateSubscription != null) _stateSubscription.cancel();
|
|
|
|
super.dispose();
|
|
|
|
}
|
2018-09-29 16:19:01 +03:00
|
|
|
}
|