add HomeAssistant module and use execute command

This commit is contained in:
2024-05-02 12:55:27 +07:00
parent 6021db52aa
commit 8f1aa07507
6 changed files with 54 additions and 4 deletions
+31
View File
@@ -0,0 +1,31 @@
import requests
from data import config
class HomeAssistant:
def __init__(self):
self.url = "http://192.168.0.112:9999/api"
self.token = config.HOME_ASSISTANT_TOKEN
def get_info(self, state):
response = requests.get(
url=f"{self.url}/states",
headers={
"Authorization": "Bearer " + self.token
}
)
return response
def send_process(self, command="выключи телевизор"):
response = requests.post(
url=f"{self.url}/services/conversation/process",
json={"text": command},
headers={
"Authorization": "Bearer " + self.token,
"content-type": "application/json"
},
)
if response.status_code == 200:
return True
return False