Add unique id to Times of Day (#81196)
This commit is contained in:
parent
2ca61eef79
commit
c5c23cbc95
2 changed files with 28 additions and 1 deletions
|
@ -13,6 +13,7 @@ from homeassistant.const import (
|
|||
CONF_AFTER,
|
||||
CONF_BEFORE,
|
||||
CONF_NAME,
|
||||
CONF_UNIQUE_ID,
|
||||
SUN_EVENT_SUNRISE,
|
||||
SUN_EVENT_SUNSET,
|
||||
)
|
||||
|
@ -43,6 +44,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
vol.Required(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_AFTER_OFFSET, default=timedelta(0)): cv.time_period,
|
||||
vol.Optional(CONF_BEFORE_OFFSET, default=timedelta(0)): cv.time_period,
|
||||
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -85,7 +87,8 @@ async def async_setup_platform(
|
|||
before = config[CONF_BEFORE]
|
||||
before_offset = config[CONF_BEFORE_OFFSET]
|
||||
name = config[CONF_NAME]
|
||||
sensor = TodSensor(name, after, after_offset, before, before_offset, None)
|
||||
unique_id = config.get(CONF_UNIQUE_ID)
|
||||
sensor = TodSensor(name, after, after_offset, before, before_offset, unique_id)
|
||||
|
||||
async_add_entities([sensor])
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ from freezegun import freeze_time
|
|||
import pytest
|
||||
|
||||
from homeassistant.const import STATE_OFF, STATE_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.entity_registry as er
|
||||
from homeassistant.helpers.sun import get_astral_event_date, get_astral_event_next
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
@ -786,3 +788,25 @@ async def test_simple_before_after_does_not_loop_berlin_in_range(hass):
|
|||
assert state.attributes["after"] == "2019-01-11T00:00:00+01:00"
|
||||
assert state.attributes["before"] == "2019-01-11T06:00:00+01:00"
|
||||
assert state.attributes["next_update"] == "2019-01-11T06:00:00+01:00"
|
||||
|
||||
|
||||
async def test_unique_id(hass: HomeAssistant) -> None:
|
||||
"""Test unique id."""
|
||||
config = {
|
||||
"binary_sensor": [
|
||||
{
|
||||
"platform": "tod",
|
||||
"name": "Evening",
|
||||
"after": "18:00",
|
||||
"before": "22:00",
|
||||
"unique_id": "very_unique_id",
|
||||
}
|
||||
]
|
||||
}
|
||||
await async_setup_component(hass, "binary_sensor", config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_reg = er.async_get(hass)
|
||||
entity = entity_reg.async_get("binary_sensor.evening")
|
||||
|
||||
assert entity.unique_id == "very_unique_id"
|
||||
|
|
Loading…
Add table
Reference in a new issue