Resolves #176 History can be requested only once per 30 seconds
This commit is contained in:
		| @@ -56,10 +56,6 @@ class Entity { | |||||||
|     domain = rawData["entity_id"].split(".")[0]; |     domain = rawData["entity_id"].split(".")[0]; | ||||||
|     entityId = rawData["entity_id"]; |     entityId = rawData["entity_id"]; | ||||||
|     state = rawData["state"]; |     state = rawData["state"]; | ||||||
|     if (domain == "sun") { |  | ||||||
|       state = "iuwfhiwushf iwuwfhiuwefh dsjhfkjsdfnksdj nfksdjfn ksdjfn kdsjfndskj sdk fhksbsk jvfk jvsfkj  sfkjvsfkvdsjk bvsfk svfjk"; |  | ||||||
|       attributes["friendly_name"] = "Black hole sun, wan't you come, wan't you come"; |  | ||||||
|     } |  | ||||||
|     assumedState = state; |     assumedState = state; | ||||||
|     _lastUpdated = DateTime.tryParse(rawData["last_updated"]); |     _lastUpdated = DateTime.tryParse(rawData["last_updated"]); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -31,6 +31,7 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> { | |||||||
|  |  | ||||||
|   List _history; |   List _history; | ||||||
|   bool _needToUpdateHistory; |   bool _needToUpdateHistory; | ||||||
|  |   DateTime _historyLastUpdated; | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   void initState() { |   void initState() { | ||||||
| @@ -39,6 +40,12 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   void _loadHistory(HomeAssistant ha, String entityId) { |   void _loadHistory(HomeAssistant ha, String entityId) { | ||||||
|  |     DateTime now = DateTime.now(); | ||||||
|  |     if (_historyLastUpdated != null) { | ||||||
|  |       TheLogger.debug("History was updated ${now.difference(_historyLastUpdated).inSeconds} seconds ago"); | ||||||
|  |     } | ||||||
|  |     if (_historyLastUpdated == null || now.difference(_historyLastUpdated).inSeconds > 30) { | ||||||
|  |       _historyLastUpdated = now; | ||||||
|       ha.getHistory(entityId).then((history){ |       ha.getHistory(entityId).then((history){ | ||||||
|         setState(() { |         setState(() { | ||||||
|           _history = history.isNotEmpty ? history[0] : []; |           _history = history.isNotEmpty ? history[0] : []; | ||||||
| @@ -52,6 +59,7 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> { | |||||||
|         }); |         }); | ||||||
|       }); |       }); | ||||||
|     } |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user