weather.openweathermap#

Description#

OpenWeatherMap plugin.

You’ll need an API token from OpenWeatherMap in order to use this API.

Configuration#

weather.openweathermap:
  # [Required]
  # OpenWeatherMap API token.
  token:   # type=str

  # [Optional]
  # If set, then this location will be used by default for
  # weather lookup. If multiple locations share the same name you can
  # disambiguate by specifying the country code as well - e.g.
  # ``London,GB``.
  # location:   # type=Optional[str]

  # [Optional]
  # If set, then this city ID will be used by default for
  # weather lookup. The full list of city IDs is available `here
  # <https://bulk.openweathermap.org/sample/>`_.
  # city_id:   # type=Optional[int]

  # [Optional]
  # If lat/long are set, then the weather by default will be
  # retrieved for the specified geo location.
  # lat:   # type=Optional[float]

  # [Optional]
  # If lat/long are set, then the weather by default will be
  # retrieved for the specified geo location.
  # long:   # type=Optional[float]

  # [Optional]
  # If set, then this ZIP code (should be in the form
  # ``zip,country_code``) will be used by default for weather lookup.
  # zip_code:   # type=Optional[str]

  # [Optional]
  # Supported: ``metric`` (default), ``standard`` and
  # ``imperial``.
  # units: metric  # type=str

  # [Optional]
  # Language code for the weather description (default: en).
  # lang:   # type=Optional[str]

  # [Optional]
  # How often the `WeatherPlugin.loop <https://docs.platypush.tech/platypush/plugins/weather.html#platypush.plugins.weather.WeatherPlugin.loop>`_ function should be
  # executed (default: 15 seconds). *NOTE*: For back-compatibility
  # reasons, the `poll_seconds` argument is also supported, but it's
  # deprecated.
  # poll_interval: 120  # type=Optional[float]

  # [Optional]
  # How long we should wait for any running
  # threads/processes to stop before exiting (default: 5 seconds).
  # stop_timeout: 5  # type=Optional[float]

  # [Optional]
  # If set to True then the plugin will not monitor
  # for new events. This is useful if you want to run a plugin in
  # stateless mode and only leverage its actions, without triggering any
  # events. Defaults to False.
  # disable_monitor: False  # type=bool

Triggered events#

Actions#

Module reference#

class platypush.plugins.weather.openweathermap.WeatherOpenweathermapPlugin(*_, **__)[source]#

Bases: WeatherPlugin

OpenWeatherMap plugin.

You’ll need an API token from OpenWeatherMap in order to use this API.

__init__(token: str, location: str | None = None, city_id: int | None = None, lat: float | None = None, long: float | None = None, zip_code: str | None = None, units: str = 'metric', lang: str | None = None, **kwargs)[source]#
Parameters:
  • token – OpenWeatherMap API token.

  • location – If set, then this location will be used by default for weather lookup. If multiple locations share the same name you can disambiguate by specifying the country code as well - e.g. London,GB.

  • city_id – If set, then this city ID will be used by default for weather lookup. The full list of city IDs is available here.

  • lat – If lat/long are set, then the weather by default will be retrieved for the specified geo location.

  • long – If lat/long are set, then the weather by default will be retrieved for the specified geo location.

  • zip_code – If set, then this ZIP code (should be in the form zip,country_code) will be used by default for weather lookup.

  • units – Supported: metric (default), standard and imperial.

  • lang – Language code for the weather description (default: en).

get_current_weather(*args, lat: float | None = None, long: float | None = None, units: str | None = None, **kwargs) dict#

Returns the current weather.

Parameters:
  • lat – Override the lat configuration value.

  • long – Override the long configuration value.

  • units – Override the units configuration value.

Returns:

{
  "apparent_temperature": 9.0,
  "cloud_cover": 0.5,
  "humidity": 30,
  "icon": "cloudy",
  "precip_intensity": "Intensity of the precipitation",
  "precip_type": "rain",
  "pressure": 1000.0,
  "summary": "Cloudy",
  "sunrise": "2020-01-01T06:00:00+00:00",
  "sunset": "2020-01-01T18:00:00+00:00",
  "temperature": 10.0,
  "time": "2020-01-01T12:00:00+00:00",
  "units": "metric",
  "visibility": 2000.0,
  "wind_direction": 180.0,
  "wind_gust": 15.0,
  "wind_speed": 10.0
}

get_forecast(*args, lat: float | None = None, long: float | None = None, units: str | None = None, **kwargs) List[dict]#

Returns the weather forecast for the upcoming hours/days.

Parameters:
  • lat – Override the lat configuration value.

  • long – Override the long configuration value.

  • units – Override the units configuration value.

Returns:

[
  {
    "apparent_temperature": 9.0,
    "cloud_cover": 0.5,
    "humidity": 30,
    "icon": "cloudy",
    "precip_intensity": "Intensity of the precipitation",
    "precip_type": "rain",
    "pressure": 1000.0,
    "summary": "Cloudy",
    "sunrise": "2020-01-01T06:00:00+00:00",
    "sunset": "2020-01-01T18:00:00+00:00",
    "temperature": 10.0,
    "time": "2020-01-01T12:00:00+00:00",
    "units": "metric",
    "visibility": 2000.0,
    "wind_direction": 180.0,
    "wind_gust": 15.0,
    "wind_speed": 10.0
  }
]

main()#

Implementation of the main loop of the plugin.

publish_entities(entities: Collection[Any] | None, callback: Callable[[Entity], Any] | None = None, **kwargs) Collection[Entity]#

Publishes a list of entities. The downstream consumers include:

It also accepts an optional callback that will be called when each of the entities in the set is flushed to the database.

You usually don’t need to override this class (but you may want to extend transform_entities() instead if your extension doesn’t natively handle Entity objects).

start()#

Start the plugin.

status(*args, **kwargs) dict#
Returns:

{
  "current": {
    "apparent_temperature": 9.0,
    "cloud_cover": 0.5,
    "humidity": 30,
    "icon": "cloudy",
    "precip_intensity": "Intensity of the precipitation",
    "precip_type": "rain",
    "pressure": 1000.0,
    "summary": "Cloudy",
    "sunrise": "2020-01-01T06:00:00+00:00",
    "sunset": "2020-01-01T18:00:00+00:00",
    "temperature": 10.0,
    "time": "2020-01-01T12:00:00+00:00",
    "units": "metric",
    "visibility": 2000.0,
    "wind_direction": 180.0,
    "wind_gust": 15.0,
    "wind_speed": 10.0
  },
  "forecast": [
    {
      "apparent_temperature": 9.0,
      "cloud_cover": 0.5,
      "humidity": 30,
      "icon": "cloudy",
      "precip_intensity": "Intensity of the precipitation",
      "precip_type": "rain",
      "pressure": 1000.0,
      "summary": "Cloudy",
      "sunrise": "2020-01-01T06:00:00+00:00",
      "sunset": "2020-01-01T18:00:00+00:00",
      "temperature": 10.0,
      "time": "2020-01-01T12:00:00+00:00",
      "units": "metric",
      "visibility": 2000.0,
      "wind_direction": 180.0,
      "wind_gust": 15.0,
      "wind_speed": 10.0
    }
  ]
}

stop()#

Stop the plugin.

transform_entities(entities: List[dict], *, type: str)#

This method takes a list of entities in any (plugin-specific) format and converts them into a standardized collection of Entity objects. Since this method is called by publish_entities() before entity updates are published, you may usually want to extend it to pre-process the entities managed by your extension into the standard format before they are stored and published to all the consumers.

wait_stop(timeout=None)#

Wait until a stop event is received.