From 7d52bceb1286be42215ab0a489d01a5d25a71ae7 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 22 Jun 2024 16:09:46 -0700 Subject: [PATCH] fix: usps_mail_delivered device_class (#923) * fix: usps_mail_delivered device_class * disable sensor by default * fix test --- custom_components/mail_and_packages/const.py | 2 +- tests/test_binary_sensor.py | 22 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/custom_components/mail_and_packages/const.py b/custom_components/mail_and_packages/const.py index de811caa..f196fd35 100644 --- a/custom_components/mail_and_packages/const.py +++ b/custom_components/mail_and_packages/const.py @@ -1133,7 +1133,7 @@ "usps_mail_delivered": BinarySensorEntityDescription( name="USPS Mail Delivered", key="usps_mail_delivered", - device_class=BinarySensorDeviceClass.UPDATE, + entity_registry_enabled_default=False, ), } diff --git a/tests/test_binary_sensor.py b/tests/test_binary_sensor.py index 1988608e..cab63aff 100644 --- a/tests/test_binary_sensor.py +++ b/tests/test_binary_sensor.py @@ -4,13 +4,14 @@ import pytest from pytest_homeassistant_custom_component.common import MockConfigEntry +from homeassistant.helpers import entity_registry as er from custom_components.mail_and_packages.const import DOMAIN from tests.const import FAKE_CONFIG_DATA @pytest.mark.asyncio -async def test_binary_sensor_no_updates(hass, mock_imap_no_email): +async def test_binary_sensor_no_updates(hass, mock_imap_no_email, entity_registry: er.EntityRegistry): entry = MockConfigEntry( domain=DOMAIN, title="imap.test.email", @@ -31,6 +32,25 @@ async def test_binary_sensor_no_updates(hass, mock_imap_no_email): assert state assert state.state == "off" + entity_entry = entity_registry.async_get("binary_sensor.usps_mail_delivered") + + assert entity_entry + assert entity_entry.disabled + assert entity_entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION + + updated_entry = entity_registry.async_update_entity( + entity_entry.entity_id, disabled_by=None + ) + assert updated_entry != entity_entry + assert updated_entry.disabled is False + + # reload the integration + await hass.config_entries.async_forward_entry_unload(entry, "binary_sensor") + await hass.config_entries.async_forward_entry_setups( + entry, ["binary_sensor"] + ) + await hass.async_block_till_done() + state = hass.states.get("binary_sensor.usps_mail_delivered") assert state assert state.state == "off"