kbrown01 / SportStandingsScores

Sports Standings and Scores Sensors and Dashboard for Home Assistant
12 stars 1 forks source link

NHL Stats off because some teams have clincher field #1

Closed kbrown01 closed 1 year ago

kbrown01 commented 1 year ago

ESPN stats started returning "CLINCHER" object in JSON, but only for those teams who have clinched. This screwed up indexing the fields.

Two solutions implemented for this for NHL only now, will implement the change in other sports.

First, the proper way to grab a field is by "abbreviation" and not positional index. This assumes that ESPN will not change the abbreviation for particular stats (doubtful). This is done using .find. FOr example for the attribute Games Played (GP):

        - name: GP
          data: entries
          modify: x.stats.find(y=>y.abbreviation == 'GP').displayValue

The second was to handle when an object does not exist without error in the flex-table. This only occurs for CLINCH I would think. it could be made as a generic change across all attributes, but implemented now for only CLINCH.

        - name: C
          data: entries
          modify: if(typeof x.stats.find(y=>y.abbreviation == 'CLINCH') !== 'undefined' ){x.stats.find(y=>y.abbreviation == 'CLINCH').displayValue}else{'-'}
kbrown01 commented 1 year ago

Implemented in lasted code for NHL and uploaded.