generated from home-assistant/addons-example
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge initial version with template repo (#1)
* Update devcontainer * Update README to remove template info * Initial import of 0.1.14. * Update config per linter * Remove example add-on * Update linter action * Update repository info; add logos.
- Loading branch information
Showing
25 changed files
with
157 additions
and
208 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
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
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
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 @@ | ||
ARG BUILD_FROM | ||
FROM ${BUILD_FROM} | ||
|
||
RUN apk --update --no-cache add python3 py3-pip \ | ||
&& pip install --no-cache-dir requests flask | ||
|
||
RUN mkdir /app | ||
|
||
COPY app/ /app | ||
RUN chmod a+x /app/run.sh | ||
|
||
EXPOSE 8081 | ||
|
||
# [email protected] | ||
LABEL \ | ||
io.hass.version="0.1.14" \ | ||
io.hass.type="addon" \ | ||
io.hass.arch="armhf|aarch64|i386|amd64|armv7" | ||
|
||
WORKDIR /app | ||
CMD [ "./run.sh" ] |
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,2 @@ | ||
from flask import Flask | ||
app = Flask(__name__) |
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,76 @@ | ||
from flask import Flask, request | ||
import requests | ||
import os | ||
import sys | ||
import logging | ||
|
||
app = Flask("Ecowitt Proxy") | ||
|
||
# Vars from environment variables | ||
# Not all of these are settable from the add-on configuration; however, I wanted to give extra | ||
# flexibility in case someone wanted to run this outside of a Home Assistant add-on. | ||
log_level = os.environ.get('ECOWITT_PROXY_LOG_LEVEL', 'INFO') # TODO | ||
service_port = os.environ.get('ECOWITT_PROXY_PORT', '8081') | ||
ha_webhook_id = os.environ.get('HA_WEBHOOK_ID', 'no-webhook-id') | ||
base_url = os.environ.get('HA_BASE_URL', 'http://supervisor/core/api/webhook/') | ||
auth_token = os.environ.get('HA_AUTH_TOKEN', 'no-auth-token') | ||
forward_url = base_url + ha_webhook_id | ||
|
||
# Set logging level | ||
logger_level = logging.INFO # Default | ||
if log_level == 'DEBUG': | ||
logger_level = logging.DEBUG | ||
if log_level == 'WARNING': | ||
logger_level = logging.WARNING | ||
|
||
# Set logging format | ||
logger_format = logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S') | ||
|
||
# Init logger | ||
logging.basicConfig(stream=sys.stdout, level=logger_level, format=logger_format) | ||
|
||
@app.route('/') | ||
def version(): | ||
return "Home Assistant Ecowitt Proxy\n" | ||
|
||
# Show a friendly error if someone tries to access the webhook URL directly | ||
@app.route('/log/ha', methods=['GET']) | ||
def logHomeAssistantGet(): | ||
return "Requires POST operation\n" | ||
|
||
@app.route('/log/ha', methods=['POST']) | ||
def logHomeAssistant(): | ||
# Get form data | ||
payload = request.form | ||
|
||
# Log payload to console | ||
logging.debug("Received Payload: " + str(payload)) | ||
|
||
# Forward to Home Assistant | ||
response = requests.post(url=forward_url, data=payload, timeout=5, headers={'Authorization': 'Bearer ' + auth_token}) | ||
response_text = response.text | ||
|
||
# Check for error (any non-200 result) | ||
if response.status_code != 200: | ||
logging.error("HA API Error: " + str(response_text)) | ||
return "HA API Error: " + str(response_text) | ||
|
||
# Log response to console | ||
logging.debug("HA API Response: " + response_text) | ||
|
||
return "OK" | ||
|
||
if __name__ == "__main__": | ||
# Verify webhook ID is set | ||
if ha_webhook_id == 'no-webhook-id': | ||
logger.error("HA_WEBHOOK_ID environment variable not set.") | ||
exit(1) | ||
|
||
logging.info("Starting Home Assistant Ecowitt Proxy") | ||
logging.info("HA Webhook URL: " + forward_url) | ||
|
||
# Suppress Flask development server startup message (not working?) | ||
cli = sys.modules['flask.cli'] | ||
cli.show_server_banner = lambda *x: None | ||
|
||
app.run(host="0.0.0.0", port=service_port, debug=log_level == 'DEBUG') |
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 @@ | ||
#!/command/with-contenv bashio | ||
HA_WEBHOOK_ID=$(bashio::config 'Webhook_ID') | ||
bashio::log.info "Using webhook ID $HA_WEBHOOK_ID" | ||
export HA_WEBHOOK_ID=$HA_WEBHOOK_ID | ||
export HA_AUTH_TOKEN=$SUPERVISOR_TOKEN | ||
python3 receiver.py |
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 @@ | ||
name: "Ecowitt HTTP Proxy" | ||
description: "An HTTP proxy for Ecowitt weather stations to foward to the Ecowitt integration over HTTPS since Ecowitt does not support HTTPS" | ||
version: "0.1.14" | ||
slug: ecowitt-proxy | ||
homeassistant_api: true | ||
init: false | ||
arch: | ||
- aarch64 | ||
- amd64 | ||
- armhf | ||
- armv7 | ||
- i386 | ||
ports: | ||
8081/tcp: 8081 | ||
ports_description: | ||
8081/tcp: "The port to listen on for Ecowitt weather station data" | ||
host_network: true | ||
options: | ||
Webhook_ID: "" | ||
schema: | ||
Webhook_ID: str |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,7 @@ | ||
configuration: | ||
Webhook_ID: | ||
name: Webhook ID | ||
description: The unique ID for the webhook for the Ecowitt integration (shown on setup). | ||
Log_Level: | ||
name: Log Level | ||
description: Verbosity of the log output for the add-on. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.