HaCasa icon indicating copy to clipboard operation
HaCasa copied to clipboard

Clean up code

Open damianeickhoff opened this issue 1 year ago • 1 comments

All the code need a pretty good swipe through.

  • Create Variables
  • Remove direct references to entity's
  • Make it better

damianeickhoff avatar Jan 11 '24 22:01 damianeickhoff

Thank you for your work. To clean up the code for the weather forecast you could edit the following code. name: '[[[ return states["sensor.weather_forecast_1"].state ]]]' to:

name: >-
  [[[
    var days = ['Zon', 'Ma', 'Di', 'Woe', 'Do', 'Vrij', 'Zat'];
    var currentDate = new Date(states[entity.entity_id].attributes.forecast[0].datetime);
    currentDate.setDate(currentDate.getDate());
    return days[currentDate.getDay()];
  ]]]

It is a little more code, but his makes adding an extra sensor unnecessary and ensures a correct link to the correct weather forecast.

TouTje avatar Feb 01 '24 13:02 TouTje