Remove ESPHome legacy entity naming (#123436)
* Remove ESPHome legacy entity naming * Update test entity_ids to use sanitized name instead of object_id
This commit is contained in:
parent
f8e1c2cfd4
commit
84d6f5ed07
23 changed files with 275 additions and 322 deletions
|
@ -62,35 +62,35 @@ async def test_generic_numeric_sensor(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "50"
|
||||
|
||||
# Test updating state
|
||||
mock_device.set_state(SensorState(key=1, state=60))
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "60"
|
||||
|
||||
# Test sending the same state again
|
||||
mock_device.set_state(SensorState(key=1, state=60))
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "60"
|
||||
|
||||
# Test we can still update after the same state
|
||||
mock_device.set_state(SensorState(key=1, state=70))
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "70"
|
||||
|
||||
# Test invalid data from the underlying api does not crash us
|
||||
mock_device.set_state(SensorState(key=1, state=object()))
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "70"
|
||||
|
||||
|
@ -120,11 +120,11 @@ async def test_generic_numeric_sensor_with_entity_category_and_icon(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "50"
|
||||
assert state.attributes[ATTR_ICON] == "mdi:leaf"
|
||||
entry = entity_registry.async_get("sensor.test_mysensor")
|
||||
entry = entity_registry.async_get("sensor.test_my_sensor")
|
||||
assert entry is not None
|
||||
# Note that ESPHome includes the EntityInfo type in the unique id
|
||||
# as this is not a 1:1 mapping to the entity platform (ie. text_sensor)
|
||||
|
@ -158,11 +158,11 @@ async def test_generic_numeric_sensor_state_class_measurement(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "50"
|
||||
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
||||
entry = entity_registry.async_get("sensor.test_mysensor")
|
||||
entry = entity_registry.async_get("sensor.test_my_sensor")
|
||||
assert entry is not None
|
||||
# Note that ESPHome includes the EntityInfo type in the unique id
|
||||
# as this is not a 1:1 mapping to the entity platform (ie. text_sensor)
|
||||
|
@ -193,7 +193,7 @@ async def test_generic_numeric_sensor_device_class_timestamp(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "2023-06-22T18:43:52+00:00"
|
||||
|
||||
|
@ -222,7 +222,7 @@ async def test_generic_numeric_sensor_legacy_last_reset_convert(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "50"
|
||||
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.TOTAL_INCREASING
|
||||
|
@ -248,7 +248,7 @@ async def test_generic_numeric_sensor_no_state(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
@ -273,7 +273,7 @@ async def test_generic_numeric_sensor_nan_state(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
@ -298,7 +298,7 @@ async def test_generic_numeric_sensor_missing_state(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
@ -325,7 +325,7 @@ async def test_generic_text_sensor(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "i am a teapot"
|
||||
|
||||
|
@ -350,7 +350,7 @@ async def test_generic_text_sensor_missing_state(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
@ -378,7 +378,7 @@ async def test_generic_text_sensor_device_class_timestamp(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "2023-06-22T18:43:52+00:00"
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.TIMESTAMP
|
||||
|
@ -407,7 +407,7 @@ async def test_generic_text_sensor_device_class_date(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "2023-06-22"
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.DATE
|
||||
|
@ -434,7 +434,7 @@ async def test_generic_numeric_sensor_empty_string_uom(
|
|||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("sensor.test_mysensor")
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
assert state is not None
|
||||
assert state.state == "123"
|
||||
assert ATTR_UNIT_OF_MEASUREMENT not in state.attributes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue