From ac9c08f52c29cac1c2563a27421f9baadab9ff6e Mon Sep 17 00:00:00 2001 From: Steven Looman Date: Thu, 4 Jul 2024 09:07:41 +0200 Subject: [PATCH] Add port mapping entry count sensor to upnp (#120263) Add port mapping entry count sensor --- homeassistant/components/upnp/const.py | 1 + homeassistant/components/upnp/device.py | 5 +++++ homeassistant/components/upnp/icons.json | 3 +++ homeassistant/components/upnp/sensor.py | 7 +++++++ homeassistant/components/upnp/strings.json | 3 +++ 5 files changed, 19 insertions(+) diff --git a/homeassistant/components/upnp/const.py b/homeassistant/components/upnp/const.py index e7b44329546..5d68a83d4d4 100644 --- a/homeassistant/components/upnp/const.py +++ b/homeassistant/components/upnp/const.py @@ -21,6 +21,7 @@ TIMESTAMP = "timestamp" DATA_PACKETS = "packets" DATA_RATE_PACKETS_PER_SECOND = f"{DATA_PACKETS}/{UnitOfTime.SECONDS}" WAN_STATUS = "wan_status" +PORT_MAPPING_NUMBER_OF_ENTRIES_IPV4 = "port_mapping_number_of_entries" ROUTER_IP = "ip" ROUTER_UPTIME = "uptime" CONFIG_ENTRY_ST = "st" diff --git a/homeassistant/components/upnp/device.py b/homeassistant/components/upnp/device.py index e819a16f2d2..923d4828879 100644 --- a/homeassistant/components/upnp/device.py +++ b/homeassistant/components/upnp/device.py @@ -30,6 +30,7 @@ from .const import ( PACKETS_PER_SEC_SENT, PACKETS_RECEIVED, PACKETS_SENT, + PORT_MAPPING_NUMBER_OF_ENTRIES_IPV4, ROUTER_IP, ROUTER_UPTIME, TIMESTAMP, @@ -48,6 +49,7 @@ TYPE_STATE_ITEM_MAPPING = { ROUTER_IP: IgdStateItem.EXTERNAL_IP_ADDRESS, ROUTER_UPTIME: IgdStateItem.UPTIME, WAN_STATUS: IgdStateItem.CONNECTION_STATUS, + PORT_MAPPING_NUMBER_OF_ENTRIES_IPV4: IgdStateItem.PORT_MAPPING_NUMBER_OF_ENTRIES, } @@ -254,4 +256,7 @@ class Device: KIBIBYTES_PER_SEC_SENT: igd_state.kibibytes_per_sec_sent, PACKETS_PER_SEC_RECEIVED: igd_state.packets_per_sec_received, PACKETS_PER_SEC_SENT: igd_state.packets_per_sec_sent, + PORT_MAPPING_NUMBER_OF_ENTRIES_IPV4: get_value( + igd_state.port_mapping_number_of_entries + ), } diff --git a/homeassistant/components/upnp/icons.json b/homeassistant/components/upnp/icons.json index 1d4ebaf183d..b6451f0fca8 100644 --- a/homeassistant/components/upnp/icons.json +++ b/homeassistant/components/upnp/icons.json @@ -33,6 +33,9 @@ }, "packet_upload_speed": { "default": "mdi:server-network" + }, + "port_mapping_number_of_entries_ipv4": { + "default": "mdi:server-network" } } } diff --git a/homeassistant/components/upnp/sensor.py b/homeassistant/components/upnp/sensor.py index d72dce55eab..d6da50c877d 100644 --- a/homeassistant/components/upnp/sensor.py +++ b/homeassistant/components/upnp/sensor.py @@ -33,6 +33,7 @@ from .const import ( PACKETS_PER_SEC_SENT, PACKETS_RECEIVED, PACKETS_SENT, + PORT_MAPPING_NUMBER_OF_ENTRIES_IPV4, ROUTER_IP, ROUTER_UPTIME, WAN_STATUS, @@ -99,6 +100,12 @@ SENSOR_DESCRIPTIONS: tuple[UpnpSensorEntityDescription, ...] = ( entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, ), + UpnpSensorEntityDescription( + key=PORT_MAPPING_NUMBER_OF_ENTRIES_IPV4, + translation_key="port_mapping_number_of_entries_ipv4", + entity_category=EntityCategory.DIAGNOSTIC, + entity_registry_enabled_default=False, + ), UpnpSensorEntityDescription( key=BYTES_RECEIVED, translation_key="download_speed", diff --git a/homeassistant/components/upnp/strings.json b/homeassistant/components/upnp/strings.json index 7ce1798c351..bb95978c8dc 100644 --- a/homeassistant/components/upnp/strings.json +++ b/homeassistant/components/upnp/strings.json @@ -65,6 +65,9 @@ }, "wan_status": { "name": "WAN status" + }, + "port_mapping_number_of_entries_ipv4": { + "name": "Number of port mapping entries (IPv4)" } } }