Skip to content
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

Added Home Assistant Notification Support #354

Merged
merged 1 commit into from
Feb 14, 2021

Conversation

caronc
Copy link
Owner

@caronc caronc commented Feb 4, 2021

Description:

Related issue (if applicable): #350
Added Home Assistant Notification Support to Apprise

Details:

  1. Access your profile after logging into your Home Assistant website.
  2. You need to generate a Long-Lived Access Tokens via the Create Token button (very bottom of profile page)

Syntax:

  • hassio://{host}/{long-lived-access-token}
  • hassio://{user}:{pass}:{host}/{long-lived-access-token}
  • hassio://{user}:{pass}:{host}:{port}/{long-lived-access-token}
  • hassio://{host}/optional/path/{long-lived-access-token}
  • hassio://{user}:{pass}:{host}/optional/path/{long-lived-access-token}
  • hassio://{user}:{pass}:{host}:{port}/optional/path/{long-lived-access-token}

By default hassio:// will use port 8123 (unless you otherwise specify). If you use hassios:// (adding an s) to the end, then you use the https protocol on port 443 (unless otherwise specified).

So the same URL's above could be written using a secure connection/port as:

  • hassios://{host}/{long-lived-access-token}
  • hassios://{user}:{pass}:{host}/{long-lived-access-token}
  • hassios://{user}:{pass}:{host}:{port}/{long-lived-access-token}
  • hassios://{host}/optional/path/{long-lived-access-token}
  • hassios://{user}:{pass}:{host}/optional/path/{long-lived-access-token}
  • hassios://{user}:{pass}:{host}:{port}/optional/path/{long-lived-access-token}

The other thing to note is that Home Assistant requires a notification_id associated with each message sent. If the ID is the same as the previous, then the previous message is over-written with the new. This may or may not be what your goal is.

So by default Apprise will generate a unique ID (thus a separate message) on every call. If this isn't the effect you're going for, then define your own Notification ID like so:

  • hassio://{host}/{long-lived-access-token}?nid=myid

New Service Completion Status

  • apprise/plugins/NotifyHomeAssistant.py
  • setup.py
    • add new service into the keywords section of the setup() declaration
  • README.md
    • add entry for new service to table (as a quick reference)
  • packaging/redhat/python-apprise.spec
    • add new service into the %global common_description

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • No lint errors (use flake8)
  • 100% test coverage

if isinstance(self.port, int):
url += ':%d' % self.port

url += '/' + self.fullpath.strip('/')
Copy link

@haidahaha haidahaha Mar 6, 2021

Choose a reason for hiding this comment

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

@caronc you have the url method below. it looks like you are constructing the url manually here. why don't you use the url method instead?

I seem to have run into an issue here. when the self.fullpath is empty, the url becomes like //api/services/persistent_notification/create, which causes the error

Socket Exception: HTTPConnectionPool(host='localhost', port=8123): Max retries exceeded with url: //api/services/persistent_notification/create (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0xffff8b9d0730>, 'Connection to localhost timed out. (connect timeout=4.0)'))

My example URLs are:

hassio://localhost/{access_token}
hassio://localhost:8123/{access_token}

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good find; I'll get this fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants