mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +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
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import cast
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -46,6 +47,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_ADDRESS,
|
ATTR_ADDRESS,
|
||||||
@ -378,10 +380,10 @@ SERVICE_STOP_START_SCHEMA = vol.Schema(
|
|||||||
|
|
||||||
def get_hub(hass: HomeAssistant, name: str) -> ModbusHub:
|
def get_hub(hass: HomeAssistant, name: str) -> ModbusHub:
|
||||||
"""Return modbus hub with name."""
|
"""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."""
|
"""Set up Modbus component."""
|
||||||
return await async_modbus_setup(
|
return await async_modbus_setup(
|
||||||
hass,
|
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."""
|
"""Sensor schema validator."""
|
||||||
|
|
||||||
data_type = config[CONF_DATA_TYPE]
|
data_type = config[CONF_DATA_TYPE]
|
||||||
@ -154,13 +154,11 @@ def number_validator(value: Any) -> int | float:
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
try:
|
try:
|
||||||
value = int(value)
|
return int(value)
|
||||||
return value
|
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
value = float(value)
|
return float(value)
|
||||||
return value
|
|
||||||
except (TypeError, ValueError) as err:
|
except (TypeError, ValueError) as err:
|
||||||
raise vol.Invalid(f"invalid number {value}") from err
|
raise vol.Invalid(f"invalid number {value}") from err
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user