Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,23 @@ class EzvizTuyaAutomation:
|
|
| 23 |
self.is_running = False
|
| 24 |
self.status_queue = queue.Queue()
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def get_ezviz_devices(self):
|
| 27 |
"""Get list of EZVIZ cameras"""
|
| 28 |
if not self.ezviz_access_token:
|
|
@@ -129,7 +146,8 @@ def create_ui():
|
|
| 129 |
'tuya_client_id': tuya_id,
|
| 130 |
'tuya_secret': tuya_secret
|
| 131 |
})
|
| 132 |
-
|
|
|
|
| 133 |
|
| 134 |
def get_devices():
|
| 135 |
# Attempt to fetch devices
|
|
|
|
| 23 |
self.is_running = False
|
| 24 |
self.status_queue = queue.Queue()
|
| 25 |
|
| 26 |
+
def fetch_ezviz_token(self):
|
| 27 |
+
"""Fetch and set EZVIZ access token"""
|
| 28 |
+
url = f"{self.ezviz_base_url}/oauth/token"
|
| 29 |
+
payload = {
|
| 30 |
+
"appKey": self.credentials['ezviz_app_key'],
|
| 31 |
+
"appSecret": self.credentials['ezviz_app_secret']
|
| 32 |
+
}
|
| 33 |
+
try:
|
| 34 |
+
response = requests.post(url, json=payload)
|
| 35 |
+
if response.status_code == 200:
|
| 36 |
+
self.ezviz_access_token = response.json().get("accessToken")
|
| 37 |
+
return "EZVIZ token fetched successfully."
|
| 38 |
+
else:
|
| 39 |
+
return f"Failed to fetch EZVIZ token: {response.text}"
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return f"Error fetching EZVIZ token: {str(e)}"
|
| 42 |
+
|
| 43 |
def get_ezviz_devices(self):
|
| 44 |
"""Get list of EZVIZ cameras"""
|
| 45 |
if not self.ezviz_access_token:
|
|
|
|
| 146 |
'tuya_client_id': tuya_id,
|
| 147 |
'tuya_secret': tuya_secret
|
| 148 |
})
|
| 149 |
+
ezviz_status = automation.fetch_ezviz_token()
|
| 150 |
+
return f"Credentials updated. {ezviz_status}"
|
| 151 |
|
| 152 |
def get_devices():
|
| 153 |
# Attempt to fetch devices
|