Skip to content
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

Keep track of the derivative for unit_time #31397

Merged
merged 19 commits into from
Feb 3, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
set time_window=0 by default
  • Loading branch information
basnijholt committed Feb 3, 2020
commit 3e727beb70bacd49ba2004bee7df17e6aae552f2
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