ESPHome enable static type checking (#52348)
This commit is contained in:
parent
9b2107b71f
commit
4d16cda957
16 changed files with 364 additions and 304 deletions
|
@ -4,11 +4,16 @@ from __future__ import annotations
|
|||
from aioesphomeapi import BinarySensorInfo, BinarySensorState
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import EsphomeEntity, platform_async_setup_entry
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up ESPHome binary sensors based on a config entry."""
|
||||
await platform_async_setup_entry(
|
||||
hass,
|
||||
|
@ -21,17 +26,15 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
)
|
||||
|
||||
|
||||
class EsphomeBinarySensor(EsphomeEntity, BinarySensorEntity):
|
||||
# Pylint gets confused with the EsphomeEntity generics -> let mypy handle member checking
|
||||
# pylint: disable=no-member
|
||||
|
||||
|
||||
class EsphomeBinarySensor(
|
||||
EsphomeEntity[BinarySensorInfo, BinarySensorState], BinarySensorEntity
|
||||
):
|
||||
"""A binary sensor implementation for ESPHome."""
|
||||
|
||||
@property
|
||||
def _static_info(self) -> BinarySensorInfo:
|
||||
return super()._static_info
|
||||
|
||||
@property
|
||||
def _state(self) -> BinarySensorState | None:
|
||||
return super()._state
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if the binary sensor is on."""
|
||||
|
@ -39,7 +42,7 @@ class EsphomeBinarySensor(EsphomeEntity, BinarySensorEntity):
|
|||
# Status binary sensors indicated connected state.
|
||||
# So in their case what's usually _availability_ is now state
|
||||
return self._entry_data.available
|
||||
if self._state is None:
|
||||
if not self._has_state:
|
||||
return None
|
||||
if self._state.missing_state:
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue