1
mirror of https://github.com/home-assistant/core synced 2024-09-28 03:04:04 +02:00

Add unique id for min_max (#81007)

This commit is contained in:
G Johansson 2022-10-26 11:27:44 +02:00 committed by GitHub
parent 352976fd1d
commit be7e61b88b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -16,6 +16,7 @@ from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT,
CONF_NAME,
CONF_TYPE,
CONF_UNIQUE_ID,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
@ -61,6 +62,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
vol.Optional(CONF_NAME): cv.string,
vol.Required(CONF_ENTITY_IDS): cv.entity_ids,
vol.Optional(CONF_ROUND_DIGITS, default=2): vol.Coerce(int),
vol.Optional(CONF_UNIQUE_ID): str,
}
)
@ -102,11 +104,12 @@ async def async_setup_platform(
name = config.get(CONF_NAME)
sensor_type = config.get(CONF_TYPE)
round_digits = config.get(CONF_ROUND_DIGITS)
unique_id = config.get(CONF_UNIQUE_ID)
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
async_add_entities(
[MinMaxSensor(entity_ids, name, sensor_type, round_digits, None)]
[MinMaxSensor(entity_ids, name, sensor_type, round_digits, unique_id)]
)

View File

@ -14,6 +14,7 @@ from homeassistant.const import (
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
import homeassistant.helpers.entity_registry as er
from homeassistant.setup import async_setup_component
from tests.common import get_fixture_path
@ -63,6 +64,7 @@ async def test_min_sensor(hass):
"name": "test_min",
"type": "min",
"entity_ids": ["sensor.test_1", "sensor.test_2", "sensor.test_3"],
"unique_id": "very_unique_id",
}
}
@ -81,6 +83,10 @@ async def test_min_sensor(hass):
assert entity_ids[2] == state.attributes.get("min_entity_id")
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entity_reg = er.async_get(hass)
entity = entity_reg.async_get("sensor.test_min")
assert entity.unique_id == "very_unique_id"
async def test_max_sensor(hass):
"""Test the max sensor."""