Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework of configuration handling (preparation for config ui) #1184

Closed
wants to merge 1 commit into from

Conversation

bboehmke
Copy link
Contributor

@bboehmke bboehmke commented Jun 29, 2021

This change reworks the way the configuration is loaded.
The changes are based on the feature/config-basics branch with a different approach to handle the individual entries (currently only meters).

The main focus is based on:

  • reduce of duplicated code (no util.DecodeOther to struct in every device)
  • reduced complexity (no decorator required anymore)
  • define config field metadata via struct tags (defaults, validation, description, ...) see example here

This changes also contains a web API to get the possible value types:

http://127.0.0.1:7070/api/config/types/meter
[
  {
   "name": "modbus",
   "label": "ModBus",
   "fields": [
    {
     "name": "ID",
     "type": "uint8",
     "required": true,
     "label": "ID",
     "default": "1"
    },
    {
     "name": "SubDevice",
     "type": "int",
     "label": "SubDevice"
    },
    {
     "name": "URI",
     "type": "string",
     "label": "URI"
    },
    {
     "name": "Device",
     "type": "string",
     "label": "Device"
    },
    {
     "name": "Comset",
     "type": "string",
     "label": "Comset",
     "enum": [
      "8E1",
      "8N1"
     ]
    },
    {
     "name": "Baudrate",
     "type": "int",
     "label": "Baudrate"
    },
    {
     "name": "RTU",
     "type": "bool",
     "label": "RTU"
    },
    {
     "name": "Model",
     "type": "string",
     "label": "Model"
    },
    {
     "name": "Power",
     "type": "string",
     "label": "Power",
     "default": "Power"
    },
    {
     "name": "Energy",
     "type": "string",
     "label": "Energy"
    },
    {
     "name": "SoCConf",
     "type": "string",
     "label": "SoCConf"
    },
    {
     "name": "Timeout",
     "type": "duration",
     "label": "Timeout"
    }
   ]
  },
  {
   "name": "openwb",
   "label": "openWB",
   "fields": [
    {
     "name": "Broker",
     "type": "string",
     "required": true,
     "label": "Broker"
    },
    {
     "name": "User",
     "type": "string",
     "label": "User"
    },
    {
     "name": "Password",
     "type": "string",
     "label": "Password"
    },
    {
     "name": "ClientID",
     "type": "string",
     "label": "ClientID"
    },
    {
     "name": "Topic",
     "type": "string",
     "label": "Topic",
     "default": "openWB"
    },
    {
     "name": "Timeout",
     "type": "duration",
     "label": "Timeout",
     "default": "15s"
    },
    {
     "name": "Usage",
     "type": "string",
     "required": true,
     "label": "Usage",
     "enum": [
      "grid",
      "pv",
      "battery"
     ]
    }
   ]
  },
  {
   "name": "sma",
   "label": "SMA/Speedwire device (Home Manager/Energy Meter/Inverter)",
   "fields": [
    {
     "name": "URI",
     "type": "string",
     "label": "URI"
    },
    {
     "name": "Interface",
     "type": "string",
     "label": "Name of network interface device is connected to"
    },
    {
     "name": "Password",
     "type": "password",
     "label": "Password",
     "default": "0000"
    },
    {
     "name": "Serial",
     "type": "uint32",
     "label": "Serial"
    },
    {
     "name": "Power",
     "type": "string",
     "hidden": true,
     "label": "Power"
    },
    {
     "name": "Energy",
     "type": "string",
     "hidden": true,
     "label": "Energy"
    },
    {
     "name": "Scale",
     "type": "float64",
     "label": "Scale",
     "default": "1"
    }
   ]
  },
  {
   "name": "tesla",
   "label": "Tesla Powerwall",
   "fields": [
    {
     "name": "URI",
     "type": "string",
     "required": true,
     "label": "URI"
    },
    {
     "name": "Usage",
     "type": "string",
     "required": true,
     "label": "Usage",
     "enum": [
      "grid",
      "pv",
      "battery"
     ]
    },
    {
     "name": "Password",
     "type": "string",
     "required": true,
     "label": "Password"
    }
   ]
  },
  {
   "name": "discovergy",
   "label": "Discovergy",
   "fields": [
    {
     "name": "User",
     "type": "string",
     "required": true,
     "label": "User"
    },
    {
     "name": "Password",
     "type": "string",
     "required": true,
     "label": "Password"
    },
    {
     "name": "Meter",
     "type": "string",
     "label": "Meter"
    },
    {
     "name": "Scale",
     "type": "float64",
     "label": "Scale",
     "default": "1"
    }
   ]
  },
  {
   "name": "default",
   "label": "Generic configurable Meter",
   "fields": [
    {
     "name": "Power",
     "type": "plugin",
     "required": true,
     "label": "Power"
    },
    {
     "name": "Energy",
     "type": "plugin",
     "label": "Energy"
    },
    {
     "name": "CurrentsConf",
     "type": "[]plugin",
     "label": "CurrentsConf"
    },
    {
     "name": "SoCConf",
     "type": "plugin",
     "label": "SoCConf"
    }
   ]
  },
  {
   "name": "custom",
   "label": "Generic configurable Meter",
   "fields": [
    {
     "name": "Power",
     "type": "plugin",
     "required": true,
     "label": "Power"
    },
    {
     "name": "Energy",
     "type": "plugin",
     "label": "Energy"
    },
    {
     "name": "CurrentsConf",
     "type": "[]plugin",
     "label": "CurrentsConf"
    },
    {
     "name": "SoCConf",
     "type": "plugin",
     "label": "SoCConf"
    }
   ]
  }
 ]

TODO:

  • Missing objects (charger, vehicles, plugins, ...)
  • More meta data (descriptions, validation, ...)

Not Part of this change (done in separate PRs)

  • i18n/internationalization
  • web ui of config

@bboehmke bboehmke force-pushed the config_rework branch 2 times, most recently from 0e3de77 to ac114ca Compare June 29, 2021 15:47
@andig
Copy link
Member

andig commented Jul 24, 2021

Ich schließe hier mal fürs erste als wontfix wie besprochen. Das Thema nehmen wir später wieder auf.

@andig andig closed this Jul 24, 2021
@andig andig added the wontfix This will not be worked on label Jul 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants