From f6d8868eb611a492293a2385fff69e6498abda37 Mon Sep 17 00:00:00 2001 From: Manu <4445816+tr4nt0r@users.noreply.github.com> Date: Wed, 23 Apr 2025 16:28:58 +0200 Subject: [PATCH] Fix some minor issues and nitpicks in ntfy integration (#143516) Fix nitpicks --- homeassistant/components/ntfy/__init__.py | 2 +- homeassistant/components/ntfy/config_flow.py | 6 +++-- homeassistant/components/ntfy/notify.py | 4 ++-- .../components/ntfy/quality_scale.yaml | 10 ++++---- homeassistant/components/ntfy/strings.json | 8 +++---- tests/components/ntfy/test_config_flow.py | 23 ++++++++----------- 6 files changed, 26 insertions(+), 27 deletions(-) diff --git a/homeassistant/components/ntfy/__init__.py b/homeassistant/components/ntfy/__init__.py index 76f09497c8d..f51e5d5a0e1 100644 --- a/homeassistant/components/ntfy/__init__.py +++ b/homeassistant/components/ntfy/__init__.py @@ -68,7 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: NtfyConfigEntry) -> bool return True -async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None: +async def _async_update_listener(hass: HomeAssistant, entry: NtfyConfigEntry) -> None: """Handle update.""" await hass.config_entries.async_reload(entry.entry_id) diff --git a/homeassistant/components/ntfy/config_flow.py b/homeassistant/components/ntfy/config_flow.py index 81ae688f847..cc4bcbf14ba 100644 --- a/homeassistant/components/ntfy/config_flow.py +++ b/homeassistant/components/ntfy/config_flow.py @@ -6,7 +6,7 @@ import logging import random import re import string -from typing import Any +from typing import TYPE_CHECKING, Any from aiontfy import Ntfy from aiontfy.exceptions import ( @@ -138,8 +138,10 @@ class NtfyConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.exception("Unexpected exception") errors["base"] = "unknown" else: + if TYPE_CHECKING: + assert url.host return self.async_create_entry( - title=url.host or "", + title=url.host, data={ CONF_URL: url.human_repr(), CONF_USERNAME: username, diff --git a/homeassistant/components/ntfy/notify.py b/homeassistant/components/ntfy/notify.py index ad47b8016e8..ac06e430346 100644 --- a/homeassistant/components/ntfy/notify.py +++ b/homeassistant/components/ntfy/notify.py @@ -46,6 +46,7 @@ class NtfyNotifyEntity(NotifyEntity): name=None, has_entity_name=True, ) + _attr_supported_features = NotifyEntityFeature.TITLE def __init__( self, @@ -57,8 +58,7 @@ class NtfyNotifyEntity(NotifyEntity): self._attr_unique_id = f"{config_entry.entry_id}_{subentry.subentry_id}_{self.entity_description.key}" self.topic = subentry.data[CONF_TOPIC] - self._attr_supported_features = NotifyEntityFeature.TITLE - self.device_info = DeviceInfo( + self._attr_device_info = DeviceInfo( entry_type=DeviceEntryType.SERVICE, manufacturer="ntfy LLC", model="ntfy", diff --git a/homeassistant/components/ntfy/quality_scale.yaml b/homeassistant/components/ntfy/quality_scale.yaml index 1b52f91d539..d476981cf6a 100644 --- a/homeassistant/components/ntfy/quality_scale.yaml +++ b/homeassistant/components/ntfy/quality_scale.yaml @@ -13,7 +13,9 @@ rules: config-flow-test-coverage: done config-flow: done dependency-transparency: done - docs-actions: done + docs-actions: + status: exempt + comment: integration has only entity actions docs-high-level-description: done docs-installation-instructions: done docs-removal-instructions: done @@ -46,7 +48,7 @@ rules: test-coverage: done # Gold - devices: todo + devices: done diagnostics: todo discovery-update-info: todo discovery: todo @@ -67,13 +69,13 @@ rules: comment: only one entity entity-translations: status: exempt - comment: the notify entity uses the topic as name, no translation required + comment: the notify entity uses the device name as entity name, no translation required exception-translations: done icon-translations: done reconfiguration-flow: todo repair-issues: status: exempt - comment: the integration has no repeairs + comment: the integration has no repairs stale-devices: status: exempt comment: only one device per entry, is deleted with the entry. diff --git a/homeassistant/components/ntfy/strings.json b/homeassistant/components/ntfy/strings.json index f50777d87ee..21b1fb22200 100644 --- a/homeassistant/components/ntfy/strings.json +++ b/homeassistant/components/ntfy/strings.json @@ -35,7 +35,7 @@ "unknown": "[%key:common::config_flow::error::unknown%]" }, "abort": { - "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" + "already_configured": "[%key:common::config_flow::abort::already_configured_service%]" } }, "config_subentries": { @@ -69,11 +69,11 @@ "error": { "publish_forbidden": "Publishing to this topic is forbidden", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", - "unknown": "[%key:common::config_flow::error::unknown%]" + "unknown": "[%key:common::config_flow::error::unknown%]", + "invalid_topic": "Invalid topic. Only letters, numbers, underscores, or dashes allowed." }, "abort": { - "already_configured": "Topic is already configured", - "invalid_topic": "Invalid topic. Only letters, numbers, underscores, or dashes allowed." + "already_configured": "Topic is already configured" } } }, diff --git a/tests/components/ntfy/test_config_flow.py b/tests/components/ntfy/test_config_flow.py index 27e5bd18720..9e719eff154 100644 --- a/tests/components/ntfy/test_config_flow.py +++ b/tests/components/ntfy/test_config_flow.py @@ -1,7 +1,7 @@ """Test the ntfy config flow.""" from typing import Any -from unittest.mock import AsyncMock, patch +from unittest.mock import AsyncMock from aiontfy.exceptions import ( NtfyException, @@ -56,20 +56,15 @@ async def test_form( result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER} ) - assert result["type"] == FlowResultType.FORM + assert result["type"] is FlowResultType.FORM assert result["errors"] == {} - with patch( - "homeassistant.components.ntfy.config_flow.Ntfy.publish", - return_value=True, - ): - result = await hass.config_entries.flow.async_configure( - result["flow_id"], - user_input, - ) - await hass.async_block_till_done() + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input, + ) - assert result["type"] == FlowResultType.CREATE_ENTRY + assert result["type"] is FlowResultType.CREATE_ENTRY assert result["title"] == "ntfy.sh" assert result["data"] == entry_data assert len(mock_setup_entry.mock_calls) == 1 @@ -116,7 +111,7 @@ async def test_form_errors( }, ) - assert result["type"] == FlowResultType.FORM + assert result["type"] is FlowResultType.FORM assert result["errors"] == {"base": error} mock_aiontfy.account.side_effect = None @@ -129,7 +124,7 @@ async def test_form_errors( ) await hass.async_block_till_done() - assert result["type"] == FlowResultType.CREATE_ENTRY + assert result["type"] is FlowResultType.CREATE_ENTRY assert result["title"] == "ntfy.sh" assert result["data"] == { CONF_URL: "https://ntfy.sh/",