"""Bundled dashboard: weather."""
import json


def register(ctx):
    from dashboard_bundled.feeds import feed_weather

    ctx.register_dashboard_tile(
        {
            "id": "weather",
            "title": "Forecast",
            "path": "/tile",
            "refresh_seconds": 1200,
            "priority": 1,
        }
    )

    def route_handler(req):
        body = json.dumps(feed_weather(), ensure_ascii=False)
        return {
            "status": 200,
            "headers": {"Content-Type": "application/json; charset=utf-8"},
            "body": body,
        }

    ctx.register_route_handler(route_handler)
