mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Remove str from binary sensor device class (#83393)
This commit is contained in:
parent
46caefca7b
commit
cb69364ad2
@ -179,19 +179,19 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
class BinarySensorEntityDescription(EntityDescription):
|
||||
"""A class that describes binary sensor entities."""
|
||||
|
||||
device_class: BinarySensorDeviceClass | str | None = None
|
||||
device_class: BinarySensorDeviceClass | None = None
|
||||
|
||||
|
||||
class BinarySensorEntity(Entity):
|
||||
"""Represent a binary sensor."""
|
||||
|
||||
entity_description: BinarySensorEntityDescription
|
||||
_attr_device_class: BinarySensorDeviceClass | str | None
|
||||
_attr_device_class: BinarySensorDeviceClass | None
|
||||
_attr_is_on: bool | None = None
|
||||
_attr_state: None = None
|
||||
|
||||
@property
|
||||
def device_class(self) -> BinarySensorDeviceClass | str | None:
|
||||
def device_class(self) -> BinarySensorDeviceClass | None:
|
||||
"""Return the class of this entity."""
|
||||
if hasattr(self, "_attr_device_class"):
|
||||
return self._attr_device_class
|
||||
|
@ -1,7 +1,12 @@
|
||||
"""Support for ONVIF binary sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from contextlib import suppress
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import STATE_ON
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
@ -61,13 +66,21 @@ class ONVIFBinarySensor(ONVIFBaseEntity, RestoreEntity, BinarySensorEntity):
|
||||
"""Initialize the ONVIF binary sensor."""
|
||||
self._attr_unique_id = uid
|
||||
if entry is not None:
|
||||
self._attr_device_class = entry.original_device_class
|
||||
if entry.original_device_class:
|
||||
with suppress(ValueError):
|
||||
self._attr_device_class = BinarySensorDeviceClass(
|
||||
entry.original_device_class
|
||||
)
|
||||
self._attr_entity_category = entry.entity_category
|
||||
self._attr_name = entry.name
|
||||
else:
|
||||
event = device.events.get_uid(uid)
|
||||
assert event
|
||||
self._attr_device_class = event.device_class
|
||||
if event.device_class:
|
||||
with suppress(ValueError):
|
||||
self._attr_device_class = BinarySensorDeviceClass(
|
||||
event.device_class
|
||||
)
|
||||
self._attr_entity_category = event.entity_category
|
||||
self._attr_entity_registry_enabled_default = event.entity_enabled
|
||||
self._attr_name = f"{device.name} {event.name}"
|
||||
|
@ -732,7 +732,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
|
||||
matches=[
|
||||
TypeHintMatch(
|
||||
function_name="device_class",
|
||||
return_type=["BinarySensorDeviceClass", "str", None],
|
||||
return_type=["BinarySensorDeviceClass", None],
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="is_on",
|
||||
|
Loading…
x
Reference in New Issue
Block a user