TileBoard
TileBoard copied to clipboard
HISTORY tile can fail to display graph if initialized before entity is ready
Noticed in https://github.com/resoai/TileBoard/pull/433#issuecomment-699512635:
some graphs fail with r is undefined
I've managed to reproduce by restarting HA and then trying to run TB as early as possible after HA restarts. This is possibly due to some timing issues.
It all goes south here:
// Create extra state with current value.
dataset.push({
x: Date.now(),
y: $scope.states[firstStateInfo.entity_id].state
});
That last state seems to be a bit broken in this case:
x: 1601148398645
y: "unknown"
So it looks like $scope.states
doesn't have up to date information at that point.
Actually, I've checked the pre-rollup code and Chart.js has a fix for this issue there.
It's this code: https://github.com/chartjs/Chart.js/blob/17e27e16cc52a7df3e87df8251f040d7cd394dab/src/core/core.scale.js#L450
The this.options.labels
check is missing in the npm
version of Chart.js
With that fix there is no crash but the graphs won't be correct so we should fix that anyway.
Here is a graph where the issue is triggered:
And here is how it should look like: