Skip to content

Commit 905236d

Browse files
authored
Merge pull request #32 from Capstone-Projects-2024-Spring/ISH-95
Ish 95 - Get all devices
2 parents 55bb317 + c42eb78 commit 905236d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

app/app.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ def detectHand(hands, img, ASLModel):
4242
return gestureName,img
4343

4444

45-
46-
4745
def detect_motion(last_frame, current_frame, threshold=20):
4846
# Convert frames to grayscale
4947
if last_frame is None:
@@ -68,6 +66,7 @@ def detect_motion(last_frame, current_frame, threshold=20):
6866
print('checking for motion', len(contours))
6967
return len(contours) > 0, current_frame
7068

69+
7170
def toggle_light():
7271
#action = "turn_on" if state else "turn_off"
7372
url = f"http://localhost:8123/api/services/switch/toggle"
@@ -85,6 +84,22 @@ def toggle_light():
8584
return light_state['state'] == 'on'
8685
return None
8786

87+
88+
def get_all_devices(device_type):
89+
url = "http://localhost:8123/api/states"
90+
headers = {
91+
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIyOGU3ZDZmNTg5MjE0MzAxOWQwNTVjZWI5MThmYTcyMCIsImlhdCI6MTcxMjM0NDQ1MywiZXhwIjoyMDI3NzA0NDUzfQ.AXaP5ndD3QFtxhYxfXwT93x6qBh3GacCKmgiTHU6g7A",
92+
"Content-Type": "application/json"
93+
}
94+
response = requests.get(url, headers=headers)
95+
if response.status_code == 200:
96+
devices = response.json()
97+
filtered_devices = [device for device in devices if device_type in device['entity_id']]
98+
return filtered_devices
99+
else:
100+
return None
101+
102+
88103
def black_image(img):
89104
black_screen = np.zeros_like(img)
90105
img = black_screen
@@ -175,6 +190,7 @@ def gen_frames(cap):
175190
yield (b'--frame\r\n'
176191
b'Content-Type: image/jpeg\r\n\r\n' + img + b'\r\n')
177192

193+
178194
app = Flask(__name__)
179195
CORS(app)
180196
#comment this out if mediapipe doesnt work

0 commit comments

Comments
 (0)