From d22fc99294b2980750b155a27406e5ea636da199 Mon Sep 17 00:00:00 2001 From: Oxan van Leeuwen Date: Thu, 3 Feb 2022 21:23:30 +0100 Subject: [PATCH] Add device class to ESPHome switches (#64919) Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- homeassistant/components/esphome/switch.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/esphome/switch.py b/homeassistant/components/esphome/switch.py index 952cb96fcd8..fbb22bb7397 100644 --- a/homeassistant/components/esphome/switch.py +++ b/homeassistant/components/esphome/switch.py @@ -5,7 +5,7 @@ from typing import Any from aioesphomeapi import SwitchInfo, SwitchState -from homeassistant.components.switch import SwitchEntity +from homeassistant.components.switch import DEVICE_CLASSES, SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -45,6 +45,13 @@ class EsphomeSwitch(EsphomeEntity[SwitchInfo, SwitchState], SwitchEntity): """Return true if the switch is on.""" return self._state.state + @property + def device_class(self) -> str | None: + """Return the class of this device.""" + if self._static_info.device_class not in DEVICE_CLASSES: + return None + return self._static_info.device_class + async def async_turn_on(self, **kwargs: Any) -> None: """Turn the entity on.""" await self._client.switch_command(self._static_info.key, True)