The gateway configurations are stored in the yombo.ini can be accessed and managed through the configuration library. The configuration library can be referenced from magic attribute as self._Configs. An example of looking up a configuration item within the "core" section:
def somefunction(self): v4ip_address = self._Configs.get('core', 'localipaddress_v4')
- For detailed python interactions and more examples, see: Configuration @ Yombo Python API
- _configuration_delete_ - Called when a configuration has been deleted.
- _configuration_details_ - Provide a description for a configuration variable and is i18n friendly.
- _configuration_set_ - Called when a configuration has been set.
Sections and Options
Configurations relating to each other are grouped into a secion, while an individual configuration is known as an option. For example, all items relating to the web interface are grouped together in the webinterface section.
For complete list of functions, parameters, exceptions raised, returns, and additional examples, see: Configuration @ Yombo Python API
- get(section, option, default, set_if_missing) [doc] [source] - Get a configuration option. This returns a static value of the configuration at the time it's being called.
- get2(section, option, default, set_if_missing) [doc] [source] - Get a callable that always gets the live value. Useful when reading a configuration will be long lived.
- set(section, option, value) [doc] [source] - Sets a configuration value to a given value.
The easiest way to get a configuration item is to simply use the get function or call the library as a dictionary, using two hashes (##) as a seperator between the section and the option being requested:
v4ip_address = self._Configs.get('mqtt', 'server_listen_ip') # is the same as:E v4ip_address = self._Configs('mqtt##server_listen_ip')
If a configuration item will be referenced throughout the life of the runtime of the gateway software, you can get a callable version that will always return the current value. This allows the configuration item to be updated without worry that the module using stale information. **Notice that the function is get2 vs get.** As an additional benefit, a new value can be assigned using the callable.
listen_port = self._Configs.get2('mqtt', 'server_listen_port') print "The current server listen IP address is: %s" % listen_port() # Lets change the port number. listen_port(set=10101)
To set a configuration value, use the set function:
self._Configs.set('mqtt', 'server_listen_port', 10101)