Skip to content

Commit

Permalink
Merge initial version with template repo (#1)
Browse files Browse the repository at this point in the history
* 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
ChrisRomp authored Aug 6, 2023
1 parent a3ed27f commit ae8991e
Show file tree
Hide file tree
Showing 25 changed files with 157 additions and 208 deletions.
28 changes: 16 additions & 12 deletions .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
"containerEnv": {
"WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}"
},
"extensions": ["timonwong.shellcheck", "esbenp.prettier-vscode"],
"mounts": ["type=volume,target=/var/lib/docker"],
"settings": {
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
},
"extensions": ["timonwong.shellcheck", "esbenp.prettier-vscode"]
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Builder

env:
BUILD_ARGS: "--test"
MONITORED_FILES: "build.yaml config.yaml Dockerfile rootfs"
MONITORED_FILES: "build.yaml config.yaml Dockerfile app"

on:
push:
Expand Down
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
# Example Home Assistant add-on repository
# Home Assistant Ecowitt Proxy add-on repository

This repository can be used as a "blueprint" for add-on development to help you get started.

Add-on documentation: <https://developers.home-assistant.io/docs/add-ons>

[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fhome-assistant%2Faddons-example)
[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fchrisromp%2Faddon-ecowitt-proxy)

## Add-ons

This repository contains the following add-ons

### [Example add-on](./example)
### [Ecowitt Proxy](./ecowitt-proxy)

![Supports aarch64 Architecture][aarch64-shield]
![Supports amd64 Architecture][amd64-shield]
![Supports armhf Architecture][armhf-shield]
![Supports armv7 Architecture][armv7-shield]
![Supports i386 Architecture][i386-shield]

_Example add-on to use as a blueprint for new add-ons._
_An HTTP proxy for Ecowitt weather stations to foward to the Home Assistant Ecowitt integration since Ecowitt does not support HTTPS._

<!--
Expand Down
21 changes: 21 additions & 0 deletions ecowitt-proxy/Dockerfile
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" ]
2 changes: 2 additions & 0 deletions ecowitt-proxy/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from flask import Flask
app = Flask(__name__)
76 changes: 76 additions & 0 deletions ecowitt-proxy/app/receiver.py
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')
6 changes: 6 additions & 0 deletions ecowitt-proxy/app/run.sh
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
21 changes: 21 additions & 0 deletions ecowitt-proxy/config.yaml
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
Binary file added ecowitt-proxy/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ecowitt-proxy/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions ecowitt-proxy/translations/en.yaml
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.
15 changes: 0 additions & 15 deletions example/CHANGELOG.md

This file was deleted.

10 changes: 0 additions & 10 deletions example/DOCS.md

This file was deleted.

12 changes: 0 additions & 12 deletions example/Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions example/README.md

This file was deleted.

57 changes: 0 additions & 57 deletions example/apparmor.txt

This file was deleted.

14 changes: 0 additions & 14 deletions example/build.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions example/config.yaml

This file was deleted.

Binary file removed example/icon.png
Binary file not shown.
Binary file removed example/logo.png
Binary file not shown.
15 changes: 0 additions & 15 deletions example/rootfs/etc/services.d/example/finish

This file was deleted.

19 changes: 0 additions & 19 deletions example/rootfs/etc/services.d/example/run

This file was deleted.

Loading

0 comments on commit ae8991e

Please sign in to comment.