Plugins

ExtensionsSingleton(config[, invoke_on_load]) This is the central manager for all plugins.
dao.Plugin Get Plugin Info
dao.Startup Send messages to plugins on startup
dao.API Get API Configurations from plugins.
dao.Settings Manage plugins’ settings
dao.Weather Get the weather from the weather driver
dao.UnitConversion Convert diffent units of measurement

ExtensionSingleton

class blueweather.plugins.ExtensionsSingleton(config: blueweather.config.Config, invoke_on_load=False)

This is the central manager for all plugins.

There should only exist one ExtensionsSingleton object which will be held in the django settings module.

You can get the django settings from calling

from django.conf import settings
settings.EXTENSIONS
getAllExtensions() → Dict[str, Dict[str, stevedore.extension.Extension]]

Get all extensions

Returns:extensions
getPluginList() → Dict[str, dict]

Get a list of all the plugins

Example of a plugin dict

{
    'human_name': 'Simple Plugin',
    'description': 'Description',
    'author': 'Author',
    'url': 'url',
    'entrypoints': [
        'blueweather.plugins.startup'
    ],
    'builtin': False,
    'enabled': True,
    'disableable': True
}
Returns:a list of plugins
invoke()

Invoke the classes that have been loaded

The act of invoking, initializes the plugin objects and is required for any functionality.

DAO

The DAO is the link between BlueWeather and the plugins.

Plugin

class blueweather.plugins.dao.Plugin

Get Plugin Info

static get_plugin_author(ext: stevedore.extension.Extension) → List[str]

Get the authors of the plugin

Parameters:ext – extension
Returns:plugin authors
static get_plugin_description(ext: stevedore.extension.Extension) → str

Get the human readable description of the plugin

Parameters:ext – extension
Returns:plugin description
static get_plugin_name(ext: stevedore.extension.Extension) → str

Get the human readable name of the plugin

Parameters:ext – extension
Returns:plugin name
static get_plugin_url(ext: stevedore.extension.Extension) → str

Get the url for the plugin

Parameters:ext – extension
Returns:plugin url

Startup

class blueweather.plugins.dao.Startup

Send messages to plugins on startup

static on_startup(man: stevedore.enabled.EnabledExtensionManager)

Send a message to all the plugins that the server has started.

Parameters:man – startup extension manager

API

class blueweather.plugins.dao.API

Get API Configurations from plugins.

static allApiPatterns(man: stevedore.extension.ExtensionManager) → list

Get all the API patterns for each api extension

Parameters:man – API Extension Manager
Returns:list of api patterns
static get_api_urlpatterns(ext: stevedore.extension.Extension) -> (<class 'str'>, <class 'list'>)

Get the API Patterns for an extension

Parameters:ext – extension
Returns:API Patterns

Settings

class blueweather.plugins.dao.Settings

Manage plugins’ settings

static load_settings(man: stevedore.enabled.EnabledExtensionManager, config: blueweather.config.Config)

Load the plugins’ settings from the supplied config

All the plugins’ settings will be processed and loaded into memory.

Note

If any changes were made while loading the settings, config.modified will be set.

Parameters:
  • man – Settings Extension Manager
  • config – configuration
static on_settings_initialized(ext: stevedore.extension.Extension)

Send a message to the extension that the settings have been initialized

Parameters:ext – extension
static settings_deserialize(ext: stevedore.extension.Extension, settings: dict)

Deserialize the settings of an extension.

Parameters:
  • ext – extension
  • settings – saved settings
static settings_migrate(ext: stevedore.extension.Extension, settings: dict) → dict

Migrate the settings of the extension

Parameters:
  • ext – extension
  • settings – saved settings
Returns:

migrated settings

static settings_serialize(ext: stevedore.extension.Extension, settings: dict) → dict

Serialize an extension’s settings

This serializes the extensions local settings, and returns it

Parameters:
  • ext – extension
  • setings – saved settings
Returns:

serialized settings

static unload_settings(man: stevedore.enabled.EnabledExtensionManager, config: blueweather.config.Config)

Unload the plugins’ settings to the supplied config.

The settings stored in memory will be processed and dumped into the supplied config.

Parameters:
  • man – Settings Extension Manager
  • config – configuration

Weather

class blueweather.plugins.dao.Weather

Get the weather from the weather driver

static on_weather_request(ext: stevedore.extension.Extension) → dict

request the weather from the weather driver

Parameters:ext – driver
Returns:weather data

UnitConversion

class blueweather.plugins.dao.UnitConversion

Convert diffent units of measurement

static all_conversions(man: stevedore.dispatch.DispatchExtensionManager = None, units: Dict[str, Set[str]] = None) → Dict[str, Set[str]]

Get all the possible conversions

This finds all the possible conversions by using recursive conversions

Parameters:
  • man – UnitConversion Extension Manager
  • units – All the basic conversions
Returns:

All the possible conversions

static conversions(man: stevedore.dispatch.DispatchExtensionManager) → Dict[str, Set[str]]

Get all the basic conversions

Parameters:man – UnitConversion Extension Manager
Returns:Possible Conversions
static convert(man: stevedore.dispatch.DispatchExtensionManager, data: float, from_type: str, to_type: str) → Tuple[List[str], float]

Convert from one type to another

Parameters:
  • man – UnitConversion Extension Manager
  • data – value to convert from
  • from_type – type to convert from
  • to_type – type to convert to
Returns:

name(s) of the extensions that performed the conversion, and the converted value

static get_conversion_types(ext: stevedore.extension.Extension) → Tuple[str, List[Tuple[str, str]]]

Get the types that an extension can convert

Parameters:ext – extension
Returns:extension name, and possible conversions
static on_request_conversion_check(ext: stevedore.extension.Extension, data: float, from_type: str, to_type: str) → bool

Check if a conversion can be performed

Parameters:
  • ext – extension
  • data – value to convert from
  • from_type – type to convert from
  • to_type – type to convert to
Returns:

True if the conversion is possible

static request_conversion(ext: stevedore.extension.Extension, data: float, from_type: str, to_type: str) -> (<class 'str'>, <class 'float'>)

Request a conversion to be made

Parameters:
  • ext – extension
  • data – value to convert from
  • from_type – type to convert from
  • to_type – type to convert to
Returns:

the name of the extension, and the converted value