Skip to content

Commit 766ddfa

Browse files
bieniufrenck
authored andcommitted
Fix Shelly entity names for gen1 sleeping devices (home-assistant#147019)
1 parent 5ea6cb3 commit 766ddfa

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

homeassistant/components/shelly/entity.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ def __init__(
653653
)
654654
elif entry is not None:
655655
self._attr_unique_id = entry.unique_id
656-
self._attr_name = cast(str, entry.original_name)
657656

658657
@callback
659658
def _update_callback(self) -> None:

tests/components/shelly/test_sensor.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from homeassistant.const import (
2424
ATTR_DEVICE_CLASS,
2525
ATTR_ENTITY_ID,
26+
ATTR_FRIENDLY_NAME,
2627
ATTR_UNIT_OF_MEASUREMENT,
2728
PERCENTAGE,
2829
STATE_UNAVAILABLE,
@@ -40,6 +41,7 @@
4041
from homeassistant.setup import async_setup_component
4142

4243
from . import (
44+
MOCK_MAC,
4345
init_integration,
4446
mock_polling_rpc_update,
4547
mock_rest_update,
@@ -1585,3 +1587,45 @@ async def test_rpc_switch_no_returned_energy_sensor(
15851587
await init_integration(hass, 3)
15861588

15871589
assert hass.states.get("sensor.test_name_test_switch_0_returned_energy") is None
1590+
1591+
1592+
async def test_block_friendly_name_sleeping_sensor(
1593+
hass: HomeAssistant,
1594+
mock_block_device: Mock,
1595+
device_registry: DeviceRegistry,
1596+
entity_registry: EntityRegistry,
1597+
monkeypatch: pytest.MonkeyPatch,
1598+
) -> None:
1599+
"""Test friendly name for restored sleeping sensor."""
1600+
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
1601+
device = register_device(device_registry, entry)
1602+
1603+
entity = entity_registry.async_get_or_create(
1604+
SENSOR_DOMAIN,
1605+
DOMAIN,
1606+
f"{MOCK_MAC}-sensor_0-temp",
1607+
suggested_object_id="test_name_temperature",
1608+
original_name="Test name temperature",
1609+
disabled_by=None,
1610+
config_entry=entry,
1611+
device_id=device.id,
1612+
)
1613+
1614+
# Old name, the word "temperature" starts with a lower case letter
1615+
assert entity.original_name == "Test name temperature"
1616+
1617+
await hass.config_entries.async_setup(entry.entry_id)
1618+
await hass.async_block_till_done()
1619+
1620+
assert (state := hass.states.get(entity.entity_id))
1621+
1622+
# New name, the word "temperature" starts with a capital letter
1623+
assert state.attributes[ATTR_FRIENDLY_NAME] == "Test name Temperature"
1624+
1625+
# Make device online
1626+
monkeypatch.setattr(mock_block_device, "initialized", True)
1627+
mock_block_device.mock_online()
1628+
await hass.async_block_till_done(wait_background_tasks=True)
1629+
1630+
assert (state := hass.states.get(entity.entity_id))
1631+
assert state.attributes[ATTR_FRIENDLY_NAME] == "Test name Temperature"

0 commit comments

Comments
 (0)