mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Strictly type modbus __init__.py, validator.py (#56378)
* strictly type: __init__.py, validator.py
This commit is contained in:
parent
518c99c8b7
commit
c7c789f618
@ -2,6 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import cast
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@ -46,6 +47,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
ATTR_ADDRESS,
|
||||
@ -378,10 +380,10 @@ SERVICE_STOP_START_SCHEMA = vol.Schema(
|
||||
|
||||
def get_hub(hass: HomeAssistant, name: str) -> ModbusHub:
|
||||
"""Return modbus hub with name."""
|
||||
return hass.data[DOMAIN][name]
|
||||
return cast(ModbusHub, hass.data[DOMAIN][name])
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Modbus component."""
|
||||
return await async_modbus_setup(
|
||||
hass,
|
||||
|
@ -84,7 +84,7 @@ DEFAULT_STRUCT_FORMAT = {
|
||||
}
|
||||
|
||||
|
||||
def struct_validator(config):
|
||||
def struct_validator(config: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Sensor schema validator."""
|
||||
|
||||
data_type = config[CONF_DATA_TYPE]
|
||||
@ -154,13 +154,11 @@ def number_validator(value: Any) -> int | float:
|
||||
return value
|
||||
|
||||
try:
|
||||
value = int(value)
|
||||
return value
|
||||
return int(value)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
try:
|
||||
value = float(value)
|
||||
return value
|
||||
return float(value)
|
||||
except (TypeError, ValueError) as err:
|
||||
raise vol.Invalid(f"invalid number {value}") from err
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user