"""The tests for the Template Weather platform.""" import pytest from homeassistant.components.weather import ( ATTR_WEATHER_HUMIDITY, ATTR_WEATHER_OZONE, ATTR_WEATHER_PRESSURE, ATTR_WEATHER_TEMPERATURE, ATTR_WEATHER_VISIBILITY, ATTR_WEATHER_WIND_BEARING, ATTR_WEATHER_WIND_SPEED, DOMAIN, ) from homeassistant.const import ATTR_ATTRIBUTION @pytest.mark.parametrize("count,domain", [(1, DOMAIN)]) @pytest.mark.parametrize( "config", [ { "weather": [ {"weather": {"platform": "demo"}}, { "platform": "template", "name": "test", "attribution_template": "{{ states('sensor.attribution') }}", "condition_template": "sunny", "forecast_template": "{{ states.weather.demo.attributes.forecast }}", "temperature_template": "{{ states('sensor.temperature') | float }}", "humidity_template": "{{ states('sensor.humidity') | int }}", "pressure_template": "{{ states('sensor.pressure') }}", "wind_speed_template": "{{ states('sensor.windspeed') }}", "wind_bearing_template": "{{ states('sensor.windbearing') }}", "ozone_template": "{{ states('sensor.ozone') }}", "visibility_template": "{{ states('sensor.visibility') }}", }, ] }, ], ) async def test_template_state_text(hass, start_ha): """Test the state text of a template.""" for attr, v_attr, value in [ ( "sensor.attribution", ATTR_ATTRIBUTION, "The custom attribution", ), ("sensor.temperature", ATTR_WEATHER_TEMPERATURE, 22.3), ("sensor.humidity", ATTR_WEATHER_HUMIDITY, 60), ("sensor.pressure", ATTR_WEATHER_PRESSURE, 1000), ("sensor.windspeed", ATTR_WEATHER_WIND_SPEED, 20), ("sensor.windbearing", ATTR_WEATHER_WIND_BEARING, 180), ("sensor.ozone", ATTR_WEATHER_OZONE, 25), ("sensor.visibility", ATTR_WEATHER_VISIBILITY, 4.6), ]: hass.states.async_set(attr, value) await hass.async_block_till_done() state = hass.states.get("weather.test") assert state is not None assert state.state == "sunny" assert state.attributes.get(v_attr) == value