fix 'enable' button
This commit is contained in:
parent
e3df1052ef
commit
be329733bd
25
pymhcgui.py
25
pymhcgui.py
@ -6,36 +6,39 @@ import json
|
||||
import time
|
||||
|
||||
# Variable pour stocker l'adresse IP
|
||||
server_ip = "127.0.0.1" # Adresse IP par défaut
|
||||
server_ip = "192.168.1.111" # Adresse IP par défaut
|
||||
|
||||
# Fonction pour envoyer la commande de démarrage ou d'arrêt de la chauffe
|
||||
def toggle_heating_state(heating_button, current_state):
|
||||
def toggle_heating_state(heating_button):
|
||||
|
||||
try:
|
||||
global server_ip
|
||||
if server_ip is None:
|
||||
raise ValueError("L'adresse IP du serveur n'est pas définie.")
|
||||
|
||||
port = 4623 # Port du serveur
|
||||
|
||||
|
||||
btcolor = heating_button.cget("bg")
|
||||
current_state = 0 if btcolor == "gray" else 0
|
||||
|
||||
# Si la chauffe est active (vert), envoyer la commande "stop"
|
||||
if current_state == "HEATING":
|
||||
print("stop")
|
||||
if current_state == 1:
|
||||
# print("stop")
|
||||
command = "stop"
|
||||
heating_button.config(bg="gray", text="Chauffe inactive")
|
||||
# Si la chauffe est inactive (gris), envoyer la commande "start"
|
||||
elif current_state == "IDLE":
|
||||
print("start")
|
||||
else:
|
||||
# print("start")
|
||||
command = "start"
|
||||
heating_button.config(bg="green", text="Chauffe active")
|
||||
else:
|
||||
return # Ne rien faire si l'état est inconnu
|
||||
|
||||
|
||||
# Créer la commande à envoyer au serveur
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.connect((server_ip, port))
|
||||
# Envoi de la commande
|
||||
s.sendall(command.encode('utf-8'))
|
||||
print(f"Commande envoyée : {command}")
|
||||
# print(f"Commande envoyée : {command}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Erreur lors de l'envoi de la commande de chauffe : {e}")
|
||||
@ -267,7 +270,7 @@ def create_app():
|
||||
target_button.pack(pady=10)
|
||||
|
||||
# Bouton pour gérer la chauffe
|
||||
heating_button = tk.Button(root, text="Chauffe inactive", bg="gray", width=15, height=2)
|
||||
heating_button = tk.Button(root, text="Chauffe inactive", bg="gray", width=15, height=2, command=lambda: toggle_heating_state(heating_button))
|
||||
heating_button.pack(pady=10)
|
||||
|
||||
# Fonction de mise à jour des widgets après chaque lecture
|
||||
|
||||
Loading…
Reference in New Issue
Block a user