Reduce overhead to update esphome entities (#94930)

This commit is contained in:
J. Nick Koston 2023-06-21 10:00:21 +01:00 committed by GitHub
parent 933ae5198e
commit 804a8ef36a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 117 additions and 158 deletions

View file

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