Resolves #131
This commit is contained in:
parent
f248268984
commit
d9ca55c3b7
@ -1,9 +1,9 @@
|
|||||||
part of 'main.dart';
|
part of 'main.dart';
|
||||||
|
|
||||||
class EntityViewPage extends StatefulWidget {
|
class EntityViewPage extends StatefulWidget {
|
||||||
EntityViewPage({Key key, @required this.entity, @required this.homeAssistant }) : super(key: key);
|
EntityViewPage({Key key, @required this.entityId, @required this.homeAssistant }) : super(key: key);
|
||||||
|
|
||||||
final Entity entity;
|
final String entityId;
|
||||||
final HomeAssistant homeAssistant;
|
final HomeAssistant homeAssistant;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -12,21 +12,26 @@ class EntityViewPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _EntityViewPageState extends State<EntityViewPage> {
|
class _EntityViewPageState extends State<EntityViewPage> {
|
||||||
String _title;
|
String _title;
|
||||||
|
StreamSubscription _refreshDataSubscription;
|
||||||
StreamSubscription _stateSubscription;
|
StreamSubscription _stateSubscription;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_stateSubscription = eventBus.on<StateChangedEvent>().listen((event) {
|
_stateSubscription = eventBus.on<StateChangedEvent>().listen((event) {
|
||||||
if (event.entityId == widget.entity.entityId) {
|
TheLogger.debug("State change event handled by entity page: ${event.entityId}");
|
||||||
|
if (event.entityId == widget.entityId) {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
_refreshDataSubscription = eventBus.on<RefreshDataFinishedEvent>().listen((event) {
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
_prepareData();
|
_prepareData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _prepareData() async {
|
void _prepareData() async {
|
||||||
_title = widget.entity.displayName;
|
_title = widget.homeAssistant.entities.get(widget.entityId).displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -45,7 +50,7 @@ class _EntityViewPageState extends State<EntityViewPage> {
|
|||||||
padding: EdgeInsets.all(10.0),
|
padding: EdgeInsets.all(10.0),
|
||||||
child: HomeAssistantModel(
|
child: HomeAssistantModel(
|
||||||
homeAssistant: widget.homeAssistant,
|
homeAssistant: widget.homeAssistant,
|
||||||
child: widget.entity.buildEntityPageWidget(context)
|
child: widget.homeAssistant.entities.get(widget.entityId).buildEntityPageWidget(context)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -54,6 +59,7 @@ class _EntityViewPageState extends State<EntityViewPage> {
|
|||||||
@override
|
@override
|
||||||
void dispose(){
|
void dispose(){
|
||||||
if (_stateSubscription != null) _stateSubscription.cancel();
|
if (_stateSubscription != null) _stateSubscription.cancel();
|
||||||
|
if (_refreshDataSubscription != null) _refreshDataSubscription.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ class _SwitchStateWidgetState extends State<SwitchStateWidget> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
newState = entity.state;
|
newState = entity.state;
|
||||||
updatedHere = true;
|
updatedHere = true;
|
||||||
TheLogger.debug("Timer@!!");
|
//TheLogger.debug("Timer@!!");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
eventBus.fire(new ServiceCallEvent(
|
eventBus.fire(new ServiceCallEvent(
|
||||||
|
@ -156,6 +156,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
_settingsLoaded = false;
|
_settingsLoaded = false;
|
||||||
WidgetsBinding.instance.addObserver(this);
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
|
||||||
|
TheLogger.debug("<!!!> Creating new HomeAssistant instance");
|
||||||
_homeAssistant = HomeAssistant();
|
_homeAssistant = HomeAssistant();
|
||||||
|
|
||||||
_settingsSubscription = eventBus.on<SettingsChangedEvent>().listen((event) {
|
_settingsSubscription = eventBus.on<SettingsChangedEvent>().listen((event) {
|
||||||
@ -221,7 +222,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
if (_showEntityPageSubscription == null) {
|
if (_showEntityPageSubscription == null) {
|
||||||
_showEntityPageSubscription =
|
_showEntityPageSubscription =
|
||||||
eventBus.on<ShowEntityPageEvent>().listen((event) {
|
eventBus.on<ShowEntityPageEvent>().listen((event) {
|
||||||
_showEntityPage(event.entity);
|
_showEntityPage(event.entity.entityId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +242,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
_refreshData() async {
|
_refreshData() async {
|
||||||
_homeAssistant.updateSettings(_webSocketApiEndpoint, _password, _authType, _useLovelaceUI);
|
_homeAssistant.updateSettings(_webSocketApiEndpoint, _password, _authType, _useLovelaceUI);
|
||||||
_hideBottomBar();
|
_hideBottomBar();
|
||||||
_showInfoBottomBar(message: "Refreshing data...");
|
_showInfoBottomBar(message: "Refreshing...");
|
||||||
await _homeAssistant.fetch().then((result) {
|
await _homeAssistant.fetch().then((result) {
|
||||||
_hideBottomBar();
|
_hideBottomBar();
|
||||||
}).catchError((e) {
|
}).catchError((e) {
|
||||||
@ -270,11 +271,11 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
_homeAssistant.callService(domain, service, entityId, additionalParams).catchError((e) => _setErrorState(e));
|
_homeAssistant.callService(domain, service, entityId, additionalParams).catchError((e) => _setErrorState(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showEntityPage(Entity entity) {
|
void _showEntityPage(String entityId) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => EntityViewPage(entity: entity, homeAssistant: _homeAssistant),
|
builder: (context) => EntityViewPage(entityId: entityId, homeAssistant: _homeAssistant),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -386,7 +387,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
|
|
||||||
void _showInfoBottomBar({@required String message}) {
|
void _showInfoBottomBar({@required String message}) {
|
||||||
_bottomBarAction = Container(height: 0.0, width: 0.0,);
|
_bottomBarAction = Container(height: 0.0, width: 0.0,);
|
||||||
_bottomBarColor = Colors.blue.shade100;
|
_bottomBarColor = Colors.grey.shade50;
|
||||||
setState(() {
|
setState(() {
|
||||||
_bottomBarText = "$message";
|
_bottomBarText = "$message";
|
||||||
_showBottomBar = true;
|
_showBottomBar = true;
|
||||||
|
Reference in New Issue
Block a user