Abstract Base Classes

Config

The Settings Object allows for apps to integrate with settings for blueweather

The settings are very restrictive on what can be used for settings

To create a settings object, place your Settings class in the config.py module

class MySettings(Settings):
    version = 1

    def get_interface(self):
        return {}

    def migrate(self, data, version):
        return data
class blueweather.plugins.apps.config.Settings(app_label: str)

Bases: object

The Settings object that is defined in the AppConfig

Parameters:app_label – label of the app
label

Name of the settings label

get_interface() → dict

Get the settings interface.

The settings interface is a definition of what settings are available to the api and how they should appear on the settings page.

Note

This enforces the given settings. This means that the api will fail if the do not match what is given in the interface.

The interface should be structured as follows (using typescript as a schema language)

interface Choice {
    key: string
    value: string
    enabled?: boolean
}

interface SettingItem {
    name: string,
    type: 'number' | 'select' | 'text' | 'radio' | 'bool'
    default?: string
    enabled?: boolean
    options?: {
        precision?: number
        range?: [number, number]
        hint?: string
        choices?: Array<Choice>
        multiple?: boolean
    }
}

interface Item {
    type: 'divider' | 'header' | 'label' | 'info' | 'setting'
    value: string
}

interface GroupItem {
    type: 'group'
    value: Item | GroupItem
}

interface Interface {
    settings: Array<SettingItem>
    items: Array<Item | GroupItem>
}
Returns:interface
migrate(data: dict, version: int) → dict

Migrate from an old version of the settings to the current version

Parameters:
  • data – the old settings
  • version – the version of the old settings
Returns:

the new migrated settings

ready()

Called when the settings are ready

Parameters:config – config
version

The version of the settings

interface() → dict

The validated settings interface

Returns:validated interface
Raises:marshmallow.ValidationError – if the interface is invalid
config

Get the app’s settings

Returns:settings
blueweather.plugins.apps.config.getSettings(config: django.apps.config.AppConfig) → blueweather.plugins.apps.config.Settings

Get the settings from the config

Parameters:config – app config
Returns:settings

Weather

class blueweather.plugins.apps.weather.Weather

Bases: object

Plugin that Collects the weather data

on_weather_request() → Dict[str, Tuple[str, float]]

Collect the current weather

This should be returned as a dictionary of tuples. Each tuple contains the unit and value in that order:

{
    "temperature": ("c", 25.3),
    "wind_speed": ("m/s", 5.2)
}

While a unit does not need to be a standardized unit, it is important that it is a unit accessable to conversions through the UnitConversion extension. If you choose to use your own custom units, it is important that you make those units convertable by supplying your own conversion extension.

The following list contains units that are garanteed to be convertable

  • temperature: c
  • distance: m
  • mass: kg
  • time: s
  • speed: m/s
  • acceleration: m/s/s
  • force: N
  • pressure: Pa
  • energy: J
  • power: W
  • current: A
  • luminous: cd

Note

units are case-sensitive

Returns:weather data
blueweather.plugins.apps.weather.getWeather(config: django.apps.config.AppConfig) → blueweather.plugins.apps.weather.Weather

Get the weather from the config

Parameters:config – app config
Returns:weather

Conversion

Note

Currently the conversion plugin is disabled. I don’t know if I will continue supporting it in the future.

class blueweather.plugins.apps.conversion.UnitConversion

Bases: object

An Extension that can facilitate conversions

This allows for custom conversion between units.

get_conversion_types() → List[Tuple[str, str]]

Get a list of available conversions in the form of tuples

Each conversion is in the form: from_type -> to_type

Returns:list of conversions
conversion_request(data: float, from_type: str, to_type: str) → float

Convert from one type to another.

When converting values, the first successful conversion will stop

Parameters:
  • data – value in the unit (from_type)
  • from_type – type to convert from
  • to_type – type to convert to
Returns:

converted value (if the conversion is not available, return None)

blueweather.plugins.apps.conversion.getConversions(config: django.apps.config.AppConfig) → List[blueweather.plugins.apps.conversion.UnitConversion]

Get the Conversions from the config

Parameters:config – app config
Returns:list of conversions