Skip to content

Commit

Permalink
Merge pull request britkat1980#97 from salewis38:main
Browse files Browse the repository at this point in the history
Fix PALM issues
  • Loading branch information
britkat1980 authored Aug 6, 2023
2 parents e00fd46 + b73be25 commit f9ba1fc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Pylint

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install requests
- name: Analysing the code with pylint
run: |
pylint --fail-under=7 $(git ls-files '*.py')
2 changes: 1 addition & 1 deletion GivTCP/palm_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GE:
#batt_utilisation = 0.85
batt_utilisation = float(os.getenv('PALM_BATT_UTILISATION'))

#batt_max_charge = batt_capacity * batt_utilisation
batt_max_charge = batt_capacity * batt_utilisation

# Inverter charge/discharge rate in kW, INVERTER_MAX_BAT_RATE is in Watts
#charge_rate = 2.5
Expand Down
48 changes: 26 additions & 22 deletions GivTCP/palm_soc.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env python3
"""PALM - PV Active Load Manager."""

import sys

import time
import json
from datetime import datetime, timedelta
from typing import Tuple, List
from os.path import exists
import pickle
import requests
import palm_settings as stgs
import write as wr
from GivLUT import GivLUT, GivQueue
from os.path import exists
import pickle
logger = GivLUT.logger

# This software in any form is covered by the following Open Source BSD license:
Expand Down Expand Up @@ -123,7 +123,7 @@ def get_latest_data(self):
}

try:
resp = requests.request('GET', url, headers=headers)
resp = requests.request('GET', url, headers=headers, timeout=10)
except requests.exceptions.RequestException as error:
logger.error(error)
return
Expand Down Expand Up @@ -155,7 +155,7 @@ def get_latest_data(self):

url = stgs.GE.url + "meter-data/latest"
try:
resp = requests.request('GET', url, headers=headers)
resp = requests.request('GET', url, headers=headers, timeout=10)
except requests.exceptions.RequestException as error:
logger.error(error)
return
Expand Down Expand Up @@ -206,7 +206,7 @@ def get_load_hist_day(offset: int):
}

try:
resp = requests.request('GET', url, headers=headers, params=params)
resp = requests.request('GET', url, headers=headers, params=params, timeout=10)
except requests.exceptions.RequestException as error:
logger.error(error)
return load_array
Expand Down Expand Up @@ -293,7 +293,7 @@ def set_inverter_register(register: str, value: str):
resp = "TEST"
if not TEST_MODE:
try:
resp = requests.request('POST', url, headers=headers, json=payload)
resp = requests.request('POST', url, headers=headers, json=payload, timeout=10)
except requests.exceptions.RequestException as error:
logger.error(error)
return
Expand All @@ -317,7 +317,7 @@ def set_inverter_register(register: str, value: str):
payload = {}

try:
resp = requests.request('POST', url, headers=headers, json=payload)
resp = requests.request('POST', url, headers=headers, json=payload, timeout=10)
except resp.exceptions.RequestException as error:
logger.error(error)
return
Expand Down Expand Up @@ -593,9 +593,9 @@ def get_solcast(url) -> Tuple[bool, str]:
pv_est90 = [0] * 10080

if stgs.Solcast.url_sw != "": # Two arrays are specified
forecast_lines = min(len(solcast_data_1['forecasts']), len(solcast_data_2['forecasts']))
forecast_lines = min(len(solcast_data_1['forecasts']), len(solcast_data_2['forecasts'])) - 1
else:
forecast_lines = len(solcast_data_1['forecasts'])
forecast_lines = len(solcast_data_1['forecasts']) - 1
interval = int(solcast_data_1['forecasts'][0]['period'][2:4])
solcast_offset = (60 * int(solcast_data_1['forecasts'][0]['period_end'][11:13]) +
int(solcast_data_1['forecasts'][0]['period_end'][14:16]) - interval - 60)
Expand All @@ -608,17 +608,21 @@ def get_solcast(url) -> Tuple[bool, str]:
i = solcast_offset
cntr = 0
while i < solcast_offset + forecast_lines * interval:
if stgs.Solcast.url_sw != "": # Two arrays are specified
pv_est10[i] = (int(solcast_data_1['forecasts'][cntr]['pv_estimate10'] * 1000) +
int(solcast_data_2['forecasts'][cntr]['pv_estimate10'] * 1000))
pv_est50[i] = (int(solcast_data_1['forecasts'][cntr]['pv_estimate'] * 1000) +
int(solcast_data_2['forecasts'][cntr]['pv_estimate'] * 1000))
pv_est90[i] = (int(solcast_data_1['forecasts'][cntr]['pv_estimate90'] * 1000) +
int(solcast_data_2['forecasts'][cntr]['pv_estimate90'] * 1000))
else:
pv_est10[i] = int(solcast_data_1['forecasts'][cntr]['pv_estimate10'] * 1000)
pv_est50[i] = int(solcast_data_1['forecasts'][cntr]['pv_estimate'] * 1000)
pv_est90[i] = int(solcast_data_1['forecasts'][cntr]['pv_estimate90'] * 1000)
try:
if stgs.Solcast.url_sw != "": # Two arrays are specified
pv_est10[i] = (int(solcast_data_1['forecasts'][cntr]['pv_estimate10'] * 1000) +
int(solcast_data_2['forecasts'][cntr]['pv_estimate10'] * 1000))
pv_est50[i] = (int(solcast_data_1['forecasts'][cntr]['pv_estimate'] * 1000) +
int(solcast_data_2['forecasts'][cntr]['pv_estimate'] * 1000))
pv_est90[i] = (int(solcast_data_1['forecasts'][cntr]['pv_estimate90'] * 1000) +
int(solcast_data_2['forecasts'][cntr]['pv_estimate90'] * 1000))
else:
pv_est10[i] = int(solcast_data_1['forecasts'][cntr]['pv_estimate10'] * 1000)
pv_est50[i] = int(solcast_data_1['forecasts'][cntr]['pv_estimate'] * 1000)
pv_est90[i] = int(solcast_data_1['forecasts'][cntr]['pv_estimate90'] * 1000)
except Exception:
logger.error("Error: Unexpected end of Solcast data. i="+ str(i)+ "cntr="+ str(cntr))
break

if i > 1 and i % interval == 0:
cntr += 1
Expand Down Expand Up @@ -698,7 +702,7 @@ def t_to_hrs(time_in: int) -> str:

# if exists(ge.batcap):
# logger.info("Battery Capacity: "+ str(ge.batcap))

# Solcast PV prediction object initialisation
solcast: SolcastObj = SolcastObj()
solcast.update()
Expand Down

0 comments on commit f9ba1fc

Please sign in to comment.