WIP #355 Disconnect when logout

This commit is contained in:
estevez-dev
2019-04-05 13:06:14 +03:00
parent 15b3d31a6f
commit cabf836fa3
6 changed files with 28 additions and 33 deletions

View File

@ -131,7 +131,7 @@ class _CameraStreamViewState extends State<CameraStreamView> {
.of(context)
.entityWrapper
.entity;
_webHost = HomeAssistantModel.of(context).homeAssistant.connection.httpWebHost;
_webHost = Connection().httpWebHost;
_connect();
}

View File

@ -40,14 +40,14 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
_needToUpdateHistory = true;
}
void _loadHistory(HomeAssistant ha, String entityId) {
void _loadHistory(String entityId) {
DateTime now = DateTime.now();
if (_historyLastUpdated != null) {
Logger.d("History was updated ${now.difference(_historyLastUpdated).inSeconds} seconds ago");
}
if (_historyLastUpdated == null || now.difference(_historyLastUpdated).inSeconds > 30) {
_historyLastUpdated = now;
ha.connection.getHistory(entityId).then((history){
Connection().getHistory(entityId).then((history){
if (!_disposed) {
setState(() {
_history = history.isNotEmpty ? history[0] : [];
@ -68,13 +68,12 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
@override
Widget build(BuildContext context) {
final HomeAssistantModel homeAssistantModel = HomeAssistantModel.of(context);
final EntityModel entityModel = EntityModel.of(context);
final Entity entity = entityModel.entityWrapper.entity;
if (!_needToUpdateHistory) {
_needToUpdateHistory = true;
} else {
_loadHistory(homeAssistantModel.homeAssistant, entity.entityId);
_loadHistory(entity.entityId);
}
return _buildChart();
}