Do not fail MQTT setup if numbers configured via yaml can't be validated (#102316)
Add number
This commit is contained in:
parent
f1eb28b7ac
commit
12c4a10cfc
3 changed files with 15 additions and 29 deletions
|
@ -17,7 +17,6 @@ from homeassistant.helpers import config_validation as cv
|
|||
from . import (
|
||||
cover as cover_platform,
|
||||
event as event_platform,
|
||||
number as number_platform,
|
||||
sensor as sensor_platform,
|
||||
)
|
||||
from .const import (
|
||||
|
@ -56,10 +55,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
|||
Platform.LAWN_MOWER.value: vol.All(cv.ensure_list, [dict]),
|
||||
Platform.LIGHT.value: vol.All(cv.ensure_list, [dict]),
|
||||
Platform.LOCK.value: vol.All(cv.ensure_list, [dict]),
|
||||
Platform.NUMBER.value: vol.All(
|
||||
cv.ensure_list,
|
||||
[number_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.NUMBER.value: vol.All(cv.ensure_list, [dict]),
|
||||
Platform.SCENE.value: vol.All(cv.ensure_list, [dict]),
|
||||
Platform.SELECT.value: vol.All(cv.ensure_list, [dict]),
|
||||
Platform.SENSOR.value: vol.All(
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
import functools
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -28,7 +27,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from . import subscription
|
||||
from .config import MQTT_RW_SCHEMA
|
||||
|
@ -45,7 +44,7 @@ from .debug_info import log_messages
|
|||
from .mixins import (
|
||||
MQTT_ENTITY_COMMON_SCHEMA,
|
||||
MqttEntity,
|
||||
async_setup_entry_helper,
|
||||
async_mqtt_entry_helper,
|
||||
write_state_on_attr_change,
|
||||
)
|
||||
from .models import (
|
||||
|
@ -118,21 +117,15 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT number through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
await async_mqtt_entry_helper(
|
||||
hass,
|
||||
config_entry,
|
||||
MqttNumber,
|
||||
number.DOMAIN,
|
||||
async_add_entities,
|
||||
DISCOVERY_SCHEMA,
|
||||
PLATFORM_SCHEMA_MODERN,
|
||||
)
|
||||
await async_setup_entry_helper(hass, number.DOMAIN, setup, DISCOVERY_SCHEMA)
|
||||
|
||||
|
||||
async def _async_setup_entity(
|
||||
hass: HomeAssistant,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
config: ConfigType,
|
||||
config_entry: ConfigEntry,
|
||||
discovery_data: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the MQTT number."""
|
||||
async_add_entities([MqttNumber(hass, config, config_entry, discovery_data)])
|
||||
|
||||
|
||||
class MqttNumber(MqttEntity, RestoreNumber):
|
||||
|
|
|
@ -826,8 +826,7 @@ async def test_invalid_min_max_attributes(
|
|||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test invalid min/max attributes."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry()
|
||||
assert await mqtt_mock_entry()
|
||||
assert f"'{CONF_MAX}' must be > '{CONF_MIN}'" in caplog.text
|
||||
|
||||
|
||||
|
@ -948,11 +947,9 @@ async def test_invalid_mode(
|
|||
valid: bool,
|
||||
) -> None:
|
||||
"""Test invalid mode."""
|
||||
if valid:
|
||||
await mqtt_mock_entry()
|
||||
return
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry()
|
||||
await mqtt_mock_entry()
|
||||
state = hass.states.get("number.test_number")
|
||||
assert (state is not None) == valid
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
Loading…
Add table
Reference in a new issue