ayushsharma82 / ESP-DASH

Blazing fast library to create a functional dashboard for ESP8266 / ESP32
https://espdash.pro
GNU General Public License v3.0
976 stars 200 forks source link

Provide default value for Statistic constructor (oss & pro) #173

Closed mathieucarbou closed 11 months ago

mathieucarbou commented 11 months ago

At the time we create the Stat object, we might not be able to access the stats values yet. So we end up setting an empty string to the value:

    Statistic _appFirmwareStat = Statistic(&_dashboard, "App Firmware", "");
    Statistic _appIdStat = Statistic(&_dashboard, "App Id", "");
    Statistic _appManufacturerStat = Statistic(&_dashboard, "App Manufacturer", "");
    Statistic _appName = Statistic(&_dashboard, "App Name", "");
    Statistic _appVersionStat = Statistic(&_dashboard, "App Version", "");
    Statistic _cpuCoresStat = Statistic(&_dashboard, "CPU Cores", "");
    Statistic _cpuModelStat = Statistic(&_dashboard, "CPU Model", "");

It would be better to support a default constructor with a customisable default, like this:

#ifndef DASH_DEFAULT_STATISTICS_VALUE
  #define DASH_DEFAULT_STATISTICS_VALUE ""
#endif

[...]

Statistic(ESPDash *dashboard, const char *key, const char *value = DASH_DEFAULT_STATISTICS_VALUE);