Add device class to ESPHome switches (#64919)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
pull/65584/head
Oxan van Leeuwen 2022-02-03 21:23:30 +01:00 committed by GitHub
parent a3d2a1a5e0
commit d22fc99294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -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)