1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Handle empty strings for ESPHome UOMs (#96556)

This commit is contained in:
J. Nick Koston
2023-07-14 12:14:32 -10:00
committed by GitHub
parent 72458b6672
commit b77de2abaf
4 changed files with 70 additions and 4 deletions

View File

@@ -15,7 +15,7 @@ from homeassistant.components.number import (
DOMAIN as NUMBER_DOMAIN,
SERVICE_SET_VALUE,
)
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
from homeassistant.const import ATTR_ENTITY_ID, ATTR_UNIT_OF_MEASUREMENT, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
@@ -89,3 +89,36 @@ async def test_generic_number_nan(
state = hass.states.get("number.test_mynumber")
assert state is not None
assert state.state == STATE_UNKNOWN
async def test_generic_number_with_unit_of_measurement_as_empty_string(
hass: HomeAssistant,
mock_client: APIClient,
mock_generic_device_entry,
) -> None:
"""Test a generic number entity with nan state."""
entity_info = [
NumberInfo(
object_id="mynumber",
key=1,
name="my number",
unique_id="my_number",
max_value=100,
min_value=0,
step=1,
unit_of_measurement="",
mode=ESPHomeNumberMode.SLIDER,
)
]
states = [NumberState(key=1, state=42)]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
entity_info=entity_info,
user_service=user_service,
states=states,
)
state = hass.states.get("number.test_mynumber")
assert state is not None
assert state.state == "42"
assert ATTR_UNIT_OF_MEASUREMENT not in state.attributes