8000 Add name option to season sensor by springstan · Pull Request #29302 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add name option to season sensor #29302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions homeassistant/components/season/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

from homeassistant import util
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
import homeassistant.util.dt as dt_util

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = "Season"

EQUATOR = "equator"

NORTHERN = "northern"
Expand Down Expand Up @@ -44,7 +47,10 @@


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,
}
)


Expand All @@ -56,6 +62,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):

latitude = util.convert(hass.config.latitude, float)
_type = config.get(CONF_TYPE)
name = config.get(CONF_NAME)

if latitude < 0:
hemisphere = SOUTHERN
Expand All @@ -65,7 +72,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
hemisphere = EQUATOR

_LOGGER.debug(_type)
add_entities([Season(hass, hemisphere, _type)])
add_entities([Season(hass, hemisphere, _type, name)])

return True

Expand Down Expand Up @@ -105,9 +112,10 @@ def get_season(date, hemisphere, season_tracking_type):
class Season(Entity):
"""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."""
self.hass = hass
self._name = name
self.hemisphere = hemisphere
self.datetime = dt_util.utcnow().replace(tzinfo=None)
self.type = season_tracking_type
Expand All @@ -116,7 +124,7 @@ def __init__(self, hass, hemisphere, season_tracking_type):
@property
def name(self):
"""Return the name."""
return "Season"
return self._name

@property
def state(self):
Expand Down
0