From 638d74145a86d1f132c8d712133df64ba5007a6b Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 18 Jan 2018 20:13:35 +0100 Subject: [PATCH] Initial version --- .gitignore | 3 +++ Makefile | 27 +++++++++++++++++++++++++++ config.yml | 24 ++++++++++++++++++++++++ requirements.txt | 2 ++ update.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 config.yml create mode 100644 requirements.txt create mode 100644 update.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3a9ff58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +tasmota +venv +build diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..17a7b5f --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +TASMOTA_VERSION=v5.11.1 + +default: build_sonoff build_sonoff-minimal + +ci: clean default + +build_%: download update_user-config venv + cd tasmota && ../venv/bin/platformio run -e $* + mkdir -p build + cp tasmota/.pioenvs/$*/firmware.bin build/$*.bin + +clean: + rm -rf tasmota build venv + +download: + git clone https://github.com/arendst/Sonoff-Tasmota.git tasmota + cd tasmota && git reset --hard $(TASMOTA_VERSION) + +update_user-config: venv + ./venv/bin/python update.py + cd tasmota && git --no-pager diff -w sonoff/user_config.h + +venv: + virtualenv -p python2 venv + ./venv/bin/pip install -r requirements.txt + +.PHONY: venv diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..2a25ea8 --- /dev/null +++ b/config.yml @@ -0,0 +1,24 @@ +--- + +STA_SSID1: '${WIFI_SSID}' +STA_PASS1: '${WIFI_PASS}' + +OTA_URL: '${OTA_URL}' + +MQTT_HOST: '${MQTT_HOST}' +MQTT_USER: '${MQTT_USER}' +MQTT_PASS: '${MQTT_PASS}' +MQTT_TOPIC: '"unconfigured"' + +USE_DOMOTICZ: '!undef' +USE_EMULATION: '!undef' +USE_DISCOVERY: '!undef' + +NTP_SERVER1: '"ptbtime1.ptb.de"' +NTP_SERVER2: '"ptbtime2.ptb.de"' + +USE_IR_REMOTE: '!undef' +USE_WS2812: '!undef' +USE_ARILUX_RF: '!undef' + +... diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..556a2f4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +PyYAML +platformio diff --git a/update.py b/update.py new file mode 100644 index 0000000..d43720e --- /dev/null +++ b/update.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- + +import os + +import yaml + + +def fmt_line(prefix, param, content, comment): + return '{: <47} // {}'.format('{}#define {: <22} {}'.format(prefix, param, content), comment) + + +def get_line(param, content, comment): + if content == '!undef': + return fmt_line('//', param, '', comment) + if content == '!def': + return fmt_line('', param, '', comment) + + if content[:2] == '${': + envvar = content.strip('${}') + if envvar in os.environ: + content = os.environ[envvar] + + return fmt_line('', param, content, comment) + + +def main(): + cfg = yaml.load(open('config.yml')) + config = open('tasmota/sonoff/user_config.h').read().split('\n') + + for (i, line) in enumerate(config): + for param, content in cfg.items(): + if '#define {} '.format(param) in line: + comment = line.lstrip('/').split(' //', 1)[1].strip() + config[i] = get_line(param, content, comment) + + with open('tasmota/sonoff/user_config.h', 'w') as fh: + fh.write('\n'.join(config)) + + +if __name__ == '__main__': + main()