Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looking for help solving this long-time conversion issue (can't find example code to learn from) #51

Open
ironsheep opened this issue Dec 4, 2021 · 0 comments

Comments

@ironsheep
Copy link

ironsheep commented Dec 4, 2021

Hi, I'm back and still just as unsuccessful. re: (my #34)

For more than a year now I've had the interval since the last update not showing up on my card : https://github.com/ironsheep/lovelace-rpi-monitor-card

It was working long ago but changes to the underlying helper methods stopped the display from appearing. You can see the value in the screenshots at the repo. It was working... I'd like to get it working again.

And... it seems (#42) also pointed out this issue...

The issue is that I've spent hours twice now trying to figure out how to call these methods.

The 2nd time the parameters have changed yet again. Can someone please provide examples for how to call these methods in the latest version of these helpers... ??

I even found https://custom-cards.github.io/custom-card-helpers/ which is pretty but does not show any example invocations of any of the methods.

I'm attempting to use computeStateDisplay() and relativeTime()

I apologize if I'm new enough that you deem that this was obvious. Please feel free to send me to examples to study.

Here's what I think I should be doing but it doesn't compile due to the new third parameter data type changing. I'm trying to make the change but am unsuccessful.

private _getRelativeTimeSinceUpdate(): string {
    const stateObj = this._config.entity ? this.hass.states[this._config.entity] : undefined;
    const stateStrInterp = computeStateDisplay(this.hass?.localize, stateObj!, this.hass?.locale);
    const relativeInterp =
      stateStrInterp === undefined ? '{unknown}' : relativeTime(new Date(stateStrInterp), this.hass?.localize);
    const desiredValue = this._sensorAvailable ? relativeInterp : '{unknown}';
    return desiredValue;
  }

  private _getMinutesSinceUpdate(): number {
    const stateObj = this._config.entity ? this.hass.states[this._config.entity] : undefined;
    const stateStrInterp = computeStateDisplay(this.hass?.localize, stateObj!, this.hass?.locale);
    const then = new Date(stateStrInterp);
    const now = new Date();
    let diff = (now.getTime() - then.getTime()) / 1000;
    diff /= 60;
    return Math.abs(Math.round(diff));
  }

The issue is I don't know from where to get the locale value for the 3rd parameter of computeStateDisplay() since there is one in hass (HomeAssistant) I'm trying to use it but the value can come back as undefined which now fails to compile as you might expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant