import requests from flask import render_template_string class Platform: def docs(self): documentation = { "name": "weather", "author": "RMountjoy", "author_url": "https://github.com/rmountjoy92", "version": 1.0, "description": "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 https://www.metaweather.com", "example": """ ```ini [variable_name] platform = weather woeid = 2514815 [custom_card_name] type = custom data_sources = variable_name ``` """, "returns": "HTML for custom card", "variables": [ { "variable": "[variable_name]", "description": "Name for the data source.", "default": "", "options": ".ini header", }, { "variable": "platform", "description": "Name of the platform.", "default": "weather", "options": "weather", }, { "variable": "woeid", "description": "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", "default": "2514815", "options": "woeid", }, { "variable": "temp_unit", "description": "The unit to be used for temperature", "default": "c", "options": "c,f", }, { "variable": "wind_speed_unit", "description": "The unit to be used for wind speed", "default": "kph", "options": "kph,mph", }, { "variable": "air_pressure_unit", "description": "The unit to be used for air pressure", "default": "mbar", "options": "mbar,inHg", }, { "variable": "visibility_unit", "description": "The unit to be used for visibility", "default": "km", "options": "km,mi", }, ], } return documentation 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 = "mbar" if not hasattr(self, "visibility_unit"): self.visibility_unit = "km" self.html_template = """