WebThingsIO / gateway-addon-python

Python bindings for developing add-ons for WebThings Gateway
Mozilla Public License 2.0
16 stars 10 forks source link

Database is not updating to shorter variable name #53

Closed flatsiedatsie closed 5 years ago

flatsiedatsie commented 5 years ago

I changed the name of a variable in the JSON of the addon. But no matter what I do, it keeps referring to the old variable name.

Here's the add-on json:

{
  "name": "Candle-manager-addon",
  "display_name": "Candle manager",
  "version": "0.0.4",
  "description": "Candle manager allows you to upload sketches to an Arduino.",
  "author": "CreateCandle",
  "main": "bootstrap.py",
  "keywords": [
    "privacy",
    "iot",
    "webthings",
    "mysensors",
    "arduino"
  ],
  "homepage": "https://github.com/createcandle/Candle-manager-addon",
  "license": "MPL-2.0",
  "repository": {
    "type": "git",
    "url": "https://github.com/createcandle/Candle-manager-addon.git"
  },
  "bugs": {
    "url": "https://github.com/createcandle/Candle-manager-addon/issues"
  },
  "files": [
    "LICENSE",
    "SHA256SUMS",
    "bootstrap.py",
    "main.py",
    "pkg/__init__.py",
    "pkg/candle_adapter.py",
    "requirements.txt",
    "boards.txt",
    "arduino-cli",
    "pkg/static/css/main.css",
    "pkg/static/css/wizard.css",
    "pkg/static/js/jquery-3.4.1.min.js",
    "pkg/static/js/main.js",
    "pkg/static/js/wizard.jquery.js",
    "pkg/static/images/candle_logo_simple.png",
    "pkg/templates/index.html",
    "source/Candle_cleaner/Candle_cleaner.ino",
    "code/Candle_cleaner/Candle_cleaner.ino"
  ],
  "moziot": {
    "api": {
      "min": 2,
      "max": 2
    },
    "plugin": true,
    "exec": "python3 {path}/bootstrap.py",
    "config": {
      "Sketches": "https://raw.githubusercontent.com/createcandle/candle_source_code_list/master/candle_source_code_list.json",
      "Password": "changeme",
      "Arduino type": "Arduino Nano",
      "Advanced": false,
      "Debug": false
    },
    "schema": {
      "type": "object",
      "properties": {
        "Password": {
          "type": "string",
          "description": "A password for the security (encryption and/or signing) of the Candle/MySensors network. If you change this you will have to manually re-upload code to all your Candle/MySensors devices."
        },
        "Sketches": {
          "type": "string",
          "description": "Advanced. If you enter the URL of an Arduino sketch (.ino file) it will be downloaded and become available in the sketches list. You can also enter a link to a json file with multiple sketches."
        },
        "Arduino type": {
          "type": "string",
          "enum": [
            "Arduino Nano",
            "Arduino Uno",
            "Arduino Mega"
          ],
          "description": "Advanced. What type of Arduino you will connect? The Candle project works with the Arduino Nano."
        },
        "Advanced": {
          "type": "boolean",
          "description": "Advanced. Show the advanced interface? This will give you extra options and details."
        },
        "Debug": {
          "type": "boolean",
          "description": "Advanced. Enable this to see much more detail in the internal WebThings Gateway log about what this add-on is doing."
        }
      }
    }
  }
}

Here's the config from the database printed as a string:

Loading settings for Candle manager Config: {'Arduino type': 'Arduino Nano', 'Encryption password': 'changeme', 'Debug': False, 'Sketches': 'https://raw.githubusercontent.com/createcandle/candle_source_code_list/master/candle_source_code_list.json'}

I tried updating it so a new version, to see if that would override the value. I tried all kinds of ways of enabling and re-enabling the add-on, changing the configuratino settings. But not matter what I do, I cannot get the new variable "Password" to be stored or retreived. Even though in the settings interface it does say the correct shorter name.

I will not try removing the add-on.

mrstegeman commented 5 years ago

If you change the config object, you have to write code to handle the transition. The only other way to have it changed is to make the user go in and redo their config. There is no way for the gateway to know what your intent was in changing the config object, so it can't be handled automatically.

For an example (in JS), see here: https://github.com/mozilla-iot/gpio-adapter/blob/master/gpio-adapter.js#L253-L285

flatsiedatsie commented 5 years ago

Thanks. I actually found the issue, I was still using the old add-on name in the adapter class. Sorry to waste your time.

mrstegeman commented 5 years ago

No worries! Glad you got it figured out.