Skip to content

Commit

Permalink
Merge pull request #10 from bastoscorp/staging
Browse files Browse the repository at this point in the history
Staging to main
  • Loading branch information
bastoscorp authored Jul 17, 2024
2 parents 092144f + 092311e commit 8e67dff
Show file tree
Hide file tree
Showing 22 changed files with 530 additions and 593 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Python application

on:
push:
branches: [ "staging" ]
branches: [ "dev", "staging", "main" ]
pull_request:
branches: [ "main", "staging" ]
branches: [ "main" ]


permissions:
Expand Down
5 changes: 4 additions & 1 deletion business/actionDeviceManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_device_status(self, dev_type: str, dev_name: str):
status = dev_manager.get_device_status(dev_name)
return status
if dev_type == "testing":
if self.testing_status.get(dev_name) == None:
if self.testing_status.get(dev_name) is None:
if randrange(10) % 2 == 0:
status = {'status': True,
'message': "powered on"
Expand All @@ -31,6 +31,7 @@ def get_device_status(self, dev_type: str, dev_name: str):
return self.testing_status.get(dev_name)
else:
logging.warning(dev_type + " device type not implemented")
return status

def enable_device(self, dev_type: str, dev_name: str):
status = None
Expand All @@ -46,6 +47,7 @@ def enable_device(self, dev_type: str, dev_name: str):
return True
else:
logging.warning(dev_type + " device type not implemented")
return status

def disable_device(self, dev_type: str, dev_name: str):
status = None
Expand All @@ -61,3 +63,4 @@ def disable_device(self, dev_type: str, dev_name: str):
return True
else:
logging.warning(dev_type + " device type not implemented")
return status
2 changes: 1 addition & 1 deletion business/actionDevicePhilipsHue.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class ActionDevicePhilipsHue:
config: Config = None
bridge_ip: str = None
bridge_ip: str = ''
bridge_ip_token: str = "<bridge_ip>"

def __init__(self, conf: Config):
Expand Down
7 changes: 1 addition & 6 deletions business/alertManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ class AlertManager:
def __init__(self, conf: Config):
self.config = conf

def sendAlert(self, message):
def send_alert(self, message):
url = self.config.alert_configured_url

headers = {
"Title": self.config.alert_title,
#"Priority": "urgent",
"Tags": "warning"
}

Expand All @@ -27,7 +26,3 @@ def sendAlert(self, message):
else:
logging.error("cannot send alert")
return False




12 changes: 6 additions & 6 deletions business/connectManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
from config.config import Config


def decode_pwd(encoded):
decoded_bytes = base64.b64decode(encoded)
decoded_string = decoded_bytes.decode("utf-8").rstrip()
return decoded_string


class ConnectManager:
session_cookie = {}
Expand All @@ -29,14 +34,9 @@ def init_session(self):
if not self.load_session():
self.login()

def decode_pwd(self, encoded):
decoded_bytes = base64.b64decode(encoded)
decoded_string = decoded_bytes.decode("utf-8").rstrip()
return decoded_string

def login(self):
uri = self.config.loginUri
data = {"userName": self.config.userName, "systemCode": self.decode_pwd(self.config.systemCode)}
data = {"userName": self.config.userName, "systemCode": decode_pwd(self.config.systemCode)}
json_data = json.dumps(data)
try:
response = requests.post(uri, data=json_data)
Expand Down
4 changes: 0 additions & 4 deletions business/inverterDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ class InverterDevice:
# 768 mean --KO
power = ""
temperature = ""




76 changes: 36 additions & 40 deletions business/inverterRules.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@

class InverterRules:

ok_status = 512
ko_status = 768


status_list = {
"0":{"message": "Standby: initializing", "type": "warning"},
"1":{"message":"Standby: insulation resistance detecting", "type": "warning"},
"2":{"message":"Standby: irradiation detecting", "type": "warning"},
"3":{"message":"Standby: grid detecting", "type": "warning"},
"256":{"message":"Start", "type": "ok"},
"512":{"message":"Grid-connected", "type": "ok"},
"513":{"message":"Grid-connected: power limited", "type": "ok"},
"514":{"message":"Grid-connected: self-derating", "type": "ok"},
"515":{"message":"Off-grid operation","type": "warning"},
"768":{"message":"Shutdown: on fault", "type": "error"},
"769":{"message":"Shutdown: on command", "type": "error"},
"770":{"message":"Shutdown: OVGR", "type": "error"},
"771":{"message":"Shutdown: communication interrupted", "type": "error"},
"772":{"message":"Shutdown: power limited", "type": "error"},
"773":{"message":"Shutdown: manual startup required", "type": "error"},
"774":{"message":"Shutdown: DC switch disconnected", "type": "error"},
"775":{"message":"Shutdown: rapid shutdown","type": "error"},
"776":{"message":"Shutdown: input underpower","type": "error"},
"777":{"message":"Shutdown: NS protection","type": "error"},
"778":{"message":"Shutdown: commanded rapid shutdown","type": "error"},
"1025":{"message":"Grid scheduling: cosφ-P curve", "type": "warning"},
"1026":{"message":"Grid scheduling: Q-U curve","type": "warning"},
"1027":{"message":"Power grid scheduling: PF-U characteristic curve","type": "warning"},
"1028":{"message":"Grid scheduling: dry contact","type": "warning"},
"1029":{"message":"Power grid scheduling: Q-P characteristic curve","type": "warning"},
"1280":{"message":"Ready for terminal test","type": "warning"},
"1281":{"message":"Terminal testing...","type": "warning"},
"1536":{"message":"Inspection in progress","type": "warning"},
"1792":{"message":"AFCI self-check","type": "warning"},
"2048":{"message":"I-V scanning","type": "warning"},
"2304":{"message":"DC input detection","type": "warning"},
"2560":{"message":"Off-grid charging","type": "warning"},
"40960":{"message":"Standby: no irradiation","type": "warning"},
"40961":{"message":"Standby: no DC input","type": "warning"},
"45056":{"message":"Communication interrupted (written by SmartLogger)","type": "error"},
"49152":{"message":"Loading... (written by SmartLogger)","type": "warning"},
"0": {"message": "Standby: initializing", "type": "warning"},
"1": {"message": "Standby: insulation resistance detecting", "type": "warning"},
"2": {"message": "Standby: irradiation detecting", "type": "warning"},
"3": {"message": "Standby: grid detecting", "type": "warning"},
"256": {"message": "Start", "type": "ok"},
"512": {"message": "Grid-connected", "type": "ok"},
"513": {"message": "Grid-connected: power limited", "type": "ok"},
"514": {"message": "Grid-connected: self-derating", "type": "ok"},
"515": {"message": "Off-grid operation", "type": "warning"},
"768": {"message": "Shutdown: on fault", "type": "error"},
"769": {"message": "Shutdown: on command", "type": "error"},
"770": {"message": "Shutdown: OVGR", "type": "error"},
"771": {"message": "Shutdown: communication interrupted", "type": "error"},
"772": {"message": "Shutdown: power limited", "type": "error"},
"773": {"message": "Shutdown: manual startup required", "type": "error"},
"774": {"message": "Shutdown: DC switch disconnected", "type": "error"},
"775": {"message": "Shutdown: rapid shutdown", "type": "error"},
"776": {"message": "Shutdown: input underpower", "type": "error"},
"777": {"message": "Shutdown: NS protection", "type": "error"},
"778": {"message": "Shutdown: commanded rapid shutdown", "type": "error"},
"1025": {"message": "Grid scheduling: cosφ-P curve", "type": "warning"},
"1026": {"message": "Grid scheduling: Q-U curve", "type": "warning"},
"1027": {"message": "Power grid scheduling: PF-U characteristic curve", "type": "warning"},
"1028": {"message": "Grid scheduling: dry contact", "type": "warning"},
"1029": {"message": "Power grid scheduling: Q-P characteristic curve", "type": "warning"},
"1280": {"message": "Ready for terminal test", "type": "warning"},
"1281": {"message": "Terminal testing...", "type": "warning"},
"1536": {"message": "Inspection in progress", "type": "warning"},
"1792": {"message": "AFCI self-check", "type": "warning"},
"2048": {"message": "I-V scanning", "type": "warning"},
"2304": {"message": "DC input detection", "type": "warning"},
"2560": {"message": "Off-grid charging", "type": "warning"},
"40960": {"message": "Standby: no irradiation", "type": "warning"},
"40961": {"message": "Standby: no DC input", "type": "warning"},
"45056": {"message": "Communication interrupted (written by SmartLogger)", "type": "error"},
"49152": {"message": "Loading... (written by SmartLogger)", "type": "warning"},
}

6 changes: 2 additions & 4 deletions business/powerUsageRules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

class PowerUsageRules():

class PowerUsageRules:
rules = [{'rule_id': 1,
'rule_name': "Pool Heating Threshold",
'rule_remaining_power_value': 1000,
Expand All @@ -9,4 +7,4 @@ class PowerUsageRules():
'action_device_name': 'PAC piscine',
'action_device_type': 'philips_hue'
}
]
]
2 changes: 1 addition & 1 deletion business/powersensorDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class PowersensorDevice:

power: float = None
# 100
# -3159.0
# -3159.0
2 changes: 1 addition & 1 deletion business/powersensorRules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ class PowersensorRules:

ok_status = 1
# 1 mean --> OK
# other mean --KO
# other mean --KO
Loading

0 comments on commit 8e67dff

Please sign in to comment.