mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Add device class to ESPHome switches (#64919)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
a3d2a1a5e0
commit
d22fc99294
@ -5,7 +5,7 @@ from typing import Any
|
|||||||
|
|
||||||
from aioesphomeapi import SwitchInfo, SwitchState
|
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.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
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 true if the switch is on."""
|
||||||
return self._state.state
|
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:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the entity on."""
|
"""Turn the entity on."""
|
||||||
await self._client.switch_command(self._static_info.key, True)
|
await self._client.switch_command(self._static_info.key, True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user