sdetweil / MMM-Config

testing
30 stars 3 forks source link

Changed module settings not updating in form after restart #43

Closed PandaKing185 closed 3 months ago

PandaKing185 commented 3 months ago

Starting config.js of relevant modules (censored sensitive info):

{
        module: "MMM-Tesla",
        position: "top_right",
        config: {
          source: {
            name: "tessie",
            apiKey: "********************",
            vin: "****************"
          },
          items: [
            "battery",
            "odometer",
            "heading",
            "battery",
            "range",
            "range-estimated",
            "power-connected",
            "charge-time",
            "charge-added",
            "charge-power",
            "locked",
            "odometer",
            "temperature",
            "map",
            "version",
            "version-new",
            "location",
            "data-time"
          ]
        }
{
        module: "weather",
        position: "top_right",
        label: "instance 1",
        order: "2",
        index: 0,
        config: {
          weatherProvider: "weathergov",
          apiBase: "https://api.weather.gov/points/",
          weatherEndpoint: "/forecast",
          lat: *****,
          lon: *****,
          windUnits: "mph",
          timeFormat: 24,
          useBeaufort: true,
          degreeLabel: "false",
          useKmh: false,
          showHumidity: false,
          units: "metric",
          tempUnits: "metric"
        },
        disabled: false
      }

Steps to reproduce (and taken in somefile.txt):

  1. Start MM
  2. Open webform via ip:port/modules/MMM-Config/review
  3. Remove all items but battery and odometer from MMM-Tesla: image
  4. Change default Weather module instance one units and tempUnits from metric to imperial: Screenshot 2024-08-08 121550
  5. Click save config
  6. config.js now shows correct configuration:
    {
        module: "MMM-Tesla",
        position: "top_right",
        config: {
          source: {
            name: "tessie",
            apiKey: "**************",
            vin: "*************"
          },
          items: [
            "battery",
            "odometer"
          ]
        },
        order: "1",
        disabled: false
      }
    {
        module: "weather",
        position: "top_right",
        label: "instance 1",
        order: "2",
        index: 0,
        config: {
          weatherProvider: "weathergov",
          apiBase: "https://api.weather.gov/points/",
          weatherEndpoint: "/forecast",
          lat: ********,
          lon: ********,
          windUnits: "mph",
          timeFormat: 24,
          useBeaufort: true,
          degreeLabel: "false",
          useKmh: false,
          showHumidity: false
        },
        disabled: false
      }
  7. Web form refreshes and shows old configuration: Screenshot 2024-08-08 121506 image

Restarting MM will load the correct configuration onto the mirror, but the web form will still show the old configuration, despite the config.js still showing the correct configuration. This only applies to changes in the "Modules" section. Changes in the "Base" and "Module Positions" sections do properly save and update in the form.

PandaKing185 commented 3 months ago

I cant figure out the rhyme or reason for when it saves. Previously I was having issues with it reverting after updating the restart condition for MMM-Config to "use PM2," but I just tried it and it did properly save. Trying to save just the Weather module (thinking it might be related to the Tesla module somehow) it still reverts the changes.

PandaKing185 commented 3 months ago

Actually I just realized it's deleting the entry for "units" and "tempUnits", along with many others, instead of changing the value. Compare instance 1 of the weather module (the one changed):

{
        module: "weather",
        position: "top_right",
        label: "instance 1",
        order: "2",
        index: 0,
        config: {
          weatherProvider: "weathergov",
          apiBase: "https://api.weather.gov/points/",
          weatherEndpoint: "/forecast",
          lat: 28.026182,
          lon: -81.967439,
          windUnits: "mph",
          timeFormat: 24,
          useBeaufort: true,
          degreeLabel: "false",
          useKmh: false,
          showHumidity: false
        },
        disabled: false
      }

with instance 2 (not touched since it's correct):

{
        module: "weather",
        position: "top_right",
        label: "instance 2",
        order: "3",
        index: 1,
        config: {
          weatherProvider: "weathergov",
          apiBase: "https://cors-anywhere.herokuapp.com/https://api.darksky.net",
          weatherEndpoint: "/forecast",
          lat: 28.026182,
          lon: -81.967439,
          units: "imperial",
          tempUnits: "imperial",
          windUnits: "mph",
          updateInterval: 600000,
          animationSpeed: 1000,
          timeFormat: 24,
          showPeriod: true,
          showWindDirection: true,
          useBeaufort: true,
          lang: "en",
          showSun: true,
          degreeLabel: "false",
          decimalSymbol: ".",
          maxNumberOfDays: 5,
          maxEntries: 5,
          fade: true,
          fadePoint: 0.25,
          initialLoadDelay: 0,
          appendLocationNameToHeader: true,
          calendarClass: "calendar",
          tableClass: "small",
          showFeelsLike: true,
          roundTemp: false,
          useKmh: false,
          showPeriodUpper: false,
          showWindDirectionAsArrow: false,
          showHumidity: false,
          showIndoorTemperature: false,
          showIndoorHumidity: false,
          onlyTemp: false,
          showPrecipitationAmount: false,
          colored: false
        },
        disabled: false
      }
sdetweil commented 3 months ago

Some/many time you have to hit refresh AFTER restarting mm. I only build the form at startup

PandaKing185 commented 3 months ago

The same thing occurs with refreshing after restart. I also tried just opening it in a private window after restarting in case there was some sort of cache or something in the browser that kept it from updating with no luck.

sdetweil commented 3 months ago

What are the defaults for units and tempUnits?

The form should have everything, if the value is the same as default, then I don’t save it in config, as the default will be used by the module. This is the mm design.

PandaKing185 commented 3 months ago

image

default in weather.js appears to be "config.units," which I assume is the units setting in config.js, which is set to "imperial," and the form reflects this: image

So that makes sense that it wouldnt be saved in config.js, but then I'm not sure why it's loading as "metric" in the form after restart.

sdetweil commented 3 months ago

Can you look in defaults.js in my module folder, it’s the collection of the module defaults

PandaKing185 commented 3 months ago

Also config.units:

weather_defaults:  {
                weatherProvider: "openweathermap",
                roundTemp: false,
                type: "current", // current, forecast, daily (equivalent to forecast), hourly (only with OpenWeatherMap /onecall endpoint)
                lang: config.language,
                units: config.units,
                tempUnits: config.units,
                windUnits: config.units,
                timeFormat: config.timeFormat,
                updateInterval: 10 * 60 * 1000, // every 10 minutes
                animationSpeed: 1000,
                showFeelsLike: true,
                showHumidity: "none", // this is now a string; see current.njk
                showIndoorHumidity: false,
                showIndoorTemperature: false,
                allowOverrideNotification: false,
                showPeriod: true,
                showPeriodUpper: false,
                showPrecipitationAmount: false,
                showPrecipitationProbability: false,
                showUVIndex: false,
                showSun: true,
                showWindDirection: true,
                showWindDirectionAsArrow: false,
                degreeLabel: false,
                decimalSymbol: ".",
                maxNumberOfDays: 5,
                maxEntries: 5,
                ignoreToday: false,
                fade: true,
                fadePoint: 0.25, // Start on 1/4th of the list.
                initialLoadDelay: 0, // 0 seconds delay
                appendLocationNameToHeader: true,
                calendarClass: "calendar",
                tableClass: "small",
                onlyTemp: false,
                colored: false,
                absoluteDates: false,
                hourlyForecastIncrements: 1
                }
sdetweil commented 3 months ago

Ok, at the bottom of schema3.json is the collection of values that will populate the form

“value”:{

PandaKing185 commented 3 months ago

Yup. That shows metric:

"weather": [
      {
        "disabled": false,
        "module": "weather",
        "position": "top_right",
        "order": "2",
        "inconfig": "1",
        "config": {
          "weatherProvider": "weathergov",
          "roundTemp": false,
          "type": "current",
          "units": "metric",
          "useKmh": false,
          "tempUnits": "metric",
          "windUnits": "mph",
          "updateInterval": 600000,
          "animationSpeed": 1000,
          "timeFormat": 24,
          "showPeriod": true,
          "showPeriodUpper": false,
          "showWindDirection": true,
          "showWindDirectionAsArrow": false,
          "useBeaufort": true,
          "lang": "en",
          "showHumidity": false,
          "showSun": true,
          "degreeLabel": "false",
          "decimalSymbol": ".",
          "showIndoorTemperature": false,
          "showIndoorHumidity": false,
          "maxNumberOfDays": 5,
          "maxEntries": 5,
          "ignoreToday": false,
          "fade": true,
          "fadePoint": 0.25,
          "initialLoadDelay": 0,
          "appendLocationNameToHeader": true,
          "calendarClass": "calendar",
          "tableClass": "small",
          "onlyTemp": false,
          "showPrecipitationAmount": false,
          "colored": false,
          "showFeelsLike": true,
          "apiBase": "https://api.weather.gov/points/",
          "weatherEndpoint": "/forecast",
          "lat": *******,
          "lon": ******
        },
        "label": "instance 1",
        "index": 0
      },
PandaKing185 commented 3 months ago

And that is after manually setting it to imperial in config.js and restarting MM:

{
        module: "weather",
        position: "top_right",
        label: "instance 1",
        order: "2",
        index: 0,
        config: {
          weatherProvider: "weathergov",
          apiBase: "https://api.weather.gov/points/",
          weatherEndpoint: "/forecast",
          lat: 28.026182,
          lon: -81.967439,
          windUnits: "mph",
          timeFormat: 24,
          useBeaufort: true,
          degreeLabel: "false",
          useKmh: false,
          showHumidity: false,
          units: "imperial",
          tempUnits: "imperial"
        },
        disabled: false
      }
sdetweil commented 3 months ago

Ok, the design is mm starts, build new form of ‘now’

You edit and save AND RESTART to load the new config, AND create a new form

PandaKing185 commented 3 months ago

So on open of the form, it apparently removes the manual entries I have for imperial, which makes sense because like you said it doesnt keep it if it's the default, but then for some reason it auto populates it with metric even though that is not the default. Here is the config after a reboot right before I open the form:

{
        module: "weather",
        position: "top_right",
        label: "instance 1",
        order: "2",
        index: 0,
        config: {
          weatherProvider: "weathergov",
          apiBase: "https://api.weather.gov/points/",
          weatherEndpoint: "/forecast",
          lat: *******,
          lon: ******,
          windUnits: "mph",
          timeFormat: 24,
          useBeaufort: true,
          degreeLabel: "false",
          useKmh: false,
          showHumidity: false,
          units: "imperial",
          tempUnits: "imperial"
        },
        disabled: false
      }

Then I open the form and this is the config.js

{
        module: "weather",
        position: "top_right",
        label: "instance 1",
        order: "2",
        index: 0,
        config: {
          weatherProvider: "weathergov",
          lat: *******,
          lon: ******,
          windUnits: "mph",
          apiBase: "https://api.weather.gov/points/",
          weatherEndpoint: "/forecast",
          timeFormat: 24,
          useBeaufort: true,
          degreeLabel: "false",
          useKmh: false,
          showHumidity: false
        },
        disabled: false
      }

And here is the schema3.json after opening the form:

"weather": [
      {
        "disabled": false,
        "module": "weather",
        "position": "top_right",
        "order": "2",
        "inconfig": "1",
        "config": {
          "weatherProvider": "weathergov",
          "roundTemp": false,
          "type": "forecast",
          "units": "metric",
          "useKmh": false,
          "tempUnits": "metric",
          "windUnits": "mph",
          "updateInterval": 600000,
          "animationSpeed": 1000,
          "timeFormat": 24,
          "showPeriod": true,
          "showPeriodUpper": false,
          "showWindDirection": true,
          "showWindDirectionAsArrow": false,
          "useBeaufort": true,
          "lang": "en",
          "showHumidity": false,
          "showSun": true,
          "degreeLabel": "false",
          "decimalSymbol": ".",
          "showIndoorTemperature": false,
          "showIndoorHumidity": false,
          "maxNumberOfDays": 5,
          "maxEntries": 5,
          "ignoreToday": false,
          "fade": true,
          "fadePoint": 0.25,
          "initialLoadDelay": 0,
          "appendLocationNameToHeader": true,
          "calendarClass": "calendar",
          "tableClass": "small",
          "onlyTemp": false,
          "showPrecipitationAmount": false,
          "colored": false,
          "showFeelsLike": true,
          "lat": *******,
          "lon": *******,
          "apiBase": "https://api.weather.gov/points/",
          "weatherEndpoint": "/forecast"
        },
        "label": "instance 1",
        "index": 0
      }
sdetweil commented 3 months ago

Schema3 has the base values too at the time mm starts.

sdetweil commented 3 months ago

What is the units at the top of config.js Before the modules:[] list

PandaKing185 commented 3 months ago
 var config = {
    address: "0.0.0.0",
    port: 8080,
    basePath: "/",
    language: "en",
    locale: "en-US",
    logLevel: [
      "INFO",
      "LOG",
      "WARN",
      "ERROR"
    ],
    timeFormat: 12,
    units: "imperial",
    zoom: 1,
    useHttps: false,
    ipWhitelist: [],
    modules: [
sdetweil commented 3 months ago

I found the problem, I made a custom form for weather, it copied the defaults as of then… oops. Working on a fix

sdetweil commented 3 months ago

ok, I think I have solved this.. give it a try, git pull to refresh the module code

if you change the default (units:....lang:...) then you have to restart MM to get that as the new default value in the form, just like for the modules that use them

PandaKing185 commented 3 months ago

Yup now it's working! Thanks a bunch

sdetweil commented 3 months ago

Thank you! I never saw that