Strictly type sensor.py. (#56377)
This commit is contained in:
parent
b05c1b516e
commit
ddd31951bc
1 changed files with 6 additions and 4 deletions
|
@ -1,12 +1,14 @@
|
|||
"""Support for Modbus Register sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.sensor import CONF_STATE_CLASS, SensorEntity
|
||||
from homeassistant.const import CONF_NAME, CONF_SENSORS, CONF_UNIT_OF_MEASUREMENT
|
||||
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
|
||||
|
||||
|
@ -21,9 +23,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 sensors."""
|
||||
sensors = []
|
||||
|
||||
|
@ -50,14 +52,14 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreEntity, SensorEntity):
|
|||
self._attr_native_unit_of_measurement = entry.get(CONF_UNIT_OF_MEASUREMENT)
|
||||
self._attr_state_class = entry.get(CONF_STATE_CLASS)
|
||||
|
||||
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_native_value = state.state
|
||||
|
||||
async def async_update(self, now=None):
|
||||
async def async_update(self, now: datetime | None = None) -> None:
|
||||
"""Update the state of the sensor."""
|
||||
# remark "now" is a dummy parameter to avoid problems with
|
||||
# async_track_time_interval
|
||||
|
|
Loading…
Add table
Reference in a new issue