Fix some minor issues and nitpicks in ntfy integration (#143516)

Fix nitpicks
This commit is contained in:
Manu 2025-04-23 16:28:58 +02:00 committed by GitHub
parent 253cc377b4
commit f6d8868eb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 26 additions and 27 deletions

View File

@ -68,7 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: NtfyConfigEntry) -> bool
return True return True
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None: async def _async_update_listener(hass: HomeAssistant, entry: NtfyConfigEntry) -> None:
"""Handle update.""" """Handle update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View File

@ -6,7 +6,7 @@ import logging
import random import random
import re import re
import string import string
from typing import Any from typing import TYPE_CHECKING, Any
from aiontfy import Ntfy from aiontfy import Ntfy
from aiontfy.exceptions import ( from aiontfy.exceptions import (
@ -138,8 +138,10 @@ class NtfyConfigFlow(ConfigFlow, domain=DOMAIN):
_LOGGER.exception("Unexpected exception") _LOGGER.exception("Unexpected exception")
errors["base"] = "unknown" errors["base"] = "unknown"
else: else:
if TYPE_CHECKING:
assert url.host
return self.async_create_entry( return self.async_create_entry(
title=url.host or "", title=url.host,
data={ data={
CONF_URL: url.human_repr(), CONF_URL: url.human_repr(),
CONF_USERNAME: username, CONF_USERNAME: username,

View File

@ -46,6 +46,7 @@ class NtfyNotifyEntity(NotifyEntity):
name=None, name=None,
has_entity_name=True, has_entity_name=True,
) )
_attr_supported_features = NotifyEntityFeature.TITLE
def __init__( def __init__(
self, 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._attr_unique_id = f"{config_entry.entry_id}_{subentry.subentry_id}_{self.entity_description.key}"
self.topic = subentry.data[CONF_TOPIC] self.topic = subentry.data[CONF_TOPIC]
self._attr_supported_features = NotifyEntityFeature.TITLE self._attr_device_info = DeviceInfo(
self.device_info = DeviceInfo(
entry_type=DeviceEntryType.SERVICE, entry_type=DeviceEntryType.SERVICE,
manufacturer="ntfy LLC", manufacturer="ntfy LLC",
model="ntfy", model="ntfy",

View File

@ -13,7 +13,9 @@ rules:
config-flow-test-coverage: done config-flow-test-coverage: done
config-flow: done config-flow: done
dependency-transparency: done dependency-transparency: done
docs-actions: done docs-actions:
status: exempt
comment: integration has only entity actions
docs-high-level-description: done docs-high-level-description: done
docs-installation-instructions: done docs-installation-instructions: done
docs-removal-instructions: done docs-removal-instructions: done
@ -46,7 +48,7 @@ rules:
test-coverage: done test-coverage: done
# Gold # Gold
devices: todo devices: done
diagnostics: todo diagnostics: todo
discovery-update-info: todo discovery-update-info: todo
discovery: todo discovery: todo
@ -67,13 +69,13 @@ rules:
comment: only one entity comment: only one entity
entity-translations: entity-translations:
status: exempt 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 exception-translations: done
icon-translations: done icon-translations: done
reconfiguration-flow: todo reconfiguration-flow: todo
repair-issues: repair-issues:
status: exempt status: exempt
comment: the integration has no repeairs comment: the integration has no repairs
stale-devices: stale-devices:
status: exempt status: exempt
comment: only one device per entry, is deleted with the entry. comment: only one device per entry, is deleted with the entry.

View File

@ -35,7 +35,7 @@
"unknown": "[%key:common::config_flow::error::unknown%]" "unknown": "[%key:common::config_flow::error::unknown%]"
}, },
"abort": { "abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]" "already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
} }
}, },
"config_subentries": { "config_subentries": {
@ -69,11 +69,11 @@
"error": { "error": {
"publish_forbidden": "Publishing to this topic is forbidden", "publish_forbidden": "Publishing to this topic is forbidden",
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", "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": { "abort": {
"already_configured": "Topic is already configured", "already_configured": "Topic is already configured"
"invalid_topic": "Invalid topic. Only letters, numbers, underscores, or dashes allowed."
} }
} }
}, },

View File

@ -1,7 +1,7 @@
"""Test the ntfy config flow.""" """Test the ntfy config flow."""
from typing import Any from typing import Any
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock
from aiontfy.exceptions import ( from aiontfy.exceptions import (
NtfyException, NtfyException,
@ -56,20 +56,15 @@ async def test_form(
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER} DOMAIN, context={"source": SOURCE_USER}
) )
assert result["type"] == FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["errors"] == {} assert result["errors"] == {}
with patch(
"homeassistant.components.ntfy.config_flow.Ntfy.publish",
return_value=True,
):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
user_input, user_input,
) )
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["title"] == "ntfy.sh"
assert result["data"] == entry_data assert result["data"] == entry_data
assert len(mock_setup_entry.mock_calls) == 1 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} assert result["errors"] == {"base": error}
mock_aiontfy.account.side_effect = None mock_aiontfy.account.side_effect = None
@ -129,7 +124,7 @@ async def test_form_errors(
) )
await hass.async_block_till_done() 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["title"] == "ntfy.sh"
assert result["data"] == { assert result["data"] == {
CONF_URL: "https://ntfy.sh/", CONF_URL: "https://ntfy.sh/",