8000 Add event platform to ntfy integration by tr4nt0r · Pull Request #143529 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add event platform to ntfy integration #143529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

tr4nt0r
Copy link
Contributor
@tr4nt0r tr4nt0r commented Apr 23, 2025

Proposed change

Adds an event entity that subscribes to topics to receive notifications in Home Assistant.

When a topic is protected, it will fail to subscribe. Currently an error is logged but the entity will continue trying to subscribe to the topic. My idea was to raise a repair issue with a fix that deactivates the entity. I will add the repair in a follow-up PR.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft April 25, 2025 14:46
@tr4nt0r tr4nt0r marked this pull request as ready for review April 25, 2025 22:34
@home-assistant home-assistant bot requested a review from joostlek April 25, 2025 22:34
@tr4nt0r tr4nt0r force-pushed the ntfy_subscribe branch 2 times, most recently from ca779ea to b1a083c Compare May 19, 2025 19:17
@tr4nt0r tr4nt0r force-pushed the ntfy_subscribe branch 2 times, most recently from acf92bb to 98959a7 Compare June 21, 2025 01:37
Comment on lines +128 to +150
vol.Required(SECTION_FILTER): data_entry_flow.section(
vol.Schema(
{
vol.Optional(CONF_PRIORITY): SelectSelector(
SelectSelectorConfig(
multiple=True,
options=["5", "4", "3", "2", "1"],
mode=SelectSelectorMode.DROPDOWN,
translation_key="priority",
)
),
vol.Optional(CONF_TAGS): TextSelector(
TextSelectorConfig(
type=TextSelectorType.TEXT,
multiple=True,
),
),
vol.Optional(CONF_TITLE): str,
vol.Optional(CONF_MESSAGE): str,
}
),
{"collapsed": True},
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when subscribing ntfy allows passing parameters to filter the messages that are received https://docs.ntfy.sh/subscribe/api/#list-of-all-parameters

Comment on lines 39 to 42
self.ntfy = config_entry.runtime_data
self.config_entry = config_entry
self.subentry = subentry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we store everything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the config_entry is already used in the notify entity to initiate the reauth flow. In the event entity to create a backgroud task that is automatically cancelled when the config entry is unloaded. the subentry was added to have access to the per topic filter settings

Comment on lines +121 to +124
self._ws = self.config_entry.async_create_background_task(
hass=self.hass,
target=self.ntfy.subscribe(
topics=[self.topic],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how many websocket connections do you make in the end? Because this would leave us with 1 websocket per entity which I think is quite a lot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ntfy is limited to 30 open websocket connections anyway. Having individual websocket connections per topic allows using different filter settings when subscribing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but I mean, in the end, do we create 1 websocket or do we create 1 per entity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is 1 socket per entity yes

"filter_message": "Include messages with content that exactly matches the specified text"
},
"name": "Message filters (optional)",
"description": "Apply filters to narrow down the messages received when Home Assistant subscribes to the topic"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These filters are passed on to the websocket right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yepp

@home-assistant home-assistant bot marked this pull request as draft June 23, 2025 20:33
@tr4nt0r tr4nt0r marked this pull request as ready for review June 23, 2025 22:23
@home-assistant home-assistant bot requested a review from joostlek June 23, 2025 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0