Define binary_sensor entity attribute as class variables (#50940)
This commit is contained in:
parent
f7bc456bd2
commit
d3bc2bc47f
1 changed files with 6 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
"""Component to interface with binary sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
@ -12,6 +13,7 @@ from homeassistant.helpers.config_validation import ( # noqa: F401
|
|||
)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
# mypy: allow-untyped-defs, no-check-untyped-defs
|
||||
|
||||
|
@ -147,21 +149,18 @@ async def async_unload_entry(hass, entry):
|
|||
class BinarySensorEntity(Entity):
|
||||
"""Represent a binary sensor."""
|
||||
|
||||
_attr_is_on: bool | None = None
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if the binary sensor is on."""
|
||||
return None
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def state(self) -> StateType:
|
||||
"""Return the state of the binary sensor."""
|
||||
return STATE_ON if self.is_on else STATE_OFF
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
||||
return None
|
||||
|
||||
|
||||
class BinarySensorDevice(BinarySensorEntity):
|
||||
"""Represent a binary sensor (for backwards compatibility)."""
|
||||
|
|
Loading…
Add table
Reference in a new issue