Add setup type hints to season (#63798)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
01baa20671
commit
505320f827
2 changed files with 16 additions and 14 deletions
|
@ -1,14 +1,18 @@
|
||||||
"""Support for tracking which astronomical or meteorological season it is."""
|
"""Support for tracking which astronomical or meteorological season it is."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import ephem
|
import ephem
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import util
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||||
from homeassistant.const import CONF_NAME, CONF_TYPE
|
from homeassistant.const import CONF_NAME, CONF_TYPE
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -53,19 +57,19 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config: ConfigType,
|
||||||
|
add_entities: AddEntitiesCallback,
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> None:
|
||||||
"""Display the current season."""
|
"""Display the current season."""
|
||||||
if None in (hass.config.latitude, hass.config.longitude):
|
|
||||||
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
|
|
||||||
return False
|
|
||||||
|
|
||||||
latitude = util.convert(hass.config.latitude, float)
|
|
||||||
_type = config.get(CONF_TYPE)
|
_type = config.get(CONF_TYPE)
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
|
|
||||||
if latitude < 0:
|
if hass.config.latitude < 0:
|
||||||
hemisphere = SOUTHERN
|
hemisphere = SOUTHERN
|
||||||
elif latitude > 0:
|
elif hass.config.latitude > 0:
|
||||||
hemisphere = NORTHERN
|
hemisphere = NORTHERN
|
||||||
else:
|
else:
|
||||||
hemisphere = EQUATOR
|
hemisphere = EQUATOR
|
||||||
|
@ -73,8 +77,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
_LOGGER.debug(_type)
|
_LOGGER.debug(_type)
|
||||||
add_entities([Season(hass, hemisphere, _type, name)], True)
|
add_entities([Season(hass, hemisphere, _type, name)], True)
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def get_season(date, hemisphere, season_tracking_type):
|
def get_season(date, hemisphere, season_tracking_type):
|
||||||
"""Calculate the current season."""
|
"""Calculate the current season."""
|
||||||
|
|
|
@ -16,17 +16,17 @@ from homeassistant.const import STATE_UNKNOWN
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
HEMISPHERE_NORTHERN = {
|
HEMISPHERE_NORTHERN = {
|
||||||
"homeassistant": {"latitude": "48.864716", "longitude": "2.349014"},
|
"homeassistant": {"latitude": 48.864716, "longitude": 2.349014},
|
||||||
"sensor": {"platform": "season", "type": "astronomical"},
|
"sensor": {"platform": "season", "type": "astronomical"},
|
||||||
}
|
}
|
||||||
|
|
||||||
HEMISPHERE_SOUTHERN = {
|
HEMISPHERE_SOUTHERN = {
|
||||||
"homeassistant": {"latitude": "-33.918861", "longitude": "18.423300"},
|
"homeassistant": {"latitude": -33.918861, "longitude": 18.423300},
|
||||||
"sensor": {"platform": "season", "type": "astronomical"},
|
"sensor": {"platform": "season", "type": "astronomical"},
|
||||||
}
|
}
|
||||||
|
|
||||||
HEMISPHERE_EQUATOR = {
|
HEMISPHERE_EQUATOR = {
|
||||||
"homeassistant": {"latitude": "0", "longitude": "-51.065100"},
|
"homeassistant": {"latitude": 0, "longitude": -51.065100},
|
||||||
"sensor": {"platform": "season", "type": "astronomical"},
|
"sensor": {"platform": "season", "type": "astronomical"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue