Skip to content

Commit

Permalink
Docstrings updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ECOM-Engineering committed Aug 27, 2024
1 parent 06b4943 commit 39a87ed
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 137 deletions.
6 changes: 5 additions & 1 deletion access.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Cloud access for weather and car data."""

from requests import ConnectionError
import requests
import json
Expand Down Expand Up @@ -95,7 +97,9 @@ def ec_GetCarData():
# noinspection PyPep8
def ec_GetPVData(url=const.C_SOLAR_URL, tout=15):
"""
Get relevant data from PV inverter. API doc: https://www.solaredge.com/sites/default/files/se_monitoring_api.pdf
Get relevant data from PV inverter.
API doc: https://www.solaredge.com/sites/default/files/se_monitoring_api.pdf
:param tout: timeout for url access
:param url: complete url including api key
Expand Down
67 changes: 17 additions & 50 deletions charger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
""" Basic library for accessing go-e charger API. """

import time
from json import JSONDecodeError
import requests
from requests import ConnectionError
Expand All @@ -9,30 +9,14 @@
# API V2 see: https://github.com/goecharger/go-eCharger-API-v2
import const

def search_charger(ip_root, tout = 0.2):
retval = "-1"
command = "/api/status?filter=fna"
for i in range(1, 250):
ip = ip_root + str(i)
print(ip)
try:
response = requests.get(ip + command, timeout=(tout))
statusCode = response.status_code
if statusCode == 200:
print("IP found:", ip)
retval = ip
break
except:
continue
return retval

class Charger:

def __init__(self, url, api_version=2, timeout=5):
"""
ini function at instantiation of this class
:param url: WiFi or cloud url of charger
:param url: Wi-Fi or cloud url of charger
:param api_version: API version (series CM-02: 1, series CM-03: 2)
:param timeout: optional seconds. Default = 15
"""
Expand All @@ -49,38 +33,21 @@ def __init__(self, url, api_version=2, timeout=5):
self.chargerData = {'car': 0, 'amp': 0, 'nrg': 15 * [0], 'pha': 0, 'dwo': 0, 'ast': 1, 'err': -1,
'statusCode': -1}

def __search_charger(self, tout=0.5):
retval = "-1"
command = "/api/status?filter=fna"
for i in range(1, 250):
ip = self.url_root + str(i)
try:
response = requests.get(ip + command, timeout = 0.5)
statusCode = response.status_code
if statusCode == 200:
print("IP found:", ip)
retval = ip
break
except:
continue
return retval

def __search_charger(self, tout=0.5):
retval = "-1"
command = "/api/status?filter=fna"
for i in range(1, 250):
ip = self.url_root + str(i)
try:
# response = requests.get(ip + command, timeout=(tout, 2))
response = requests.get(ip + command, timeout = 0.5)
statusCode = response.status_code
if statusCode == 200:
print("IP found:", ip)
retval = ip
break
except:
continue
return retval
# def __search_charger(self, tout=0.5):
# retval = "-1"
# command = "/api/status?filter=fna"
# for i in range(1, 250):
# ip = self.url_root + str(i)
# try:
# response = requests.get(ip + command, timeout = 0.5)
# statusCode = response.status_code
# if statusCode == 200:
# print("IP found:", ip)
# retval = ip
# break
# except:
# continue
# return retval

def get_charger_data(self):
"""
Expand Down
14 changes: 9 additions & 5 deletions const.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
""" Project wide constants.
project wide constants defined here and in also from evs.cfg file.
"""

import configparser as CP
from pathlib import Path
from os import path as LogPath

projectRoot = str(Path(__file__).parent)
print("Project Root = ", projectRoot)

C_APP_VERSION = '0.9.0rc4'
C_APP_VERSION = '0.9.0rc5'
configFile = projectRoot + "/evs.cfg"
C_DEFAULT_SETTINGS_FILE = projectRoot + "/PV_Manager.json"
C_INI_FILE = projectRoot + "/evsGUI.ini"
Expand Down Expand Up @@ -47,8 +52,7 @@
C_SYS_LOG_INTERVAL = int(config['SYSTEM']['log_interval'])

C_CAR_STATE = ["Car Unpluged", "Car Ready", "Car Charging"]
C_CHARGER_STATUS_TEXT = ("0:Error", "1: Idle", "2: Charging", "3: WaitCar", "4: Completeç, 5: Error")
# C_CHARGER_STATUS_TEXT = ("No Charger access", "Vehicle unplugged", "Charging", "Awaiting command", "Ready")
C_CHARGER_STATUS_TEXT = ("0: imError", "1: Idle", "2: Charging", "3: WaitCar", "4: Completeç, 5: Error")
C_MODE_TXT = ["CAR UNPLUGGED",
"IDLE, waiting for event ...",
"SOLAR CHARGE init ...",
Expand Down Expand Up @@ -90,5 +94,5 @@
7wdW741898y57yc2ia4ceOFeLTvnYZfsuesm1Q78WfQL9W3SKY3kyi04NP7BTWnQBTm9xRI24kp3nz9If3278UQPZrKUAAAAASUVORK5CYII='

# ---------------- Weather constants (not used yet) -----------------------------
# C_WEATHER_URL = "https://api.openweathermap.org/data/2.5/forecast?q=arbon,ch&&units=metric&APPID="
# C_WEATHER_API_KEY = "e00176e559c6b27d5df2fe21d8cd26e0"
C_WEATHER_URL = ""
C_WEATHER_API_KEY = ""
27 changes: 21 additions & 6 deletions evsGUI.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# import as sg
"""Graphical user interface based on FreeSimpleGUI( formar PySimpleGUI)."""

import FreeSimpleGUI as sg
import const

#todo replace limit text limit sign by graph

#sg.theme('DarkBlue3')
#sg.theme('SystemDefault')
#sg.theme("SystemDefaultForReal")
Expand Down Expand Up @@ -33,13 +34,28 @@


def LEDIndicator(key=None, radius=30):
"""
LED widget built as circle.
:param key: label of selected LED
:param radius: LED radius in pixels
:return: LED
"""
return sg.Graph(canvas_size=(radius, radius),
graph_bottom_left=(-radius, -radius),
graph_top_right=(radius, radius),
pad=(0, 0), key=key)


def SetLED(win, key, color):
"""
Display Activate LED widget
:param win: parent window
:param key: label of selected LED
:param color: color of selected LED
:return: none
"""
graph = win[key]
graph.erase()
graph.draw_circle((0, 0), 12, fill_color=color, line_color='black')
Expand All @@ -58,10 +74,8 @@ def SetLED(win, key, color):
sg.Stretch(), LEDIndicator('-LED_CAR-')],
[limitSign,
limitText, sg.Text('%', pad=0)]])
# [))]])
],
[sg.Text("")],

[sg.Frame(title='Charging Power', size=(530,80), layout=[
[chargePwrBar, chargeDisp, sg.Text('kW', pad=0), chargeCurrentDisp, sg.Text('A', pad=0), phasesDisp, sg.Text('Phase'),
sg.Stretch(), LEDIndicator('-LED_CHARGER-') ],
Expand All @@ -77,7 +91,6 @@ def SetLED(win, key, color):

[sg.Frame(title='Messages', size=(530,60), layout=[
[messageText, sg.Stretch(), LEDIndicator('-LED_MSG-')]])]]
# [sg.Text('Initializing ...', key='-MESSAGE-', size=53, text_color ='grey10', background_color ='light grey')]])]]

layout = [[sg.Column(col1)],
[sg.Button('Force Charge', disabled=True), sg.Button('Stop Charge', disabled=True),
Expand All @@ -89,12 +102,14 @@ def SetLED(win, key, color):


def testLayout():
"""Displays main window (static)."""

while 1:
event, values = window.read(timeout=200)
if event == 'Quit' or event == sg.WIN_CLOSED:
quit()
window['-battBar-'].UpdateBar(50)
SetLED(window,'-LED_SOLAR-', 'grey')
SetLED(window,'-LED_SOLAR-', 'yellow')
SetLED(window,'-LED_FORCED-', 'grey')
SetLED(window,'-LED_EXTERN-', 'grey')
SetLED(window,'-LED_MSG-', 'grey')
Expand Down
20 changes: 9 additions & 11 deletions mainControl.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
""" Main control and display module."""

import configparser as CP
import os.path

Expand All @@ -10,15 +12,6 @@
import charger
import utils


# pwrOnTimer = timers.EcTimer()
# pwrOnTimer.set(2)

# while(pwrOnTimer.read()):
# x = 1



SIMULATE_PV_TO_GRID = 0

# restore window position
Expand Down Expand Up @@ -73,8 +66,14 @@
settings = sysSettings.defaultSettings
sysSettings.writeSettings(const.C_DEFAULT_SETTINGS_FILE, settings)


def printMsg(item="", value=""):
"""
Write message into message window and return message.
:param item: First text in message
:param value: optional values to display
:return: composed text
"""
text = f'{item} {value}'
window['-MESSAGE-'].update(text)
return text
Expand All @@ -83,7 +82,6 @@ def printMsg(item="", value=""):
messageTxt = printMsg('Charger on URL', const.C_CHARGER_WIFI_URL)

go_e = charger.Charger(url= const.C_CHARGER_WIFI_URL)
utils.charge = go_e #forward object go-e to utils.py

utils.writeLog(sysData, strMessage=messageTxt, strMode=chargeMode)

Expand Down
3 changes: 2 additions & 1 deletion popCharge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# import PySimpleGUI as sg
"""Popup window for manual basic charge settings"""

import FreeSimpleGUI as sg
import os.path
import const
Expand Down
9 changes: 2 additions & 7 deletions popSettings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# import PySimpleGUI as sg
"""Popup window for solar charge settings"""

import FreeSimpleGUI as sg
import os.path

Expand Down Expand Up @@ -50,7 +51,6 @@ def popSettings(batteryLevel=40, file=const.C_DEFAULT_SETTINGS_FILE, pop_locatio

# test global padding popWin = sg.Window('Manual Charge Options', layout_popC, element_padding=0)
popWin = sg.Window('PV Options', layout_popC, location=pop_location, modal=True, icon=const.C_LOGO)
# p = popWin['battLevel']

while True:
ev2, val2 = popWin.read(100)
Expand All @@ -66,11 +66,6 @@ def popSettings(batteryLevel=40, file=const.C_DEFAULT_SETTINGS_FILE, pop_locatio
done = True
break

# if ev2 == '-CHARGE LIMIT-': # prevent limit lower than actuaöl battery level
# if val2['-CHARGE LIMIT-'] < batteryLevel:
# popWin['-CHARGE LIMIT-'].update(batteryLevel)
# print(manualSettings)

# noinspection PySimplifyBooleanCheck
if val2['-allow_3_phases-'] == True:
popWin['-MIN_I_3_PH-'].update(disabled=False)
Expand Down
20 changes: 15 additions & 5 deletions sysSettings.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
"""Read an write charge settings from and to json file."""
import json
# import PySimpleGUI as sg
import FreeSimpleGUI as sg
# default
# defaultSettings = {'manual':{'cancelled': True, 'currentSet': 12, 'chargeLimit': 80, '3_phases': False, 'phaseSet': True},
# 'pv': {'currentSet': 8, 'chargeLimit': 80, '3_phases': False}}

defaultSettings = {'manual': {'currentSet': 12, 'chargeLimit': 80, '3_phases': False, 'phaseSet': True},
'pv': {'max_1_Ph_current': 14, 'min_3_Ph_current': 8, 'chargeLimit': 80, 'allow_3_phases': False}}


def writeSettings(file="", settingsDict=None):
"""
writes dictionary to json formatted file.
:param file: name of setting json file
:param settingsDict: name of dictionary containing actual settings
:return: ---
"""
if settingsDict is None:
settingsDict = {}
with open(file, "w") as write_file:
json.dump(settingsDict, write_file, indent=4)


def readSettings(file=""):
"""
reads dictionary from json formatted file.
:param file:
:return:
"""
with open(file) as readFile:
return json.load(readFile)
Loading

0 comments on commit 39a87ed

Please sign in to comment.