mirror of
https://github.com/home-assistant/core.git
synced 2026-03-24 08:18:29 +01:00
Compare commits
6 Commits
numeric-th
...
knx-defaul
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f2e89d46b | ||
|
|
a6a56c267a | ||
|
|
6ab8f9e8b0 | ||
|
|
a1e876c795 | ||
|
|
e7e388b578 | ||
|
|
c27144c810 |
@@ -10,7 +10,6 @@ from homeassistant import config_entries
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE_CLASS,
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_NAME,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
@@ -128,8 +127,7 @@ class KnxYamlBinarySensor(_KnxBinarySensor, KnxYamlEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=str(self._device.remote_value.group_address_state),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
|
||||
self._attr_device_class = config.get(CONF_DEVICE_CLASS)
|
||||
|
||||
@@ -6,7 +6,7 @@ from xknx.devices import RawValue as XknxRawValue
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.button import ButtonEntity
|
||||
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, CONF_PAYLOAD, Platform
|
||||
from homeassistant.const import CONF_NAME, CONF_PAYLOAD, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
@@ -45,8 +45,7 @@ class KNXButton(KnxYamlEntity, ButtonEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=f"{self._device.remote_value.group_address}_{self._payload}",
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
|
||||
async def async_press(self) -> None:
|
||||
|
||||
@@ -27,13 +27,7 @@ from homeassistant.components.climate import (
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_NAME,
|
||||
Platform,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, CONF_NAME, Platform, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddConfigEntryEntitiesCallback,
|
||||
@@ -655,8 +649,7 @@ class KnxYamlClimate(_KnxClimate, KnxYamlEntity):
|
||||
f"{self._device.target_temperature.group_address}_"
|
||||
f"{self._device._setpoint_shift.group_address}" # noqa: SLF001
|
||||
),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
default_hvac_mode: HVACMode = config[ClimateConf.DEFAULT_CONTROLLER_MODE]
|
||||
fan_max_step = config[ClimateConf.FAN_MAX_STEP]
|
||||
|
||||
@@ -67,6 +67,7 @@ CONF_KNX_SECURE_USER_PASSWORD: Final = "user_password"
|
||||
CONF_KNX_SECURE_DEVICE_AUTHENTICATION: Final = "device_authentication"
|
||||
|
||||
|
||||
CONF_DEFAULT_ENTITY_ID: Final = "default_entity_id"
|
||||
CONF_CONTEXT_TIMEOUT: Final = "context_timeout"
|
||||
CONF_IGNORE_INTERNAL_STATE: Final = "ignore_internal_state"
|
||||
CONF_PAYLOAD_LENGTH: Final = "payload_length"
|
||||
|
||||
@@ -15,12 +15,7 @@ from homeassistant.components.cover import (
|
||||
CoverEntity,
|
||||
CoverEntityFeature,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE_CLASS,
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_NAME,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddConfigEntryEntitiesCallback,
|
||||
@@ -215,8 +210,7 @@ class KnxYamlCover(_KnxCover, KnxYamlEntity):
|
||||
f"{self._device.updown.group_address}_"
|
||||
f"{self._device.position_target.group_address}"
|
||||
),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
self.init_base()
|
||||
if custom_device_class := config.get(CONF_DEVICE_CLASS):
|
||||
|
||||
@@ -10,13 +10,7 @@ from xknx.dpt.dpt_11 import KNXDate as XKNXDate
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.date import DateEntity
|
||||
from homeassistant.const import (
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_NAME,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.const import CONF_NAME, STATE_UNAVAILABLE, STATE_UNKNOWN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddConfigEntryEntitiesCallback,
|
||||
@@ -117,8 +111,7 @@ class KnxYamlDate(_KNXDate, KnxYamlEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=str(self._device.remote_value.group_address),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -10,13 +10,7 @@ from xknx.dpt.dpt_19 import KNXDateTime as XKNXDateTime
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.datetime import DateTimeEntity
|
||||
from homeassistant.const import (
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_NAME,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.const import CONF_NAME, STATE_UNAVAILABLE, STATE_UNKNOWN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddConfigEntryEntitiesCallback,
|
||||
@@ -122,8 +116,7 @@ class KnxYamlDateTime(_KNXDateTime, KnxYamlEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=str(self._device.remote_value.group_address),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_platform import EntityPlatform
|
||||
from homeassistant.helpers.entity_registry import RegistryEntry
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import CONF_DEFAULT_ENTITY_ID, DOMAIN
|
||||
from .storage.config_store import PlatformControllerBase
|
||||
from .storage.const import CONF_DEVICE_INFO
|
||||
|
||||
@@ -101,14 +101,17 @@ class KnxYamlEntity(_KnxEntityBase):
|
||||
self,
|
||||
knx_module: KNXModule,
|
||||
unique_id: str,
|
||||
name: str,
|
||||
entity_category: EntityCategory | None,
|
||||
entity_config: dict[str, Any],
|
||||
) -> None:
|
||||
"""Initialize the YAML entity."""
|
||||
self._knx_module = knx_module
|
||||
self._attr_name = name or None
|
||||
self._attr_name = entity_config[CONF_NAME] or None
|
||||
self._attr_unique_id = unique_id
|
||||
self._attr_entity_category = entity_category
|
||||
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:
|
||||
self.entity_id = default_entity_id
|
||||
|
||||
|
||||
class KnxUiEntity(_KnxEntityBase):
|
||||
|
||||
@@ -12,7 +12,7 @@ from xknx.telegram.address import parse_device_group_address
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.fan import FanEntity, FanEntityFeature
|
||||
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, Platform
|
||||
from homeassistant.const import CONF_NAME, Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
@@ -229,8 +229,7 @@ class KnxYamlFan(_KnxFan, KnxYamlEntity):
|
||||
if self._device.speed.group_address
|
||||
else str(self._device.switch.group_address)
|
||||
),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
# FanSpeedMode.STEP if max_step is set
|
||||
self._step_range: tuple[int, int] | None = (1, max_step) if max_step else None
|
||||
|
||||
@@ -19,7 +19,7 @@ from homeassistant.components.light import (
|
||||
ColorMode,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, Platform
|
||||
from homeassistant.const import CONF_NAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddConfigEntryEntitiesCallback,
|
||||
@@ -562,8 +562,7 @@ class KnxYamlLight(_KnxLight, KnxYamlEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=self._device_unique_id(),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
self._attr_color_mode = next(iter(self.supported_color_modes))
|
||||
self._attr_max_color_temp_kelvin: int = config[LightSchema.CONF_MAX_KELVIN]
|
||||
|
||||
@@ -7,7 +7,7 @@ from xknx.devices import Notification as XknxNotification
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.notify import NotifyEntity
|
||||
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, CONF_TYPE, Platform
|
||||
from homeassistant.const import CONF_NAME, CONF_TYPE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
@@ -50,8 +50,7 @@ class KNXNotify(KnxYamlEntity, NotifyEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=str(self._device.remote_value.group_address),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
|
||||
async def async_send_message(self, message: str, title: str | None = None) -> None:
|
||||
|
||||
@@ -10,7 +10,6 @@ from homeassistant import config_entries
|
||||
from homeassistant.components.number import NumberDeviceClass, NumberMode, RestoreNumber
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE_CLASS,
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_MODE,
|
||||
CONF_NAME,
|
||||
CONF_TYPE,
|
||||
@@ -120,8 +119,7 @@ class KnxYamlNumber(_KnxNumber, KnxYamlEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=str(self._device.sensor_value.group_address),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
dpt_string = self._device.sensor_value.dpt_class.dpt_number_str()
|
||||
dpt_info = get_supported_dpts()[dpt_string]
|
||||
|
||||
@@ -8,7 +8,7 @@ from xknx.devices import Device as XknxDevice, Scene as XknxScene
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.scene import BaseScene
|
||||
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, Platform
|
||||
from homeassistant.const import CONF_NAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddConfigEntryEntitiesCallback,
|
||||
@@ -94,8 +94,7 @@ class KnxYamlScene(_KnxScene, KnxYamlEntity):
|
||||
unique_id=(
|
||||
f"{self._device.scene_value.group_address}_{self._device.scene_number}"
|
||||
),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ from homeassistant.helpers.entity import ENTITY_CATEGORIES_SCHEMA
|
||||
|
||||
from .const import (
|
||||
CONF_CONTEXT_TIMEOUT,
|
||||
CONF_DEFAULT_ENTITY_ID,
|
||||
CONF_IGNORE_INTERNAL_STATE,
|
||||
CONF_INVERT,
|
||||
CONF_KNX_EXPOSE,
|
||||
@@ -199,12 +200,17 @@ class KNXPlatformSchema(ABC):
|
||||
}
|
||||
|
||||
|
||||
COMMON_ENTITY_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_NAME, default=""): cv.string,
|
||||
vol.Optional(CONF_ENTITY_CATEGORY): ENTITY_CATEGORIES_SCHEMA,
|
||||
}
|
||||
)
|
||||
def _entity_base_schema(platform: Platform) -> vol.Schema:
|
||||
"""Return a base schema for KNX entities."""
|
||||
return vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_NAME, default=""): cv.string,
|
||||
vol.Optional(CONF_DEFAULT_ENTITY_ID): vol.All(
|
||||
cv.entity_id, cv.entity_domain(platform)
|
||||
),
|
||||
vol.Optional(CONF_ENTITY_CATEGORY): ENTITY_CATEGORIES_SCHEMA,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class BinarySensorSchema(KNXPlatformSchema):
|
||||
@@ -213,7 +219,7 @@ class BinarySensorSchema(KNXPlatformSchema):
|
||||
PLATFORM = Platform.BINARY_SENSOR
|
||||
|
||||
ENTITY_SCHEMA = vol.All(
|
||||
COMMON_ENTITY_SCHEMA.extend(
|
||||
_entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_SYNC_STATE, default=True): sync_state_validator,
|
||||
vol.Optional(CONF_IGNORE_INTERNAL_STATE, default=False): cv.boolean,
|
||||
@@ -242,7 +248,7 @@ class ButtonSchema(KNXPlatformSchema):
|
||||
)
|
||||
|
||||
ENTITY_SCHEMA = vol.All(
|
||||
COMMON_ENTITY_SCHEMA.extend(
|
||||
_entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Required(KNX_ADDRESS): ga_validator,
|
||||
vol.Exclusive(
|
||||
@@ -332,7 +338,7 @@ class ClimateSchema(KNXPlatformSchema):
|
||||
DEFAULT_FAN_SPEED_MODE = "percent"
|
||||
|
||||
ENTITY_SCHEMA = vol.All(
|
||||
COMMON_ENTITY_SCHEMA.extend(
|
||||
_entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(
|
||||
ClimateConf.SETPOINT_SHIFT_MAX, default=DEFAULT_SETPOINT_SHIFT_MAX
|
||||
@@ -434,7 +440,7 @@ class CoverSchema(KNXPlatformSchema):
|
||||
DEFAULT_TRAVEL_TIME = 25
|
||||
|
||||
ENTITY_SCHEMA = vol.All(
|
||||
COMMON_ENTITY_SCHEMA.extend(
|
||||
_entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_MOVE_LONG_ADDRESS): ga_list_validator,
|
||||
vol.Optional(CONF_MOVE_SHORT_ADDRESS): ga_list_validator,
|
||||
@@ -477,7 +483,7 @@ class DateSchema(KNXPlatformSchema):
|
||||
|
||||
PLATFORM = Platform.DATE
|
||||
|
||||
ENTITY_SCHEMA = COMMON_ENTITY_SCHEMA.extend(
|
||||
ENTITY_SCHEMA = _entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_RESPOND_TO_READ, default=False): cv.boolean,
|
||||
vol.Optional(CONF_SYNC_STATE, default=True): sync_state_validator,
|
||||
@@ -492,7 +498,7 @@ class DateTimeSchema(KNXPlatformSchema):
|
||||
|
||||
PLATFORM = Platform.DATETIME
|
||||
|
||||
ENTITY_SCHEMA = COMMON_ENTITY_SCHEMA.extend(
|
||||
ENTITY_SCHEMA = _entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_RESPOND_TO_READ, default=False): cv.boolean,
|
||||
vol.Optional(CONF_SYNC_STATE, default=True): sync_state_validator,
|
||||
@@ -560,7 +566,7 @@ class FanSchema(KNXPlatformSchema):
|
||||
CONF_SWITCH_STATE_ADDRESS = "switch_state_address"
|
||||
|
||||
ENTITY_SCHEMA = vol.All(
|
||||
COMMON_ENTITY_SCHEMA.extend(
|
||||
_entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(KNX_ADDRESS): ga_list_validator,
|
||||
vol.Optional(CONF_STATE_ADDRESS): ga_list_validator,
|
||||
@@ -644,7 +650,7 @@ class LightSchema(KNXPlatformSchema):
|
||||
)
|
||||
|
||||
ENTITY_SCHEMA = vol.All(
|
||||
COMMON_ENTITY_SCHEMA.extend(
|
||||
_entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(KNX_ADDRESS): ga_list_validator,
|
||||
vol.Optional(CONF_STATE_ADDRESS): ga_list_validator,
|
||||
@@ -740,7 +746,7 @@ class NotifySchema(KNXPlatformSchema):
|
||||
|
||||
PLATFORM = Platform.NOTIFY
|
||||
|
||||
ENTITY_SCHEMA = COMMON_ENTITY_SCHEMA.extend(
|
||||
ENTITY_SCHEMA = _entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_TYPE, default="latin_1"): string_type_validator,
|
||||
vol.Required(KNX_ADDRESS): ga_validator,
|
||||
@@ -754,7 +760,7 @@ class NumberSchema(KNXPlatformSchema):
|
||||
PLATFORM = Platform.NUMBER
|
||||
|
||||
ENTITY_SCHEMA = vol.All(
|
||||
COMMON_ENTITY_SCHEMA.extend(
|
||||
_entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_RESPOND_TO_READ, default=False): cv.boolean,
|
||||
vol.Optional(CONF_MODE, default=NumberMode.AUTO): vol.Coerce(
|
||||
@@ -781,7 +787,7 @@ class SceneSchema(KNXPlatformSchema):
|
||||
|
||||
CONF_SCENE_NUMBER = "scene_number"
|
||||
|
||||
ENTITY_SCHEMA = COMMON_ENTITY_SCHEMA.extend(
|
||||
ENTITY_SCHEMA = _entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Required(KNX_ADDRESS): ga_list_validator,
|
||||
vol.Required(SceneConf.SCENE_NUMBER): vol.All(
|
||||
@@ -800,7 +806,7 @@ class SelectSchema(KNXPlatformSchema):
|
||||
CONF_OPTIONS = "options"
|
||||
|
||||
ENTITY_SCHEMA = vol.All(
|
||||
COMMON_ENTITY_SCHEMA.extend(
|
||||
_entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_SYNC_STATE, default=True): sync_state_validator,
|
||||
vol.Optional(CONF_RESPOND_TO_READ, default=False): cv.boolean,
|
||||
@@ -831,7 +837,7 @@ class SensorSchema(KNXPlatformSchema):
|
||||
CONF_SYNC_STATE = CONF_SYNC_STATE
|
||||
|
||||
ENTITY_SCHEMA = vol.All(
|
||||
COMMON_ENTITY_SCHEMA.extend(
|
||||
_entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_SYNC_STATE, default=True): sync_state_validator,
|
||||
vol.Optional(CONF_ALWAYS_CALLBACK, default=False): cv.boolean,
|
||||
@@ -854,7 +860,7 @@ class SwitchSchema(KNXPlatformSchema):
|
||||
CONF_INVERT = CONF_INVERT
|
||||
CONF_STATE_ADDRESS = CONF_STATE_ADDRESS
|
||||
|
||||
ENTITY_SCHEMA = COMMON_ENTITY_SCHEMA.extend(
|
||||
ENTITY_SCHEMA = _entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_INVERT, default=False): cv.boolean,
|
||||
vol.Optional(CONF_RESPOND_TO_READ, default=False): cv.boolean,
|
||||
@@ -870,7 +876,7 @@ class TextSchema(KNXPlatformSchema):
|
||||
|
||||
PLATFORM = Platform.TEXT
|
||||
|
||||
ENTITY_SCHEMA = COMMON_ENTITY_SCHEMA.extend(
|
||||
ENTITY_SCHEMA = _entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_RESPOND_TO_READ, default=False): cv.boolean,
|
||||
vol.Optional(CONF_TYPE, default="latin_1"): string_type_validator,
|
||||
@@ -886,7 +892,7 @@ class TimeSchema(KNXPlatformSchema):
|
||||
|
||||
PLATFORM = Platform.TIME
|
||||
|
||||
ENTITY_SCHEMA = COMMON_ENTITY_SCHEMA.extend(
|
||||
ENTITY_SCHEMA = _entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_RESPOND_TO_READ, default=False): cv.boolean,
|
||||
vol.Optional(CONF_SYNC_STATE, default=True): sync_state_validator,
|
||||
@@ -916,7 +922,7 @@ class WeatherSchema(KNXPlatformSchema):
|
||||
CONF_KNX_AIR_PRESSURE_ADDRESS = "address_air_pressure"
|
||||
CONF_KNX_HUMIDITY_ADDRESS = "address_humidity"
|
||||
|
||||
ENTITY_SCHEMA = COMMON_ENTITY_SCHEMA.extend(
|
||||
ENTITY_SCHEMA = _entity_base_schema(PLATFORM).extend(
|
||||
{
|
||||
vol.Optional(CONF_SYNC_STATE, default=True): sync_state_validator,
|
||||
vol.Required(CONF_KNX_TEMPERATURE_ADDRESS): ga_list_validator,
|
||||
|
||||
@@ -8,7 +8,6 @@ from xknx.devices import Device as XknxDevice, RawValue
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.select import SelectEntity
|
||||
from homeassistant.const import (
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_NAME,
|
||||
CONF_PAYLOAD,
|
||||
STATE_UNAVAILABLE,
|
||||
@@ -69,8 +68,7 @@ class KNXSelect(KnxYamlEntity, SelectEntity, RestoreEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=str(self._device.remote_value.group_address),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
self._option_payloads: dict[str, int] = {
|
||||
option[SelectSchema.CONF_OPTION]: option[CONF_PAYLOAD]
|
||||
|
||||
@@ -22,7 +22,6 @@ from homeassistant.components.sensor import (
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE_CLASS,
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_NAME,
|
||||
CONF_TYPE,
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
@@ -213,8 +212,7 @@ class KnxYamlSensor(_KnxSensor, KnxYamlEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=str(self._device.sensor_value.group_address_state),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
dpt_string = self._device.sensor_value.dpt_class.dpt_number_str()
|
||||
dpt_info = get_supported_dpts()[dpt_string]
|
||||
|
||||
@@ -10,7 +10,6 @@ from homeassistant import config_entries
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE_CLASS,
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_NAME,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
@@ -118,8 +117,7 @@ class KnxYamlSwitch(_KnxSwitch, KnxYamlEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=str(self._device.switch.group_address),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
self._attr_device_class = config.get(CONF_DEVICE_CLASS)
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ from xknx.dpt import DPTLatin1
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.text import TextEntity, TextMode
|
||||
from homeassistant.const import (
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_MODE,
|
||||
CONF_NAME,
|
||||
CONF_TYPE,
|
||||
@@ -123,8 +122,7 @@ class KnxYamlText(_KnxText, KnxYamlEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=str(self._device.remote_value.group_address),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
self._attr_mode = config[CONF_MODE]
|
||||
|
||||
|
||||
@@ -10,13 +10,7 @@ from xknx.dpt.dpt_10 import KNXTime as XknxTime
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.time import TimeEntity
|
||||
from homeassistant.const import (
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_NAME,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.const import CONF_NAME, STATE_UNAVAILABLE, STATE_UNKNOWN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddConfigEntryEntitiesCallback,
|
||||
@@ -117,8 +111,7 @@ class KnxYamlTime(_KNXTime, KnxYamlEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=str(self._device.remote_value.group_address),
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ from xknx.devices import Weather as XknxWeather
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.weather import WeatherEntity
|
||||
from homeassistant.const import (
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_NAME,
|
||||
Platform,
|
||||
UnitOfPressure,
|
||||
@@ -89,8 +88,7 @@ class KNXWeather(KnxYamlEntity, WeatherEntity):
|
||||
super().__init__(
|
||||
knx_module=knx_module,
|
||||
unique_id=str(self._device._temperature.group_address_state), # noqa: SLF001
|
||||
name=config[CONF_NAME],
|
||||
entity_category=config.get(CONF_ENTITY_CATEGORY),
|
||||
entity_config=config,
|
||||
)
|
||||
|
||||
@property
|
||||
|
||||
118
tests/components/knx/test_entity.py
Normal file
118
tests/components/knx/test_entity.py
Normal file
@@ -0,0 +1,118 @@
|
||||
"""KNX base entity tests."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.knx.const import KNX_ADDRESS
|
||||
from homeassistant.const import STATE_OFF, EntityCategory, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .conftest import KNXTestKit
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("config", "expected_entity_id", "expected_friendly_name"),
|
||||
[
|
||||
(
|
||||
{
|
||||
"name": "test",
|
||||
KNX_ADDRESS: "1/2/3",
|
||||
},
|
||||
"switch.test",
|
||||
"test",
|
||||
),
|
||||
(
|
||||
{
|
||||
KNX_ADDRESS: "1/2/3",
|
||||
},
|
||||
"switch.knx_1_2_3", # generated from unique_id
|
||||
None,
|
||||
),
|
||||
(
|
||||
{
|
||||
"name": "",
|
||||
KNX_ADDRESS: "1/2/3",
|
||||
},
|
||||
"switch.knx_1_2_3", # generated from unique_id
|
||||
None,
|
||||
),
|
||||
(
|
||||
{
|
||||
"default_entity_id": "switch.test_default_entity_id",
|
||||
KNX_ADDRESS: "1/2/3",
|
||||
},
|
||||
"switch.test_default_entity_id",
|
||||
None,
|
||||
),
|
||||
(
|
||||
{
|
||||
"name": "my_test_name",
|
||||
"default_entity_id": "switch.test_default_entity_id",
|
||||
KNX_ADDRESS: "1/2/3",
|
||||
},
|
||||
"switch.test_default_entity_id",
|
||||
"my_test_name",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_yaml_entity_naming(
|
||||
hass: HomeAssistant,
|
||||
knx: KNXTestKit,
|
||||
config: dict[str, Any],
|
||||
expected_entity_id: str,
|
||||
expected_friendly_name: str | None,
|
||||
) -> None:
|
||||
"""Test KNX entity id and name setting from YAML configuration."""
|
||||
await knx.setup_integration({Platform.SWITCH: config})
|
||||
knx.assert_state(
|
||||
expected_entity_id,
|
||||
STATE_OFF,
|
||||
friendly_name=expected_friendly_name,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("config", "expected_entity_category"),
|
||||
[
|
||||
(
|
||||
{},
|
||||
None,
|
||||
),
|
||||
(
|
||||
{
|
||||
"entity_category": "diagnostic",
|
||||
},
|
||||
EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
(
|
||||
{
|
||||
"entity_category": "config",
|
||||
},
|
||||
EntityCategory.CONFIG,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_yaml_entity_category(
|
||||
hass: HomeAssistant,
|
||||
knx: KNXTestKit,
|
||||
entity_registry: er.EntityRegistry,
|
||||
config: dict[str, Any],
|
||||
expected_entity_category: EntityCategory | None,
|
||||
) -> None:
|
||||
"""Test KNX entity category setting from YAML configuration."""
|
||||
await knx.setup_integration(
|
||||
{
|
||||
Platform.SWITCH: [
|
||||
{
|
||||
"default_entity_id": "switch.test",
|
||||
KNX_ADDRESS: "1/1/1",
|
||||
**config,
|
||||
},
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
entity = entity_registry.async_get("switch.test")
|
||||
assert entity.entity_category is expected_entity_category
|
||||
Reference in New Issue
Block a user