Reduce overhead to update esphome entities (#94930)
This commit is contained in:
parent
933ae5198e
commit
804a8ef36a
6 changed files with 117 additions and 158 deletions
|
@ -1,7 +1,7 @@
|
|||
"""Support for ESPHome binary sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from aioesphomeapi import BinarySensorInfo, BinarySensorState
|
||||
from aioesphomeapi import BinarySensorInfo, BinarySensorState, EntityInfo
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
|
@ -9,7 +9,7 @@ from homeassistant.components.binary_sensor import (
|
|||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.enum import try_parse_enum
|
||||
|
||||
|
@ -55,10 +55,13 @@ class EsphomeBinarySensor(
|
|||
return None
|
||||
return self._state.state
|
||||
|
||||
@property
|
||||
def device_class(self) -> BinarySensorDeviceClass | None:
|
||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
||||
return try_parse_enum(BinarySensorDeviceClass, self._static_info.device_class)
|
||||
@callback
|
||||
def _on_static_info_update(self, static_info: EntityInfo) -> None:
|
||||
"""Set attrs from static info."""
|
||||
super()._on_static_info_update(static_info)
|
||||
self._attr_device_class = try_parse_enum(
|
||||
BinarySensorDeviceClass, self._static_info.device_class
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue