Skip to content

Commit

Permalink
set time_window=0 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Feb 3, 2020
1 parent eb07819 commit 3e727be
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions homeassistant/components/derivative/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
ICON = "mdi:chart-line"

DEFAULT_ROUND = 3
DEFAULT_TIME_WINDOW = 0

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
Expand All @@ -47,7 +48,7 @@
vol.Optional(CONF_UNIT_PREFIX, default=None): vol.In(UNIT_PREFIXES),
vol.Optional(CONF_UNIT_TIME, default="h"): vol.In(UNIT_TIME),
vol.Optional(CONF_UNIT): cv.string,
vol.Optional(CONF_TIME_WINDOW): cv.time_period,
vol.Optional(CONF_TIME_WINDOW, default=DEFAULT_TIME_WINDOW): cv.time_period,
}
)

Expand All @@ -61,7 +62,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
config[CONF_UNIT_PREFIX],
config[CONF_UNIT_TIME],
config.get(CONF_UNIT),
config.get(CONF_TIME_WINDOW),
config[CONF_TIME_WINDOW],
)

async_add_entities([derivative])
Expand Down Expand Up @@ -98,10 +99,7 @@ def __init__(

self._unit_prefix = UNIT_PREFIXES[unit_prefix]
self._unit_time = UNIT_TIME[unit_time]
if time_window is None:
self._time_window = 0
else:
self._time_window = time_window * _unit_time
self._time_window = time_window * _unit_time

async def async_added_to_hass(self):
"""Handle entity which will be added."""
Expand Down

0 comments on commit 3e727be

Please sign in to comment.