PoC (pas testes en utilisant les API EDF)
This commit is contained in:
@ -3,6 +3,9 @@
|
||||
# EcoDevice (not the RT one) can be ip address or FQDN
|
||||
ecodevice = "192.0.2.1"
|
||||
|
||||
# Use EcoDevice or EDF "API"
|
||||
use_eco = True
|
||||
|
||||
# MQTT Broker (or GX with MQTT enabled)
|
||||
gx = "192.0.2.2"
|
||||
|
||||
|
||||
@ -7,6 +7,8 @@ import time
|
||||
import pyprowl
|
||||
#import syslog
|
||||
|
||||
from datetime import date,datetime
|
||||
|
||||
# Settings
|
||||
from secret import ecodevice,gx,gxsn,chgbleu,chgblanc,chgrouge,minbleu,minblanc,minrouge,prowlkey
|
||||
|
||||
@ -115,11 +117,13 @@ except Exception as e:
|
||||
print("Error verifying Prowl API key: {}".format(e))
|
||||
exit()
|
||||
|
||||
# Setup EcoDevice
|
||||
http = urllib3.PoolManager()
|
||||
resp = http.request("GET", "http://"+ecodevice+"/api/xdevices.json?cmd=10")
|
||||
|
||||
if resp.status == 200:
|
||||
http = urllib3.PoolManager()
|
||||
if use_eco:
|
||||
# Setup EcoDevice
|
||||
resp = http.request("GET", "http://"+ecodevice+"/api/xdevices.json?cmd=10")
|
||||
|
||||
if resp.status == 200:
|
||||
teleinfo = json.loads(resp.data)
|
||||
|
||||
# Value of var today daynight
|
||||
@ -152,6 +156,7 @@ if resp.status == 200:
|
||||
today = 0
|
||||
daynight = 0
|
||||
|
||||
|
||||
# Value of var tomorrow
|
||||
# ---- = Bleu 0
|
||||
# BLEU = Bleu 0
|
||||
@ -169,10 +174,51 @@ if resp.status == 200:
|
||||
else:
|
||||
tomorrow=0
|
||||
|
||||
|
||||
loggerinfo("Current tarif: " + curtarif + " ("+str(today)+" / "+str(daynight) + ")")
|
||||
loggerinfo("Demain tarif: " + demaintarif + " ("+str(tomorrow)+")")
|
||||
|
||||
else:
|
||||
# Use EDF "API"
|
||||
# TODO:
|
||||
today=date.today()
|
||||
resp = http.request("GET", "https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant="+str(date..strftime("%Y-%m-%d")))
|
||||
if resp.status == 200:
|
||||
edfapi = json.loads(resp.data)
|
||||
curcouleur = edfapi['couleurJourJ']
|
||||
demaincouleur = edfapi['couleurJourJ1']
|
||||
|
||||
if curcouleur == "TEMPO_BLEU":
|
||||
today = 0
|
||||
elif curcouleur == "TEMPO_BLANC":
|
||||
today = 1
|
||||
elif curcouleur == "TEMPO_ROUGE":
|
||||
today = 2
|
||||
else:
|
||||
today = -1
|
||||
|
||||
if demaincouleur == "TEMPO_BLEU":
|
||||
tomorrow = 0
|
||||
elif domaincouleur == "TEMPO_BLANC":
|
||||
tomorrow = 1
|
||||
elif demaincouleur == "TEMPO_ROUGE":
|
||||
tomorrow = 2
|
||||
elif demaincouleur == "NON_DEFINI":
|
||||
tomorrow = -1
|
||||
else:
|
||||
tomorrow = -1 # trop tot.
|
||||
|
||||
now = datetime.now()
|
||||
#Heures creuses: 22h00 -> 06h00
|
||||
if now.hour >= 6 and now.hour <=22:
|
||||
daynight = 1
|
||||
else:
|
||||
daynight = 0
|
||||
|
||||
if tomorrow == -1:
|
||||
loggerinfo("La couleur de demain n'est pas d<>finie -> exit")
|
||||
quit()
|
||||
|
||||
|
||||
# daynight : 1 = jour / 0 nuit
|
||||
# Today Tomorrow Daynight Action
|
||||
# 0 0 O Rien
|
||||
|
||||
Reference in New Issue
Block a user