From 0321c8bdc5cdf70346ed3c06152f9434e78fb7be Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Wed, 26 Oct 2022 21:04:11 +0200 Subject: [PATCH] Allow device class for switch to be set in knx (#81039) --- homeassistant/components/knx/schema.py | 4 ++++ homeassistant/components/knx/switch.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/homeassistant/components/knx/schema.py b/homeassistant/components/knx/schema.py index 55602d6153a..c1615b7e8e2 100644 --- a/homeassistant/components/knx/schema.py +++ b/homeassistant/components/knx/schema.py @@ -22,6 +22,9 @@ from homeassistant.components.cover import ( ) from homeassistant.components.number import NumberMode from homeassistant.components.sensor import CONF_STATE_CLASS, STATE_CLASSES_SCHEMA +from homeassistant.components.switch import ( + DEVICE_CLASSES_SCHEMA as SWITCH_DEVICE_CLASSES_SCHEMA, +) from homeassistant.const import ( CONF_DEVICE_CLASS, CONF_ENTITY_CATEGORY, @@ -873,6 +876,7 @@ class SwitchSchema(KNXPlatformSchema): vol.Optional(CONF_RESPOND_TO_READ, default=False): cv.boolean, vol.Required(KNX_ADDRESS): ga_list_validator, vol.Optional(CONF_STATE_ADDRESS): ga_list_validator, + vol.Optional(CONF_DEVICE_CLASS): SWITCH_DEVICE_CLASSES_SCHEMA, vol.Optional(CONF_ENTITY_CATEGORY): ENTITY_CATEGORIES_SCHEMA, } ) diff --git a/homeassistant/components/knx/switch.py b/homeassistant/components/knx/switch.py index 9f4eb6fc632..81f8de815c9 100644 --- a/homeassistant/components/knx/switch.py +++ b/homeassistant/components/knx/switch.py @@ -9,6 +9,7 @@ from xknx.devices import Switch as XknxSwitch 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, @@ -56,6 +57,7 @@ class KNXSwitch(KnxEntity, SwitchEntity, RestoreEntity): ) ) self._attr_entity_category = config.get(CONF_ENTITY_CATEGORY) + self._attr_device_class = config.get(CONF_DEVICE_CLASS) self._attr_unique_id = str(self._device.switch.group_address) async def async_added_to_hass(self) -> None: