mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Strictly type binary_sensor.py. (#56376)
This commit is contained in:
parent
5c19368ce3
commit
6b6e26c96d
@ -1,11 +1,13 @@
|
||||
"""Support for Modbus Coil and Discrete Input sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from homeassistant.const import CONF_BINARY_SENSORS, CONF_NAME, STATE_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
@ -19,9 +21,9 @@ _LOGGER = logging.getLogger(__name__)
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
):
|
||||
) -> None:
|
||||
"""Set up the Modbus binary sensors."""
|
||||
sensors = []
|
||||
|
||||
@ -38,14 +40,14 @@ async def async_setup_platform(
|
||||
class ModbusBinarySensor(BasePlatform, RestoreEntity, BinarySensorEntity):
|
||||
"""Modbus binary sensor."""
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity which will be added."""
|
||||
await self.async_base_added_to_hass()
|
||||
state = await self.async_get_last_state()
|
||||
if state:
|
||||
self._attr_is_on = state.state == STATE_ON
|
||||
|
||||
async def async_update(self, now=None):
|
||||
async def async_update(self, now: datetime | None = None) -> None:
|
||||
"""Update the state of the sensor."""
|
||||
|
||||
# do not allow multiple active calls to the same platform
|
||||
|
Loading…
x
Reference in New Issue
Block a user