From 525afb729cf998723b21ac40bd3042ed1b33de62 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 25 Aug 2022 17:45:27 -0400 Subject: [PATCH] Disable some upnp entities by default (#77330) --- homeassistant/components/upnp/binary_sensor.py | 4 +++- homeassistant/components/upnp/sensor.py | 10 ++++++++++ tests/components/upnp/conftest.py | 10 +++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/upnp/binary_sensor.py b/homeassistant/components/upnp/binary_sensor.py index d49bbddf996..7da7f187882 100644 --- a/homeassistant/components/upnp/binary_sensor.py +++ b/homeassistant/components/upnp/binary_sensor.py @@ -7,6 +7,7 @@ from homeassistant.components.binary_sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import UpnpBinarySensorEntityDescription, UpnpDataUpdateCoordinator, UpnpEntity @@ -16,6 +17,8 @@ BINARYSENSOR_ENTITY_DESCRIPTIONS: tuple[UpnpBinarySensorEntityDescription, ...] UpnpBinarySensorEntityDescription( key=WAN_STATUS, name="wan status", + device_class=BinarySensorDeviceClass.CONNECTIVITY, + entity_category=EntityCategory.DIAGNOSTIC, ), ) @@ -44,7 +47,6 @@ class UpnpStatusBinarySensor(UpnpEntity, BinarySensorEntity): """Class for UPnP/IGD binary sensors.""" entity_description: UpnpBinarySensorEntityDescription - _attr_device_class = BinarySensorDeviceClass.CONNECTIVITY def __init__( self, diff --git a/homeassistant/components/upnp/sensor.py b/homeassistant/components/upnp/sensor.py index 908a5b53940..53a918ba053 100644 --- a/homeassistant/components/upnp/sensor.py +++ b/homeassistant/components/upnp/sensor.py @@ -5,6 +5,7 @@ from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import DATA_BYTES, DATA_RATE_KIBIBYTES_PER_SECOND, TIME_SECONDS from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import UpnpDataUpdateCoordinator, UpnpEntity, UpnpSensorEntityDescription @@ -31,6 +32,7 @@ RAW_SENSORS: tuple[UpnpSensorEntityDescription, ...] = ( icon="mdi:server-network", native_unit_of_measurement=DATA_BYTES, format="d", + entity_registry_enabled_default=False, ), UpnpSensorEntityDescription( key=BYTES_SENT, @@ -38,6 +40,7 @@ RAW_SENSORS: tuple[UpnpSensorEntityDescription, ...] = ( icon="mdi:server-network", native_unit_of_measurement=DATA_BYTES, format="d", + entity_registry_enabled_default=False, ), UpnpSensorEntityDescription( key=PACKETS_RECEIVED, @@ -45,6 +48,7 @@ RAW_SENSORS: tuple[UpnpSensorEntityDescription, ...] = ( icon="mdi:server-network", native_unit_of_measurement=DATA_PACKETS, format="d", + entity_registry_enabled_default=False, ), UpnpSensorEntityDescription( key=PACKETS_SENT, @@ -52,6 +56,7 @@ RAW_SENSORS: tuple[UpnpSensorEntityDescription, ...] = ( icon="mdi:server-network", native_unit_of_measurement=DATA_PACKETS, format="d", + entity_registry_enabled_default=False, ), UpnpSensorEntityDescription( key=ROUTER_IP, @@ -65,11 +70,14 @@ RAW_SENSORS: tuple[UpnpSensorEntityDescription, ...] = ( native_unit_of_measurement=TIME_SECONDS, entity_registry_enabled_default=False, format="d", + entity_category=EntityCategory.DIAGNOSTIC, ), UpnpSensorEntityDescription( key=WAN_STATUS, name="wan status", icon="mdi:server-network", + entity_category=EntityCategory.DIAGNOSTIC, + entity_registry_enabled_default=False, ), ) @@ -97,6 +105,7 @@ DERIVED_SENSORS: tuple[UpnpSensorEntityDescription, ...] = ( icon="mdi:server-network", native_unit_of_measurement=DATA_RATE_PACKETS_PER_SECOND, format=".1f", + entity_registry_enabled_default=False, ), UpnpSensorEntityDescription( key=PACKETS_SENT, @@ -105,6 +114,7 @@ DERIVED_SENSORS: tuple[UpnpSensorEntityDescription, ...] = ( icon="mdi:server-network", native_unit_of_measurement=DATA_RATE_PACKETS_PER_SECOND, format=".1f", + entity_registry_enabled_default=False, ), ) diff --git a/tests/components/upnp/conftest.py b/tests/components/upnp/conftest.py index 0d3e869db35..e7cd24d0c7c 100644 --- a/tests/components/upnp/conftest.py +++ b/tests/components/upnp/conftest.py @@ -1,7 +1,7 @@ """Configuration for SSDP tests.""" from __future__ import annotations -from unittest.mock import AsyncMock, MagicMock, create_autospec, patch +from unittest.mock import AsyncMock, MagicMock, PropertyMock, create_autospec, patch from urllib.parse import urlparse from async_upnp_client.client import UpnpDevice @@ -184,7 +184,11 @@ async def mock_config_entry( # Load config_entry. entry.add_to_hass(hass) - await hass.config_entries.async_setup(entry.entry_id) - await hass.async_block_till_done() + with patch( + "homeassistant.helpers.entity.Entity.entity_registry_enabled_default", + PropertyMock(return_value=True), + ): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() yield entry