From 8f72df1da684eadb708239ef21310b2691c79b09 Mon Sep 17 00:00:00 2001 From: Eric Buehl <715650+ericbuehl@users.noreply.github.com> Date: Fri, 9 Dec 2022 08:28:09 -0800 Subject: [PATCH] use github actions, deprecate circleci (#172) --- .circleci/config.yml | 41 ----------------------------- .github/workflows/test.yml | 16 +++++++++++ README.md | 2 +- conversion/pickle2graphite.py | 2 +- conversion/se2MQTT.py | 6 ++--- conversion/se2csv.py | 2 +- conversion/se2graphite.py | 2 +- conversion/se2state.py | 2 +- requirements.txt | 7 +++-- se/msg.py | 6 ++--- semonitor.py | 2 +- test/test.sh | 14 +++++----- utilities/se2file.py | 2 +- utilities/sekey.py | 2 +- utilities/seprint.py | 2 +- utilities/tinyPythonSyslogServer.py | 2 +- 16 files changed, 41 insertions(+), 69 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/test.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index cf5ba25..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,41 +0,0 @@ -version: 2.1 -commands: - setup_and_test: - steps: - - run: - command: | - curl -sSL https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash - sudo apt-get install -y git-lfs tshark xxd - - checkout - - restore_cache: - key: v1-requirements-{{ checksum "/usr/local/bin/python" }}-{{ checksum "requirements.txt" }} - - run: - command: | - virtualenv venv - . venv/bin/activate - pip install -r requirements.txt - - save_cache: - key: v1-requirements-{{ checksum "/usr/local/bin/python" }}-{{ checksum "requirements.txt" }} - paths: - - "venv" - - run: - command: | - . venv/bin/activate - test/test.sh -jobs: - "Python 2": - docker: - - image: circleci/python:2.7 - steps: - - setup_and_test - "Python 3": - docker: - - image: circleci/python:3.7 - steps: - - setup_and_test - -workflows: - test: - jobs: - - "Python 2" - - "Python 3" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1a7f8dd --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,16 @@ +name: CI +on: + push +jobs: + integration: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + lfs: true + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + cache: 'pip' + - run: pip install -r requirements.txt + - run: test/test.sh diff --git a/README.md b/README.md index 513b997..14e8cd0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![CircleCI](https://circleci.com/gh/jbuehl/solaredge.svg?style=svg)](https://circleci.com/gh/jbuehl/solaredge) +![CI](https://github.com/jbuehl/solaredge/actions/workflows/test.yml/badge.svg) SolarEdge Monitoring ==================== diff --git a/conversion/pickle2graphite.py b/conversion/pickle2graphite.py index 2003f33..74b25e5 100644 --- a/conversion/pickle2graphite.py +++ b/conversion/pickle2graphite.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ Send SolarEdge performance metrics to Graphite via the graphite/carbon pickle listener port. diff --git a/conversion/se2MQTT.py b/conversion/se2MQTT.py index 677ec2a..7aa43ca 100755 --- a/conversion/se2MQTT.py +++ b/conversion/se2MQTT.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Send JSON performance data to Mosquitto MQTT Broker # @@ -10,11 +10,11 @@ # #example: # -# python2 se2MQTT.py -c solaredge -u solaredge -p s0lar3dg3 -s mosquitto.domain.local -t /ha/value/solaredge /root/solaredge/performance.json +# python3 se2MQTT.py -c solaredge -u solaredge -p s0lar3dg3 -s mosquitto.domain.local -t /ha/value/solaredge /root/solaredge/performance.json # # follow /root/solaredge/performance.json file and publish to topic "/ha/value/solaredge" on server "mosquitto.domain.local" with client id "solaredge" and user "solaredge" and password "s0lar3dg3" # -# python2 semonitor.py -t 4 -d /root/solaredge/selog.txt -s 7f123456 -vvvv /dev/ttyUSB0 | python2 se2MQTT.py -c solaredge -u solaredge -p s0lar3dg3 -s mosquitto.domain.local -t /ha/value/solaredge +# python3 semonitor.py -t 4 -d /root/solaredge/selog.txt -s 7f123456 -vvvv /dev/ttyUSB0 | python3 se2MQTT.py -c solaredge -u solaredge -p s0lar3dg3 -s mosquitto.domain.local -t /ha/value/solaredge # # pipe output from semonitor directly into se2MQTT.py and publish to topic "/ha/value/solaredge" on server "mosquitto.domain.local" with client id "solaredge" and user "solaredge" and password "s0lar3dg3" diff --git a/conversion/se2csv.py b/conversion/se2csv.py index 62f18c4..7855ef5 100755 --- a/conversion/se2csv.py +++ b/conversion/se2csv.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Convert SolarEdge inverter performance monitoring data from JSON to CSV diff --git a/conversion/se2graphite.py b/conversion/se2graphite.py index 9e32c43..00c12c4 100755 --- a/conversion/se2graphite.py +++ b/conversion/se2graphite.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # send a SolarEdge performance metrics to Graphite diff --git a/conversion/se2state.py b/conversion/se2state.py index 6721b46..9c18962 100755 --- a/conversion/se2state.py +++ b/conversion/se2state.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Maintain a file containing the current state and selected statistics # of SolarEdge inverters and optimizers diff --git a/requirements.txt b/requirements.txt index 12893e9..461c4e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -future==0.17.1 -netifaces==0.10.6 -pycrypto==2.6.1 -pyserial==3.4 +netifaces==0.11.0 +pycryptodome==3.16.0 +pyserial==3.5 diff --git a/se/msg.py b/se/msg.py index 9af8912..f3e23db 100644 --- a/se/msg.py +++ b/se/msg.py @@ -31,7 +31,7 @@ def __init__(self, key, msg0503): curtime = datetime.datetime.now() mystrtime = curtime.strftime("%Y-%m-%d %H:%M:%S") # Create a key by encrypting the data from Solar Edge with our key) - enkey1 = bytes(AES.new(key).encrypt(msg0503[:16])) + enkey1 = bytes(AES.new(key, AES.MODE_ECB).encrypt(msg0503[:16])) # Store the 0503 message in a hex string hex_msg0503 = binascii.hexlify(msg0503) # Format the line in the last0503.msg file @@ -40,9 +40,9 @@ def __init__(self, key, msg0503): # Write the outstr to the last0503.msg file, clobbering the previous (hence 'w' write mode) ko = open(LAST0503FILE, "w") ko.write(outstr) - ko.close + ko.close() # self.cipher is an AES object - self.cipher = AES.new(bytes(list((enkey1[i] ^ msg0503[i + 16] for i in range(16))))) + self.cipher = AES.new(bytes(list((enkey1[i] ^ msg0503[i + 16] for i in range(16)))), AES.MODE_ECB) self.encrypt_seq = random.randint(0, 0xffff) def crypt(self, msg003d): diff --git a/semonitor.py b/semonitor.py index d6526e6..401512f 100755 --- a/semonitor.py +++ b/semonitor.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # SolarEdge inverter performance monitoring using the SolarEdge protocol diff --git a/test/test.sh b/test/test.sh index 5996b34..7047bf9 100755 --- a/test/test.sh +++ b/test/test.sh @@ -5,25 +5,24 @@ set -eux export TZ='US/Pacific' -for pcap in test/pcap/*.pcap; do +for rec in test/rec/*.rec; do TMP=$(mktemp -d) if [ ! -d "${TMP}" ]; then echo "Failed to create temporary directory '${TMP}'" break fi TMPSE2CSV="${TMP}/se2csv" - SAMPLE="$(basename -s ".pcap" "${pcap}")" + SAMPLE="$(basename -s ".rec" "${rec}")" REC_OPTION="-r ${TMP}/${SAMPLE}.rec" OUT_OPTION="-o ${TMP}/${SAMPLE}.json" KEY_OPTION="" if [ -f "test/keys/${SAMPLE}.key" ]; then KEY_OPTION="-k test/keys/${SAMPLE}.key" fi - SEMONITOR_OPTIONS="${REC_OPTION} ${OUT_OPTION} - ${KEY_OPTION} -v -x" - tshark -r "test/pcap/${SAMPLE}.pcap" -T fields -e data | xxd -r -p | ./semonitor.py ${SEMONITOR_OPTIONS} + ./semonitor.py ${REC_OPTION} ${OUT_OPTION} "test/rec/${SAMPLE}.rec" ${KEY_OPTION} -v -x diff "test/json/${SAMPLE}.json" "${TMP}/${SAMPLE}.json" - cmp -l "test/rec/${SAMPLE}.rec" "${TMP}/${SAMPLE}.rec" + cmp "test/rec/${SAMPLE}.rec" "${TMP}/${SAMPLE}.rec" mkdir "${TMPSE2CSV}" ./conversion/se2csv.py -p "${TMPSE2CSV}/${SAMPLE}" -t < "test/json/${SAMPLE}.json" diff "test/csv/${SAMPLE}/" "${TMPSE2CSV}/" -w @@ -31,10 +30,9 @@ for pcap in test/pcap/*.pcap; do IN_OPTION="test/rec/${SAMPLE}.rec" REC_OPTION="-r ${TMP}/${SAMPLE}.re.rec" OUT_OPTION="-o ${TMP}/${SAMPLE}.re.json" - SEMONITOR_OPTIONS="${REC_OPTION} ${OUT_OPTION} ${IN_OPTION} ${KEY_OPTION} -v -x" - ./semonitor.py ${SEMONITOR_OPTIONS} + ./semonitor.py ${REC_OPTION} ${OUT_OPTION} ${IN_OPTION} ${KEY_OPTION} -v -x diff "test/json/${SAMPLE}.json" "${TMP}/${SAMPLE}.re.json" - cmp -l "test/rec/${SAMPLE}.rec" "${TMP}/${SAMPLE}.re.rec" + cmp "test/rec/${SAMPLE}.rec" "${TMP}/${SAMPLE}.re.rec" if [ -d "${TMP}" ] && [ "${TMP#/tmp/tmp.}x" != "${TMP}x" ]; then rm -rf "${TMP}" diff --git a/utilities/se2file.py b/utilities/se2file.py index ee5ce57..f8ece7a 100755 --- a/utilities/se2file.py +++ b/utilities/se2file.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import time import os diff --git a/utilities/sekey.py b/utilities/sekey.py index dadab3a..deac256 100755 --- a/utilities/sekey.py +++ b/utilities/sekey.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Get the encryption key for an inverter diff --git a/utilities/seprint.py b/utilities/seprint.py index 309d197..b8a23b0 100644 --- a/utilities/seprint.py +++ b/utilities/seprint.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # print(selected data from a JSON file diff --git a/utilities/tinyPythonSyslogServer.py b/utilities/tinyPythonSyslogServer.py index 42cfc17..a2294ee 100644 --- a/utilities/tinyPythonSyslogServer.py +++ b/utilities/tinyPythonSyslogServer.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 ## Tiny Syslog Server in Python. ##