"""Tests for scrape component.""" from __future__ import annotations from typing import Any def return_config( select, name, *, attribute=None, index=None, template=None, uom=None, device_class=None, state_class=None, authentication=None, username=None, password=None, headers=None, ) -> dict[str, dict[str, Any]]: """Return config.""" config = { "platform": "scrape", "resource": "https://www.home-assistant.io", "select": select, "name": name, } if attribute: config["attribute"] = attribute if index: config["index"] = index if template: config["value_template"] = template if uom: config["unit_of_measurement"] = uom if device_class: config["device_class"] = device_class if state_class: config["state_class"] = state_class if authentication: config["authentication"] = authentication config["username"] = username config["password"] = password if headers: config["headers"] = headers return config class MockRestData: """Mock RestData.""" def __init__( self, payload, ): """Init RestDataMock.""" self.data: str | None = None self.payload = payload self.count = 0 async def async_update(self, data: bool | None = True) -> None: """Update.""" self.count += 1 if self.payload == "test_scrape_sensor": self.data = ( "
" "

Current Version: 2021.12.10

Released: January 17, 2022" "
" "" ) if self.payload == "test_scrape_uom_and_classes": self.data = ( "
" "

Current Temperature: 22.1

" "
" ) if self.payload == "test_scrape_sensor_authentication": self.data = "
secret text
" if self.payload == "test_scrape_sensor_no_data": self.data = None if self.count == 3: self.data = None