|
23 | 23 | from homeassistant.const import ( |
24 | 24 | ATTR_DEVICE_CLASS, |
25 | 25 | ATTR_ENTITY_ID, |
| 26 | + ATTR_FRIENDLY_NAME, |
26 | 27 | ATTR_UNIT_OF_MEASUREMENT, |
27 | 28 | PERCENTAGE, |
28 | 29 | STATE_UNAVAILABLE, |
|
40 | 41 | from homeassistant.setup import async_setup_component |
41 | 42 |
|
42 | 43 | from . import ( |
| 44 | + MOCK_MAC, |
43 | 45 | init_integration, |
44 | 46 | mock_polling_rpc_update, |
45 | 47 | mock_rest_update, |
@@ -1585,3 +1587,45 @@ async def test_rpc_switch_no_returned_energy_sensor( |
1585 | 1587 | await init_integration(hass, 3) |
1586 | 1588 |
|
1587 | 1589 | 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