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

Add dev environment auto configuration #27

Merged
merged 1 commit into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
##########
## MQTT ##
##########

MQTT_HOST="mosquitto"
MQTT_PORT="1883"
MQTT_USERNAME=
MQTT_PASSWORD=
MQTT_PREFIX="enedis_gateway"
MQTT_CLIENT_ID="enedis_gateway"
RETAIN="True"
QOS=0

####################
## Home assistant ##
####################

HA_AUTODISCOVERY="False"
HA_AUTODISCOVERY_PREFIX="homeassistant"
CARD_MYENEDIS= "True"

###############
## Influx DB ##
###############

INFLUXDB_ENABLE="True"
INFLUXDB_HOST="influxdb"
INFLUXDB_PORT=8086
INFLUXDB_TOKEN="enedisgateway2mqtt"
INFLUXDB_ORG="enedisgateway2mqtt"
INFLUXDB_BUCKET="linky"


#########
## Api ##
#########

GET_CONSUMPTION="True"
GET_CONSUMPTION_DETAIL="True"
GET_PRODUCTION="False"
GET_PRODUCTION_DETAIL="False"
OFFPEAK_HOURS=
YEARS=1
CYCLE=3600
ADDRESSES="False"
CONSUMPTION_PRICE_HC=0.1781
CONSUMPTION_PRICE_HP=0.1337
CONSUMPTION_PRICE_BASE=0.1781
REFRESH_CONTRACT="False"
REFRESH_ADDRESSES="False"
WIPE_CACHE="False"
DEBUG="TRUE"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.env
/data
/app/__pycache__/
/tmp
56 changes: 56 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
COMPOSE=docker-compose -f docker-compose.dev.yml

## Start docker conatiners for dev
up: .env
@echo "Start docker conatiner for dev"
$(COMPOSE) up -d
@echo ""
@echo "\033[0;33mMQTT Explorer:\033[0m \033[0;32mhttp://127.0.0.1:4000\033[0m Auth info: (host: mosquitto)"
@echo "\033[0;33mInflux DB: \033[0m \033[0;32mhttp://127.0.0.1:8086\033[0m Auth info: (user: enedisgateway2mqtt, pawword: enedisgateway2mqtt)"

## Stop docker conatiners for dev
down: .env
@echo "Start docker conatiner for dev"
$(COMPOSE) down

## Recreate .env file
init:
rm -rf .env
make .env

## Start in app
start:
$(COMPOSE) exec enedisgateway2mqtt python -u /app/main.py

## Connect to enedisgateway2mqtt container
bash:
$(COMPOSE) exec enedisgateway2mqtt bash

.env:
@cp .env.dist .env
@echo "Init your environment:"
@echo ""
@read -p " - Enter your API key: " ACCESS_TOKEN; echo "ACCESS_TOKEN=$$ACCESS_TOKEN" >> .env
@read -p " - Enter your PDL: " PDL; echo "PDL=$$PDL" >> .env
@echo ""


.DEFAULT_GOAL := help
.PHONY: help
help:
@echo "\033[0;33mUsage:\033[0m"
@echo " make [var_name=value ...] [target]\n"
@echo "\033[0;33mAvailable variables:\033[0m"
@echo ""
@awk '/^[a-zA-Z\-_0-9\.@]+:/ {\
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf "%s \033[0;32m%-22s\033[0m %s\n", key, helpCommand, helpMessage; \
} \
} \
{lastLine = $$0;}' $(MAKEFILE_LIST)\
| sed -e "s/\`/\\\\\`/g"
@echo ""

34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,40 @@ volumes:
mydata:
```

## Dev environment

Requirement:
- docker
- docker-compose
- make

Display help information:
```bash
make
````

Start containers:
```bash
make up
````

Stop containers:
```bash
make down
````

Start application:
```bash
make start
````

Connect to container:
```bash
make start
````



## Roadmap

- Add **DJU18**
Expand Down
56 changes: 56 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: "3.9"
services:
enedisgateway2mqtt:
build: .
links:
- influxdb
- mosquitto
volumes:
- ./data:/data
- ./app:/app
env_file:
- .env
command: tail -f /dev/null

influxdb:
image: influxdb:2.0.7
ports:
- '8086:8086'
volumes:
- ./data/influxdb:/var/lib/influxdb2
healthcheck:
test: ["CMD", "curl", "-f", "http://influxdb:8086"]
interval: 25s
timeout: 3s
start_period: 30s
environment:
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: enedisgateway2mqtt
DOCKER_INFLUXDB_INIT_PASSWORD: enedisgateway2mqtt
DOCKER_INFLUXDB_INIT_ORG: enedisgateway2mqtt
DOCKER_INFLUXDB_INIT_BUCKET: enedisgateway2mqtt
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: enedisgateway2mqtt

mosquitto:
image: eclipse-mosquitto:2.0.12
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./data/mosquitto:/data
- ./mosquitto:/mosquitto/config/
ports:
- 1883:1883
- 9001:9001


mqtt_explorer:
image: smeagolworms4/mqtt-explorer
links:
- mosquitto
volumes:
- ./data/:/data
ports:
- 4000:4000

volumes:
mydata:
Loading