Add device class to ESPHome switches (#64919)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>pull/65584/head
parent
a3d2a1a5e0
commit
d22fc99294
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue