1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 08:26:41 +01:00

create entity_id_format of validated default_entity_id

This commit is contained in:
farmio
2026-03-22 13:16:27 +01:00
parent a1e876c795
commit 6ab8f9e8b0
17 changed files with 18 additions and 42 deletions

View File

@@ -7,7 +7,7 @@ from typing import Any
from xknx.devices import BinarySensor as XknxBinarySensor
from homeassistant import config_entries
from homeassistant.components.binary_sensor import ENTITY_ID_FORMAT, BinarySensorEntity
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.const import (
CONF_DEVICE_CLASS,
CONF_NAME,
@@ -80,7 +80,6 @@ class _KnxBinarySensor(BinarySensorEntity, RestoreEntity):
"""Representation of a KNX binary sensor."""
_device: XknxBinarySensor
_entity_id_format = ENTITY_ID_FORMAT
async def async_added_to_hass(self) -> None:
"""Restore last state."""

View File

@@ -5,7 +5,7 @@ from __future__ import annotations
from xknx.devices import RawValue as XknxRawValue
from homeassistant import config_entries
from homeassistant.components.button import ENTITY_ID_FORMAT, ButtonEntity
from homeassistant.components.button import ButtonEntity
from homeassistant.const import CONF_NAME, CONF_PAYLOAD, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@@ -32,7 +32,6 @@ class KNXButton(KnxYamlEntity, ButtonEntity):
"""Representation of a KNX button."""
_device: XknxRawValue
_entity_id_format = ENTITY_ID_FORMAT
def __init__(self, knx_module: KNXModule, config: ConfigType) -> None:
"""Initialize a KNX button."""

View File

@@ -11,7 +11,6 @@ from homeassistant import config_entries
from homeassistant.components.cover import (
ATTR_POSITION,
ATTR_TILT_POSITION,
ENTITY_ID_FORMAT,
CoverDeviceClass,
CoverEntity,
CoverEntityFeature,
@@ -76,7 +75,6 @@ class _KnxCover(CoverEntity):
"""Representation of a KNX cover."""
_device: XknxCover
_entity_id_format = ENTITY_ID_FORMAT
def init_base(self) -> None:
"""Initialize common attributes - may be based on xknx device instance."""

View File

@@ -9,7 +9,7 @@ from xknx.devices import DateDevice as XknxDateDevice
from xknx.dpt.dpt_11 import KNXDate as XKNXDate
from homeassistant import config_entries
from homeassistant.components.date import ENTITY_ID_FORMAT, DateEntity
from homeassistant.components.date import DateEntity
from homeassistant.const import CONF_NAME, STATE_UNAVAILABLE, STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import (
@@ -69,7 +69,6 @@ class _KNXDate(DateEntity, RestoreEntity):
"""Representation of a KNX date."""
_device: XknxDateDevice
_entity_id_format = ENTITY_ID_FORMAT
async def async_added_to_hass(self) -> None:
"""Restore last state."""

View File

@@ -9,7 +9,7 @@ from xknx.devices import DateTimeDevice as XknxDateTimeDevice
from xknx.dpt.dpt_19 import KNXDateTime as XKNXDateTime
from homeassistant import config_entries
from homeassistant.components.datetime import ENTITY_ID_FORMAT, DateTimeEntity
from homeassistant.components.datetime import DateTimeEntity
from homeassistant.const import CONF_NAME, STATE_UNAVAILABLE, STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import (
@@ -70,7 +70,6 @@ class _KNXDateTime(DateTimeEntity, RestoreEntity):
"""Representation of a KNX datetime."""
_device: XknxDateTimeDevice
_entity_id_format = ENTITY_ID_FORMAT
async def async_added_to_hass(self) -> None:
"""Restore last state."""

View File

@@ -54,7 +54,6 @@ class _KnxEntityBase(Entity):
_attr_should_poll = False
_attr_unique_id: str
_entity_id_format: str
_knx_module: KNXModule
_device: XknxDevice
@@ -111,11 +110,12 @@ class KnxYamlEntity(_KnxEntityBase):
self._attr_entity_category = entity_config.get(CONF_ENTITY_CATEGORY)
default_entity_id: str | None
if (default_entity_id := entity_config.get(CONF_DEFAULT_ENTITY_ID)) is not None:
_, _, object_id = default_entity_id.partition(".")
self.entity_id = async_generate_entity_id(
self._entity_id_format, object_id, hass=knx_module.hass
)
if (default_entity_id := entity_config.get(CONF_DEFAULT_ENTITY_ID)) is None:
return
entity_platform, _, object_id = default_entity_id.partition(".")
self.entity_id = async_generate_entity_id(
f"{entity_platform}.{{}}", object_id, hass=knx_module.hass
)
class KnxUiEntity(_KnxEntityBase):

View File

@@ -11,7 +11,7 @@ from xknx.devices import Fan as XknxFan
from xknx.telegram.address import parse_device_group_address
from homeassistant import config_entries
from homeassistant.components.fan import ENTITY_ID_FORMAT, FanEntity, FanEntityFeature
from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.const import CONF_NAME, Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry as er
@@ -130,7 +130,6 @@ class _KnxFan(FanEntity):
"""Representation of a KNX fan."""
_device: XknxFan
_entity_id_format = ENTITY_ID_FORMAT
_step_range: tuple[int, int] | None
def _get_knx_speed(self, percentage: int) -> int:

View File

@@ -16,7 +16,6 @@ from homeassistant.components.light import (
ATTR_RGB_COLOR,
ATTR_RGBW_COLOR,
ATTR_XY_COLOR,
ENTITY_ID_FORMAT,
ColorMode,
LightEntity,
)
@@ -325,7 +324,6 @@ class _KnxLight(LightEntity):
_attr_max_color_temp_kelvin: int
_attr_min_color_temp_kelvin: int
_device: XknxLight
_entity_id_format = ENTITY_ID_FORMAT
@property
def is_on(self) -> bool:

View File

@@ -6,7 +6,7 @@ from xknx import XKNX
from xknx.devices import Notification as XknxNotification
from homeassistant import config_entries
from homeassistant.components.notify import ENTITY_ID_FORMAT, NotifyEntity
from homeassistant.components.notify import NotifyEntity
from homeassistant.const import CONF_NAME, CONF_TYPE, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@@ -43,7 +43,6 @@ class KNXNotify(KnxYamlEntity, NotifyEntity):
"""Representation of a KNX notification entity."""
_device: XknxNotification
_entity_id_format = ENTITY_ID_FORMAT
def __init__(self, knx_module: KNXModule, config: ConfigType) -> None:
"""Initialize a KNX notification."""

View File

@@ -7,12 +7,7 @@ from typing import cast
from xknx.devices import NumericValue
from homeassistant import config_entries
from homeassistant.components.number import (
ENTITY_ID_FORMAT,
NumberDeviceClass,
NumberMode,
RestoreNumber,
)
from homeassistant.components.number import NumberDeviceClass, NumberMode, RestoreNumber
from homeassistant.const import (
CONF_DEVICE_CLASS,
CONF_MODE,
@@ -83,7 +78,6 @@ class _KnxNumber(RestoreNumber):
"""Representation of a KNX number."""
_device: NumericValue
_entity_id_format = ENTITY_ID_FORMAT
async def async_added_to_hass(self) -> None:
"""Restore last state."""

View File

@@ -65,7 +65,6 @@ class _KnxScene(BaseScene, _KnxEntityBase):
"""Representation of a KNX scene."""
_device: XknxScene
_entity_id_format = "scene.{}"
async def _async_activate(self, **kwargs: Any) -> None:
"""Activate the scene."""

View File

@@ -6,7 +6,7 @@ from xknx import XKNX
from xknx.devices import Device as XknxDevice, RawValue
from homeassistant import config_entries
from homeassistant.components.select import ENTITY_ID_FORMAT, SelectEntity
from homeassistant.components.select import SelectEntity
from homeassistant.const import (
CONF_NAME,
CONF_PAYLOAD,
@@ -61,7 +61,6 @@ class KNXSelect(KnxYamlEntity, SelectEntity, RestoreEntity):
"""Representation of a KNX select."""
_device: RawValue
_entity_id_format = ENTITY_ID_FORMAT
def __init__(self, knx_module: KNXModule, config: ConfigType) -> None:
"""Initialize a KNX select."""

View File

@@ -14,7 +14,6 @@ from xknx.devices import Device as XknxDevice, Sensor as XknxSensor
from homeassistant import config_entries
from homeassistant.components.sensor import (
CONF_STATE_CLASS,
ENTITY_ID_FORMAT,
RestoreSensor,
SensorDeviceClass,
SensorEntity,
@@ -170,7 +169,6 @@ class _KnxSensor(RestoreSensor, _KnxEntityBase):
"""Representation of a KNX sensor."""
_device: XknxSensor
_entity_id_format = ENTITY_ID_FORMAT
async def async_added_to_hass(self) -> None:
"""Restore last state."""

View File

@@ -7,7 +7,7 @@ from typing import Any
from xknx.devices import Switch as XknxSwitch
from homeassistant import config_entries
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity
from homeassistant.components.switch import SwitchEntity
from homeassistant.const import (
CONF_DEVICE_CLASS,
CONF_NAME,
@@ -75,7 +75,6 @@ class _KnxSwitch(SwitchEntity, RestoreEntity):
"""Base class for a KNX switch."""
_device: XknxSwitch
_entity_id_format = ENTITY_ID_FORMAT
async def async_added_to_hass(self) -> None:
"""Restore last state."""

View File

@@ -7,7 +7,7 @@ from xknx.devices import Notification as XknxNotification
from xknx.dpt import DPTLatin1
from homeassistant import config_entries
from homeassistant.components.text import ENTITY_ID_FORMAT, TextEntity, TextMode
from homeassistant.components.text import TextEntity, TextMode
from homeassistant.const import (
CONF_MODE,
CONF_NAME,
@@ -74,7 +74,6 @@ class _KnxText(TextEntity, RestoreEntity):
"""Representation of a KNX text."""
_device: XknxNotification
_entity_id_format = ENTITY_ID_FORMAT
_attr_native_max = 14
async def async_added_to_hass(self) -> None:

View File

@@ -9,7 +9,7 @@ from xknx.devices import TimeDevice as XknxTimeDevice
from xknx.dpt.dpt_10 import KNXTime as XknxTime
from homeassistant import config_entries
from homeassistant.components.time import ENTITY_ID_FORMAT, TimeEntity
from homeassistant.components.time import TimeEntity
from homeassistant.const import CONF_NAME, STATE_UNAVAILABLE, STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import (
@@ -69,7 +69,6 @@ class _KNXTime(TimeEntity, RestoreEntity):
"""Representation of a KNX time."""
_device: XknxTimeDevice
_entity_id_format = ENTITY_ID_FORMAT
async def async_added_to_hass(self) -> None:
"""Restore last state."""

View File

@@ -6,7 +6,7 @@ from xknx import XKNX
from xknx.devices import Weather as XknxWeather
from homeassistant import config_entries
from homeassistant.components.weather import ENTITY_ID_FORMAT, WeatherEntity
from homeassistant.components.weather import WeatherEntity
from homeassistant.const import (
CONF_NAME,
Platform,
@@ -78,7 +78,6 @@ class KNXWeather(KnxYamlEntity, WeatherEntity):
"""Representation of a KNX weather device."""
_device: XknxWeather
_entity_id_format = ENTITY_ID_FORMAT
_attr_native_pressure_unit = UnitOfPressure.PA
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
_attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND