-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5612411
Showing
9 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: HACS Validation | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
pull_request: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
|
||
jobs: | ||
validate: | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- uses: "actions/checkout@v2" | ||
- name: HACS validation | ||
uses: "hacs/action@main" | ||
with: | ||
category: "integration" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Validate with hassfest | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
pull_request: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
validate: | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- uses: "actions/checkout@v2" | ||
- uses: home-assistant/actions/hassfest@master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 baldarn | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
[![hacs_badge](https://img.shields.io/badge/HACS-Default-41BDF5.svg)](https://github.com/hacs/integration) | ||
|
||
# Whatsapper integration | ||
|
||
TODO descr | ||
|
||
## Getting started | ||
|
||
Install Whatsapper add on. | ||
|
||
You can find that in [alexbelgium](https://github.com/alexbelgium/hassio-addons) | ||
|
||
### Installation | ||
Whatsapper is now part ot the Default HACS repositories list. | ||
Just add it from the Integrations list. | ||
|
||
### Configuration | ||
To use Whatsapper notifications edit the `configuration.yaml` file. | ||
|
||
```yaml | ||
notify: | ||
- platform: whatsapper | ||
name: some name that you want | ||
chat_id: [email protected] # WhatsApp chat id (see below) | ||
``` | ||
#### Get chat id | ||
To get all you chat ids, go on the web browser and call: | ||
```url | ||
http://192.168.1.123:4000/chats | ||
``` | ||
|
||
Search and find the chat where you want to send messages and get it's id | ||
|
||
### Whatsapper host_port configuration | ||
|
||
If your whatsapper instance is somewhere else, you can specify that: | ||
|
||
```yaml | ||
notify: | ||
- platform: whatsapper | ||
name: some name that you want | ||
host_port: 192.168.1.123:4000 # host:port of the whatsapper instance | ||
chat_id: [email protected] # WhatsApp chat id | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"domain": "whatsapper", | ||
"name": "Whatsapper integration", | ||
"codeowners": ["baldarn"], | ||
"documentation": "https://github.com/baldarn/whatsapper-ha-integration", | ||
"iot_class": "local_push", | ||
"issue_tracker": "https://github.com/baldarn/whatsapper-ha-integration/issues", | ||
"requirements": [], | ||
"version": "2024.1.26" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""Whatsapper platform for notify component.""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
import voluptuous as vol | ||
|
||
import requests | ||
|
||
from homeassistant.components.notify import ( | ||
PLATFORM_SCHEMA, | ||
BaseNotificationService, | ||
) | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
HOST_PORT = "host_port" | ||
CONF_CHAT_ID = "chat_id" | ||
|
||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Required(CONF_CHAT_ID): vol.Coerce(str)}) | ||
|
||
def get_service( | ||
hass: HomeAssistant, | ||
config: ConfigType, | ||
discovery_info: DiscoveryInfoType | None = None, | ||
) -> WhatsapperNotificationService: | ||
"""Get the Whatsapper notification service.""" | ||
|
||
chat_id = config.get(CONF_CHAT_ID) | ||
host_port = config.get(HOST_PORT) | ||
|
||
if host_port is None: | ||
host_port = "localhost:4000" | ||
|
||
return WhatsapperNotificationService(hass, chat_id, host_port) | ||
|
||
class WhatsapperNotificationService(BaseNotificationService): | ||
|
||
def __init__(self, hass, chat_id, host_port): | ||
"""Initialize the service.""" | ||
self.chat_id = chat_id | ||
self.host_port = host_port | ||
self.hass = hass | ||
|
||
def send_message(self, message="", **kwargs): | ||
"""Send a message to the target.""" | ||
try: | ||
# Actually send the message | ||
url = f'http://{self.host_port}/command' | ||
body = {"command":"sendMessage", "params":[self.chat_id, message]} | ||
resp = requests.post(url, json = body) | ||
print(resp.text) | ||
except Exception as e: | ||
_LOGGER.error("Sending to %s failed: %s", self._chat_id, e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
notify: | ||
description: "Send a notification using Whatsapper" | ||
fields: | ||
message: | ||
description: The message to send | ||
example: "Hello World" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Whatsapper notification", | ||
"render_readme": true, | ||
"iot_class": "local_push" | ||
} |