Skip to content

Commit

Permalink
maj adr
Browse files Browse the repository at this point in the history
  • Loading branch information
m4dm4rtig4n committed Oct 4, 2021
1 parent 7d4d65f commit d3b6b05
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
/data
/app/__pycache__/
/app/__pycache__/
/tmp
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ volumes:
- Add **DJU18**
- Add HC/HP
- Create Home Assistant OS Addons
- Add Postgres/MariaDB connector
- Add Postgres/MariaDB connector*
- Add option export W or kWh

## Change log:

Expand Down
18 changes: 11 additions & 7 deletions app/daily.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ def getDaily(cur, client, mode="consumption", last_activation_date=datetime.now(
for key, value in data.items():
f.publish(client, f"{pdl}/{mode}/current_year/errorMsg/{key}", str(value))
else:
f.publish(client, f"{pdl}/{mode}/current_year/error", str(0))
for key, value in data.items():

if key != "dateBegin" and key != "dateEnded":
current_value = int(value["value"])
current_date = value["date"]
current_date = datetime.strptime(current_date, '%Y-%m-%d')
day = current_date.strftime('%A')
f.publish(client, f"{pdl}/{mode}/current_year/{key}", str(current_value))
ha_discovery[pdl].update({
f"{mode}_{key.replace('-', '_')}": {
"value": str(current_value),
Expand Down Expand Up @@ -100,6 +103,7 @@ def getDaily(cur, client, mode="consumption", last_activation_date=datetime.now(
current_date = value["date"]
current_date = datetime.strptime(current_date, '%Y-%m-%d')
day = current_date.strftime('%A')
f.publish(client, f"{pdl}/{mode}/year-{current_year}/{key}", str(current_value))
if f"{mode}_{key.replace('-', '_')}" in ha_discovery[pdl]:
# CALC VARIATION
if key in lastData:
Expand Down Expand Up @@ -283,37 +287,37 @@ def dailyBeetwen(cur, pdl, mode, dateBegin, dateEnded, last_activation_date):

# WEEK DAYS
if current_date == j1:
response[day] = {
response[f"week/{day}"] = {
"value": value,
"date": date
}
if current_date == j2:
response[day] = {
response[f"week/{day}"] = {
"value": value,
"date": date
}
if current_date == j3:
response[day] = {
response[f"week/{day}"] = {
"value": value,
"date": date
}
if current_date == j4:
response[day] = {
response[f"week/{day}"] = {
"value": value,
"date": date
}
if current_date == j5:
response[day] = {
response[f"week/{day}"] = {
"value": value,
"date": date
}
if current_date == j6:
response[day] = {
response[f"week/{day}"] = {
"value": value,
"date": date
}
if current_date == j7:
response[day] = {
response[f"week/{day}"] = {
"value": value,
"date": date
}
Expand Down
3 changes: 2 additions & 1 deletion app/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def on_connect(client, userdata, flags, rc):
if rc == 0:
log("Connected to MQTT Broker!")
else:
log("Failed to connect, return code %d\n", rc)
log(f"Failed to connect, return code {rc}\n")
quit()

# Set Connecting Client ID
client = mqtt_client.Client(main.client_id)
Expand Down
7 changes: 5 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,11 @@
api_no_result = []

def run():
client = f.connect_mqtt()
client.loop_start()
try:
client = f.connect_mqtt()
client.loop_start()
except:
f.log("MQTT : Connection failed")

# client = f.connect_mqtt()
# f.subscribe(client,topic)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ services:
YEARS: 1
BASE_PRICE: 0.1445
volumes:
mydata:
mydata:

0 comments on commit d3b6b05

Please sign in to comment.