""" ##### Weather Weather is a great example of how you can populate a custom card on the dash. This plugin creates a custom card with weather data from [metaweather.com](https://www.metaweather.com) ```ini [variable_name] platform = weather woeid = 2514815 temp_unit = c wind_speed_unit = kph air_pressure_unit = mbar visibility_unit = km ``` > **Returns:** HTML for custom card | Variable | Required | Description | Options | |-----------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------|-------------------| | [variable_name] | Yes | Name for the data source. | [variable_name] | | platform | Yes | Name of the platform. | weather | | woeid | Yes | woeid of location to use. Go here to get (replace lat and long): https://www.metaweather.com/api/location/search/?lattlong=50.068,-5.316 | url | | temp_unit | No | The unit to be used for temperature | c,f | | wind_speed_unit | No | The unit to be used for wind speed | kph,mph | | air_pressure_unit | No | The unit to be used for air pressure | mbar, inHg | | visibility_unit | No | The unit to be used for visibility | km,mi | > **Working example:** >```ini >[variable_name] >platform = weather >woeid = 2514815 > >[custom_card_name] >type = custom >data_sources = variable_name >``` """ import requests from flask import render_template_string class Platform: def __init__(self, *args, **kwargs): # parse the user's options from the config entries for key, value in kwargs.items(): self.__dict__[key] = value # set defaults for omitted options if not hasattr(self, "woeid"): self.woeid = 2514815 if not hasattr(self, "temp_unit"): self.temp_unit = "c" if not hasattr(self, "wind_speed_unit"): self.wind_speed_unit = "kph" if not hasattr(self, "air_pressure_unit"): self.air_pressure_unit = "x" if not hasattr(self, "visibility_unit"): self.visibility_unit = "km" self.html_template = """