Add rss_feed_template to strict-typing (#86528)

Add rss_feed_template to strict-typing
This commit is contained in:
Marc Mueller
2023-01-24 19:06:24 +01:00
committed by GitHub
parent 4b88a71d60
commit 90fc8dd860
3 changed files with 25 additions and 8 deletions

View File

@ -251,6 +251,7 @@ homeassistant.components.ridwell.*
homeassistant.components.rituals_perfume_genie.*
homeassistant.components.roku.*
homeassistant.components.rpi_power.*
homeassistant.components.rss_feed_template.*
homeassistant.components.rtsp_to_webrtc.*
homeassistant.components.ruuvi_gateway.*
homeassistant.components.ruuvitag_ble.*

View File

@ -1,4 +1,6 @@
"""Support to export sensor values via RSS feed."""
from __future__ import annotations
from html import escape
from aiohttp import web
@ -7,6 +9,7 @@ import voluptuous as vol
from homeassistant.components.http import HomeAssistantView
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.template import Template
from homeassistant.helpers.typing import ConfigType
CONTENT_TYPE_XML = "text/xml"
@ -43,12 +46,13 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
for (feeduri, feedconfig) in config[DOMAIN].items():
url = f"/api/rss_template/{feeduri}"
requires_auth = feedconfig.get("requires_api_password")
requires_auth: bool = feedconfig["requires_api_password"]
title: Template | None
if (title := feedconfig.get("title")) is not None:
title.hass = hass
items = feedconfig.get("items")
items: list[dict[str, Template]] = feedconfig["items"]
for item in items:
if "title" in item:
item["title"].hass = hass
@ -64,20 +68,22 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
class RssView(HomeAssistantView):
"""Export states and other values as RSS."""
requires_auth = True
url = None
name = "rss_template"
_title = None
_items = None
def __init__(self, url, requires_auth, title, items):
def __init__(
self,
url: str,
requires_auth: bool,
title: Template | None,
items: list[dict[str, Template]],
) -> None:
"""Initialize the rss view."""
self.url = url
self.requires_auth = requires_auth
self._title = title
self._items = items
async def get(self, request, entity_id=None):
async def get(self, request: web.Request) -> web.Response:
"""Generate the RSS view XML."""
response = '<?xml version="1.0" encoding="utf-8"?>\n\n'

View File

@ -2264,6 +2264,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.rss_feed_template.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.rtsp_to_webrtc.*]
check_untyped_defs = true
disallow_incomplete_defs = true