mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Add new sensors to NextDNS integration (#76262)
* Add DNS-over-HTTP/3 sensors * Update tests
This commit is contained in:
parent
bd795be0e9
commit
753a3c0921
@ -107,6 +107,17 @@ SENSORS: tuple[NextDnsSensorEntityDescription, ...] = (
|
|||||||
state_class=SensorStateClass.TOTAL,
|
state_class=SensorStateClass.TOTAL,
|
||||||
value=lambda data: data.doh_queries,
|
value=lambda data: data.doh_queries,
|
||||||
),
|
),
|
||||||
|
NextDnsSensorEntityDescription[AnalyticsProtocols](
|
||||||
|
key="doh3_queries",
|
||||||
|
coordinator_type=ATTR_PROTOCOLS,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
icon="mdi:dns",
|
||||||
|
name="DNS-over-HTTP/3 queries",
|
||||||
|
native_unit_of_measurement="queries",
|
||||||
|
state_class=SensorStateClass.TOTAL,
|
||||||
|
value=lambda data: data.doh3_queries,
|
||||||
|
),
|
||||||
NextDnsSensorEntityDescription[AnalyticsProtocols](
|
NextDnsSensorEntityDescription[AnalyticsProtocols](
|
||||||
key="dot_queries",
|
key="dot_queries",
|
||||||
coordinator_type=ATTR_PROTOCOLS,
|
coordinator_type=ATTR_PROTOCOLS,
|
||||||
@ -162,6 +173,17 @@ SENSORS: tuple[NextDnsSensorEntityDescription, ...] = (
|
|||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
value=lambda data: data.doh_queries_ratio,
|
value=lambda data: data.doh_queries_ratio,
|
||||||
),
|
),
|
||||||
|
NextDnsSensorEntityDescription[AnalyticsProtocols](
|
||||||
|
key="doh3_queries_ratio",
|
||||||
|
coordinator_type=ATTR_PROTOCOLS,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
icon="mdi:dns",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
name="DNS-over-HTTP/3 queries ratio",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value=lambda data: data.doh3_queries_ratio,
|
||||||
|
),
|
||||||
NextDnsSensorEntityDescription[AnalyticsProtocols](
|
NextDnsSensorEntityDescription[AnalyticsProtocols](
|
||||||
key="dot_queries_ratio",
|
key="dot_queries_ratio",
|
||||||
coordinator_type=ATTR_PROTOCOLS,
|
coordinator_type=ATTR_PROTOCOLS,
|
||||||
|
@ -25,6 +25,7 @@ ENCRYPTION = AnalyticsEncryption(encrypted_queries=60, unencrypted_queries=40)
|
|||||||
IP_VERSIONS = AnalyticsIpVersions(ipv4_queries=90, ipv6_queries=10)
|
IP_VERSIONS = AnalyticsIpVersions(ipv4_queries=90, ipv6_queries=10)
|
||||||
PROTOCOLS = AnalyticsProtocols(
|
PROTOCOLS = AnalyticsProtocols(
|
||||||
doh_queries=20,
|
doh_queries=20,
|
||||||
|
doh3_queries=15,
|
||||||
doq_queries=10,
|
doq_queries=10,
|
||||||
dot_queries=30,
|
dot_queries=30,
|
||||||
tcp_queries=0,
|
tcp_queries=0,
|
||||||
|
@ -52,17 +52,17 @@ async def test_entry_diagnostics(
|
|||||||
}
|
}
|
||||||
assert result["protocols_coordinator_data"] == {
|
assert result["protocols_coordinator_data"] == {
|
||||||
"doh_queries": 20,
|
"doh_queries": 20,
|
||||||
"doh3_queries": 0,
|
"doh3_queries": 15,
|
||||||
"doq_queries": 10,
|
"doq_queries": 10,
|
||||||
"dot_queries": 30,
|
"dot_queries": 30,
|
||||||
"tcp_queries": 0,
|
"tcp_queries": 0,
|
||||||
"udp_queries": 40,
|
"udp_queries": 40,
|
||||||
"doh_queries_ratio": 20.0,
|
"doh_queries_ratio": 17.4,
|
||||||
"doh3_queries_ratio": 0.0,
|
"doh3_queries_ratio": 13.0,
|
||||||
"doq_queries_ratio": 10.0,
|
"doq_queries_ratio": 8.7,
|
||||||
"dot_queries_ratio": 30.0,
|
"dot_queries_ratio": 26.1,
|
||||||
"tcp_queries_ratio": 0.0,
|
"tcp_queries_ratio": 0.0,
|
||||||
"udp_queries_ratio": 40.0,
|
"udp_queries_ratio": 34.8,
|
||||||
}
|
}
|
||||||
assert result["settings_coordinator_data"] == settings
|
assert result["settings_coordinator_data"] == settings
|
||||||
assert result["status_coordinator_data"] == {
|
assert result["status_coordinator_data"] == {
|
||||||
|
@ -31,6 +31,13 @@ async def test_sensor(hass: HomeAssistant) -> None:
|
|||||||
suggested_object_id="fake_profile_dns_over_https_queries",
|
suggested_object_id="fake_profile_dns_over_https_queries",
|
||||||
disabled_by=None,
|
disabled_by=None,
|
||||||
)
|
)
|
||||||
|
registry.async_get_or_create(
|
||||||
|
SENSOR_DOMAIN,
|
||||||
|
DOMAIN,
|
||||||
|
"xyz12_doh3_queries",
|
||||||
|
suggested_object_id="fake_profile_dns_over_http_3_queries",
|
||||||
|
disabled_by=None,
|
||||||
|
)
|
||||||
registry.async_get_or_create(
|
registry.async_get_or_create(
|
||||||
SENSOR_DOMAIN,
|
SENSOR_DOMAIN,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -38,6 +45,13 @@ async def test_sensor(hass: HomeAssistant) -> None:
|
|||||||
suggested_object_id="fake_profile_dns_over_https_queries_ratio",
|
suggested_object_id="fake_profile_dns_over_https_queries_ratio",
|
||||||
disabled_by=None,
|
disabled_by=None,
|
||||||
)
|
)
|
||||||
|
registry.async_get_or_create(
|
||||||
|
SENSOR_DOMAIN,
|
||||||
|
DOMAIN,
|
||||||
|
"xyz12_doh3_queries_ratio",
|
||||||
|
suggested_object_id="fake_profile_dns_over_http_3_queries_ratio",
|
||||||
|
disabled_by=None,
|
||||||
|
)
|
||||||
registry.async_get_or_create(
|
registry.async_get_or_create(
|
||||||
SENSOR_DOMAIN,
|
SENSOR_DOMAIN,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -212,7 +226,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
state = hass.states.get("sensor.fake_profile_dns_over_https_queries_ratio")
|
state = hass.states.get("sensor.fake_profile_dns_over_https_queries_ratio")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "20.0"
|
assert state.state == "17.4"
|
||||||
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
||||||
|
|
||||||
@ -220,6 +234,26 @@ async def test_sensor(hass: HomeAssistant) -> None:
|
|||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == "xyz12_doh_queries_ratio"
|
assert entry.unique_id == "xyz12_doh_queries_ratio"
|
||||||
|
|
||||||
|
state = hass.states.get("sensor.fake_profile_dns_over_http_3_queries")
|
||||||
|
assert state
|
||||||
|
assert state.state == "15"
|
||||||
|
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.TOTAL
|
||||||
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "queries"
|
||||||
|
|
||||||
|
entry = registry.async_get("sensor.fake_profile_dns_over_http_3_queries")
|
||||||
|
assert entry
|
||||||
|
assert entry.unique_id == "xyz12_doh3_queries"
|
||||||
|
|
||||||
|
state = hass.states.get("sensor.fake_profile_dns_over_http_3_queries_ratio")
|
||||||
|
assert state
|
||||||
|
assert state.state == "13.0"
|
||||||
|
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
||||||
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
||||||
|
|
||||||
|
entry = registry.async_get("sensor.fake_profile_dns_over_http_3_queries_ratio")
|
||||||
|
assert entry
|
||||||
|
assert entry.unique_id == "xyz12_doh3_queries_ratio"
|
||||||
|
|
||||||
state = hass.states.get("sensor.fake_profile_dns_over_quic_queries")
|
state = hass.states.get("sensor.fake_profile_dns_over_quic_queries")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "10"
|
assert state.state == "10"
|
||||||
@ -232,7 +266,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
state = hass.states.get("sensor.fake_profile_dns_over_quic_queries_ratio")
|
state = hass.states.get("sensor.fake_profile_dns_over_quic_queries_ratio")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "10.0"
|
assert state.state == "8.7"
|
||||||
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
||||||
|
|
||||||
@ -252,7 +286,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
state = hass.states.get("sensor.fake_profile_dns_over_tls_queries_ratio")
|
state = hass.states.get("sensor.fake_profile_dns_over_tls_queries_ratio")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "30.0"
|
assert state.state == "26.1"
|
||||||
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
||||||
|
|
||||||
@ -382,7 +416,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
state = hass.states.get("sensor.fake_profile_udp_queries_ratio")
|
state = hass.states.get("sensor.fake_profile_udp_queries_ratio")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "40.0"
|
assert state.state == "34.8"
|
||||||
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user