Strictly type binary_sensor.py. (#56376)

This commit is contained in:
jan iversen 2021-09-18 21:54:11 +02:00 committed by GitHub
parent 5c19368ce3
commit 6b6e26c96d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,11 +1,13 @@
"""Support for Modbus Coil and Discrete Input sensors.""" """Support for Modbus Coil and Discrete Input sensors."""
from __future__ import annotations from __future__ import annotations
from datetime import datetime
import logging import logging
from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.const import CONF_BINARY_SENSORS, CONF_NAME, STATE_ON from homeassistant.const import CONF_BINARY_SENSORS, CONF_NAME, STATE_ON
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -19,9 +21,9 @@ _LOGGER = logging.getLogger(__name__)
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities, async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
): ) -> None:
"""Set up the Modbus binary sensors.""" """Set up the Modbus binary sensors."""
sensors = [] sensors = []
@ -38,14 +40,14 @@ async def async_setup_platform(
class ModbusBinarySensor(BasePlatform, RestoreEntity, BinarySensorEntity): class ModbusBinarySensor(BasePlatform, RestoreEntity, BinarySensorEntity):
"""Modbus binary sensor.""" """Modbus binary sensor."""
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Handle entity which will be added.""" """Handle entity which will be added."""
await self.async_base_added_to_hass() await self.async_base_added_to_hass()
state = await self.async_get_last_state() state = await self.async_get_last_state()
if state: if state:
self._attr_is_on = state.state == STATE_ON 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.""" """Update the state of the sensor."""
# do not allow multiple active calls to the same platform # do not allow multiple active calls to the same platform