From d3bc2bc47f30cb6f33aca6126a06b3ad102b8351 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 22 May 2021 18:20:34 +0200 Subject: [PATCH] Define binary_sensor entity attribute as class variables (#50940) --- homeassistant/components/binary_sensor/__init__.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/binary_sensor/__init__.py b/homeassistant/components/binary_sensor/__init__.py index f022509f9de..9bf53407b38 100644 --- a/homeassistant/components/binary_sensor/__init__.py +++ b/homeassistant/components/binary_sensor/__init__.py @@ -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)."""