installation et appairage #88
Swatmorpheus
started this conversation in
General
Replies: 2 comments 3 replies
-
Il y a quelques appels d'API supplémentaires pour obtenir vos appareils, je vous suggère de regarder le fichier init.py d'intégration de l'assistant domestique, vous verrez comment collecter tous vos appareils dans le gestionnaire de périphériques |
Beta Was this translation helpful? Give feedback.
2 replies
-
Je suis aussi sous jeedom @Swatmorpheus essaies-tu de faire un plugin ? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
bonjour,
j'ai voulu installer le script qui a été un parcours du combattant , chatgpt m'a aidé a modifier tous les fichiers et j'arrive finalement a me connecter au cloud car on utilisé des app_key et app_secret mais je ne sais pas comment les avoir donc je suis passé par l'email et le mot de passe, mais il ne trouve aucun appareil lier a mon compte c'est étonnant
[root@mosquito:/opt/pymammotion# python3 /opt/pymammotion/test_mammotion.py
xxxxxxx:/opt/pymammotion# python3 /opt/pymammotion/test_mammotion.py Aucun appareil trouvé.
voici le fichier test_mammotion.py
` import sys
2 sys.path.insert(0, "/opt/pymammotion")
3
4 from pymammotion.mammotion.devices.mammotion import Mammotion
5 import asyncio
6 import configparser
7
8 # Chargement de l'email et mot de passe depuis le fichier de config
9 config = configparser.ConfigParser()
10 config.read("/opt/pymammotion/config.ini")
11
12 EMAIL = config['auth']['email']
13 PASSWORD = config['auth']['password']
14 #print(f"Email chargé : {EMAIL}")
15 #print(f"Mot de passe chargé : {PASSWORD}")
16 async def main():
17 client = Mammotion()
18 await client.login(EMAIL, PASSWORD)
19
20 devices = client.device_manager.devices
21
22 if not devices:
23 print("Aucun appareil trouvé.")
24 return
25
26 print("Liste des appareils :")
27 for name, device in devices.items():
28 print(f"- Nom : {name}, ID : {device.device_id}")
29
30 if name == "main":
31 asyncio.run(main())
32
le fichier cloud_gateway.py
1 import json
2 import time
3 import hmac
4 import hashlib
5 import requests
6 import logging
7
8 class CheckSessionException(Exception):
9 pass
10
11 class DeviceOfflineException(Exception):
12 pass
13
14 class SetupException(Exception):
15 pass
16
17 class CloudIOTGateway:
18 def init(self, mammotion_http):
19 self.mammotion_http = mammotion_http
20 self.base_url = "https://api.mammotion.com"
21 self.token = None
22
23
24 def _get_timestamp(self):
25 return str(int(time.time() * 1000))
26
27 def _sign(self, method, path, query_string, headers, body=''):
28 string_to_sign = (
29 f"{method}\n"
30 f"{headers.get('accept', '')}\n"
31 f"\n"
32 f"{headers.get('content-type', '')}\n"
33 f"{headers.get('date', '')}\n"
34 f"{query_string}"
35 )
36 signature = hmac.new(self.mammotion_http.app_secret.encode(), string_to_sign.encode(), hashlib.sha256).hexd>
37 return signature
38
39 def login(self, email, password):
40 path = "/api/user/login"
41 method = "POST"
42 body_dict = {"email": email, "password": password}
43 body = json.dumps(body_dict)
44 query_string = f"loginByOauthRequest={body}"
45
46 headers = {
47 "accept": "application/json",
48 "content-type": "application/json",
49 "date": self._get_timestamp(),
50 "x-ca-key": self.mammotion_http.app_key,
51 }
52 signature = self._sign(method, path, query_string, headers, body)
53 headers["x-ca-signature"] = signature
54 headers["x-ca-signature-headers"] = "accept,content-type,date,x-ca-key"
55
56 url = self.base_url + path + "?" + query_string
57 response = requests.post(url, headers=headers)
58 response.raise_for_status()
59 data = response.json()
60 self.token = data.get("token")
61 return self.token
62
63 def get_devices(self):
64 if not self.token:
65 raise Exception("Not authenticated, call login() first.")
66 path = "/api/user/devices"
67 method = "GET"
68 query_string = ""
69 headers = {
70 "accept": "application/json",
71 "content-type": "application/json",
72 "date": self._get_timestamp(),
73 "x-ca-key": self.mammotion_http.app_key,
74 "authorization": self.token,
75 }
76 signature = self._sign(method, path, query_string, headers)
77 headers["x-ca-signature"] = signature
78 headers["x-ca-signature-headers"] = "accept,content-type,date,x-ca-key,authorization"
79
80 url = self.base_url + path
81 response = requests.get(url, headers=headers)
82 response.raise_for_status()
83 return response.json()
84
85 def send_command(self, device_id, command):
86 if not self.token:
87 raise Exception("Not authenticated, call login() first.")
88 path = "/api/device/command"
89 method = "POST"
90 body_dict = {
91 "device_id": device_id,
92 "command": command
93 }
94 body = json.dumps(body_dict)
95 query_string = ""
96
97 headers = {
98 "accept": "application/json",
99 "content-type": "application/json",
100 "date": self._get_timestamp(),
101 "x-ca-key": self.mammotion_http.app_key,
102 "authorization": self.token,
103 }
104 signature = self._sign(method, path, query_string, headers, body)
105 headers["x-ca-signature"] = signature
106 headers["x-ca-signature-headers"] = "accept,content-type,date,x-ca-key,authorization"
107
108 url = self.base_url + path
109 response = requests.post(url, headers=headers, data=body)
110 response.raise_for_status()
111 return response.json()
112 async def get_region(self, country_code):
113 # Cette méthode est requise par le client mais pas encore implémentée
114 # On la met vide pour le moment, cela permet au reste du code de fonctionner
115 logging.debug(f"[get_region] Called with country_code={country_code}, but not implemented.")
116 pass
117 async def connect(self):
118 logging.debug("[connect] Méthode connect appelée (non implémentée)")
119 pass
120 async def aep_handle(self):
121 logging.debug("[aep_handle] Appel fictif de aep_handle()")
122 pass
123
124 async def session_by_auth_code(self):
125 logging.debug("[session_by_auth_code] Appel fictif de session_by_auth_code()")
126 pass
127
128 async def list_binding_by_account(self):
129 logging.debug("[list_binding_by_account] Appel fictif de list_binding_by_account()")
130 pass
131 async def login_by_oauth(self, country_code):
132 logging.debug(f"[login_by_oauth] Appel fictif avec le code pays: {country_code}")
133 pass
134
135 async def aep_handle(self):
136 logging.debug("[aep_handle] Appel fictif de aep_handle()")
137 pass
138
139 async def session_by_auth_code(self):
140 logging.debug("[session_by_auth_code] Appel fictif de session_by_auth_code()")
141 pass
142
143 async def list_binding_by_account(self):
144 logging.debug("[list_binding_by_account] Appel fictif de list_binding_by_account()")
145 pass
146
147 # Ajoute d’autres méthodes selon besoin, en suivant ce modèle.
148
149 if name == "main":
150 logging.basicConfig(level=logging.DEBUG)
151 app_key = "TA_CLE_APP"
152 app_secret = "TON_SECRET_APP"
153 email = "[email protected]"
154 password = "tonMotDePasse"
155
156 gateway = CloudIOTGateway(app_key, app_secret)
157 try:
158 token = gateway.login(email, password)
159 print("Connexion réussie, token:", token)
160 devices = gateway.get_devices()
161 print("Liste des appareils:", devices)
162 except Exception as e:
163 print("Erreur:", e)`
je me pose la question pourquoi je ne récupère pas mon appareil alors que ma connexion au cloud est bonne
cordialement
Beta Was this translation helpful? Give feedback.
All reactions