mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Add name option to season sensor (#29302)
* Add name option to season sensor * Changed DEFAULT_NAME from season to Season
This commit is contained in:
parent
3f2b6bfaa4
commit
b28bc1d6fb
@ -7,12 +7,15 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant import util
|
from homeassistant import util
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import CONF_TYPE
|
from homeassistant.const import CONF_NAME, CONF_TYPE
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DEFAULT_NAME = "Season"
|
||||||
|
|
||||||
EQUATOR = "equator"
|
EQUATOR = "equator"
|
||||||
|
|
||||||
NORTHERN = "northern"
|
NORTHERN = "northern"
|
||||||
@ -44,7 +47,10 @@ SEASON_ICONS = {
|
|||||||
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
{vol.Optional(CONF_TYPE, default=TYPE_ASTRONOMICAL): vol.In(VALID_TYPES)}
|
{
|
||||||
|
vol.Optional(CONF_TYPE, default=TYPE_ASTRONOMICAL): vol.In(VALID_TYPES),
|
||||||
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -56,6 +62,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
latitude = util.convert(hass.config.latitude, float)
|
latitude = util.convert(hass.config.latitude, float)
|
||||||
_type = config.get(CONF_TYPE)
|
_type = config.get(CONF_TYPE)
|
||||||
|
name = config.get(CONF_NAME)
|
||||||
|
|
||||||
if latitude < 0:
|
if latitude < 0:
|
||||||
hemisphere = SOUTHERN
|
hemisphere = SOUTHERN
|
||||||
@ -65,7 +72,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
hemisphere = EQUATOR
|
hemisphere = EQUATOR
|
||||||
|
|
||||||
_LOGGER.debug(_type)
|
_LOGGER.debug(_type)
|
||||||
add_entities([Season(hass, hemisphere, _type)])
|
add_entities([Season(hass, hemisphere, _type, name)])
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -105,9 +112,10 @@ def get_season(date, hemisphere, season_tracking_type):
|
|||||||
class Season(Entity):
|
class Season(Entity):
|
||||||
"""Representation of the current season."""
|
"""Representation of the current season."""
|
||||||
|
|
||||||
def __init__(self, hass, hemisphere, season_tracking_type):
|
def __init__(self, hass, hemisphere, season_tracking_type, name):
|
||||||
"""Initialize the season."""
|
"""Initialize the season."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
|
self._name = name
|
||||||
self.hemisphere = hemisphere
|
self.hemisphere = hemisphere
|
||||||
self.datetime = dt_util.utcnow().replace(tzinfo=None)
|
self.datetime = dt_util.utcnow().replace(tzinfo=None)
|
||||||
self.type = season_tracking_type
|
self.type = season_tracking_type
|
||||||
@ -116,7 +124,7 @@ class Season(Entity):
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name."""
|
"""Return the name."""
|
||||||
return "Season"
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user