mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Improvement typing core (#2624)
* Add package typing * Add util/location typing * FIX: lint wrong order of imports * Fix sometyping and add helpers/entity typing * Mypy import trick * Add asteroid to test requiremts to fix pylint issue * Fix deprecated function isSet for is_set * Add loader.py typing * Improve typing bootstrap
This commit is contained in:
committed by
Paulus Schoutsen
parent
8c728d1b4e
commit
ae97218582
@@ -5,8 +5,11 @@ detect_location_info and elevation are mocked by default during tests.
|
||||
"""
|
||||
import collections
|
||||
import math
|
||||
from typing import Any, Optional, Tuple, Dict
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
ELEVATION_URL = 'http://maps.googleapis.com/maps/api/elevation/json'
|
||||
FREEGEO_API = 'https://freegeoip.io/json/'
|
||||
IP_API = 'http://ip-api.com/json'
|
||||
@@ -81,7 +84,8 @@ def elevation(latitude, longitude):
|
||||
# Source: https://github.com/maurycyp/vincenty
|
||||
# License: https://github.com/maurycyp/vincenty/blob/master/LICENSE
|
||||
# pylint: disable=too-many-locals, invalid-name, unused-variable
|
||||
def vincenty(point1, point2, miles=False):
|
||||
def vincenty(point1: Tuple[float, float], point2: Tuple[float, float],
|
||||
miles: bool=False) -> Optional[float]:
|
||||
"""
|
||||
Vincenty formula (inverse method) to calculate the distance.
|
||||
|
||||
@@ -148,7 +152,7 @@ def vincenty(point1, point2, miles=False):
|
||||
return round(s, 6)
|
||||
|
||||
|
||||
def _get_freegeoip():
|
||||
def _get_freegeoip() -> Optional[Dict[str, Any]]:
|
||||
"""Query freegeoip.io for location data."""
|
||||
try:
|
||||
raw_info = requests.get(FREEGEO_API, timeout=5).json()
|
||||
@@ -169,7 +173,7 @@ def _get_freegeoip():
|
||||
}
|
||||
|
||||
|
||||
def _get_ip_api():
|
||||
def _get_ip_api() -> Optional[Dict[str, Any]]:
|
||||
"""Query ip-api.com for location data."""
|
||||
try:
|
||||
raw_info = requests.get(IP_API, timeout=5).json()
|
||||
|
||||
Reference in New Issue
Block a user