Resolves #176 History can be requested only once per 30 seconds
This commit is contained in:
parent
f5434e26e5
commit
3190b45db3
@ -56,10 +56,6 @@ class Entity {
|
||||
domain = rawData["entity_id"].split(".")[0];
|
||||
entityId = rawData["entity_id"];
|
||||
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;
|
||||
_lastUpdated = DateTime.tryParse(rawData["last_updated"]);
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
||||
|
||||
List _history;
|
||||
bool _needToUpdateHistory;
|
||||
DateTime _historyLastUpdated;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -39,6 +40,12 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
||||
}
|
||||
|
||||
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){
|
||||
setState(() {
|
||||
_history = history.isNotEmpty ? history[0] : [];
|
||||
@ -52,6 +59,7 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
Reference in New Issue
Block a user