mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Improve AccuWeather type annotations (#50616)
* Improve type annotations * Remove unused argument * Simplify state logic * Fix uvindex state * Fix type for logger * Increase tests coverage * Fix pylint arguments-differ error * Suggested change * Suggested change * Remove unnecessary variable * Remove unnecessary conditions * Use int instead of list for forecast days * Add enabled to sensor types dicts * Fix request_remaining conversion and tests * Run hassfest * Suggested change * Suggested change * Do not use StateType
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""Test sensor of AccuWeather integration."""
|
||||
from datetime import timedelta
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import PropertyMock, patch
|
||||
|
||||
from homeassistant.components.accuweather.const import ATTRIBUTION, DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
@@ -13,6 +13,7 @@ from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONCENTRATION_PARTS_PER_CUBIC_METER,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
LENGTH_FEET,
|
||||
LENGTH_METERS,
|
||||
LENGTH_MILLIMETERS,
|
||||
PERCENTAGE,
|
||||
@@ -25,6 +26,7 @@ from homeassistant.const import (
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from tests.common import async_fire_time_changed, load_fixture
|
||||
from tests.components.accuweather import init_integration
|
||||
@@ -616,6 +618,10 @@ async def test_availability(hass):
|
||||
return_value=json.loads(
|
||||
load_fixture("accuweather/current_conditions_data.json")
|
||||
),
|
||||
), patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.requests_remaining",
|
||||
new_callable=PropertyMock,
|
||||
return_value=10,
|
||||
):
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.async_block_till_done()
|
||||
@@ -641,7 +647,11 @@ async def test_manual_update_entity(hass):
|
||||
) as mock_current, patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.async_get_forecast",
|
||||
return_value=forecast,
|
||||
) as mock_forecast:
|
||||
) as mock_forecast, patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.requests_remaining",
|
||||
new_callable=PropertyMock,
|
||||
return_value=10,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
"homeassistant",
|
||||
"update_entity",
|
||||
@@ -650,3 +660,16 @@ async def test_manual_update_entity(hass):
|
||||
)
|
||||
assert mock_current.call_count == 1
|
||||
assert mock_forecast.call_count == 1
|
||||
|
||||
|
||||
async def test_sensor_imperial_units(hass):
|
||||
"""Test states of the sensor without forecast."""
|
||||
hass.config.units = IMPERIAL_SYSTEM
|
||||
await init_integration(hass)
|
||||
|
||||
state = hass.states.get("sensor.home_cloud_ceiling")
|
||||
assert state
|
||||
assert state.state == "10500"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-fog"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == LENGTH_FEET
|
||||
|
||||
Reference in New Issue
Block a user