Looking for some JS help refactoring code for a Wizard Clock

Hello,

Looking to rework some code to work with the built-in HA device trackers as opposed to OwnTracks that the original project was written.

https://github.com/malcolmrigg/WizardClock/blob/43c17e4d20b116ebf1e458349c749f5edf4a460f/weasley-card.js

There is a link to the original JavaScript. I have located the section I need to change for getting the “traveling” piece to start working.

const stateVelo = state && state.attributes ? (
  state.attributes.speed ? state.attributes.speed : (
    state.attribute.moving ? 16 : 0
  )) : 0; 

It used to be state.attributes.velocity instead of speed. The part that seems to not work is the moving part of the equation. I don’t know enough about JavaScript to understand what is happening with all of the variables in this statement.

Is someone willing/able to help?

TIA,
Donnie

This code says:

let stateVelo;
if(state && state.attributes) {
  if(state.attributes.speed) {
    stateVelo = state.attributes.speed;
  } else {
    if(state.attributes.moving) {
      stateVelo = 16;
    } else {
      stateVelo = 0;
    }
  }
} else {
  stateVelo = 0;
}

Hope that helps.

TY for the pseudocode conversion! This has given me some insight. I’ll chew on it and see if I can boil it down into an answer that fits my needs.

This is what I came up with:

        const stateVelo = state && state.attributes ? (
          state.attributes.speed ) : 0; 

Between that and a change to the Resource URL I was able to make it work and stay functional between page loads and core restarts