From d15dfc9a70fef20fe4a778820d4f5a7def174d78 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Fri, 22 Nov 2019 15:13:51 -0500 Subject: [PATCH] WIP: replacing homeassistant.remote API with REST API --- r0b3bot.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 99891f0..423b74f 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -14,6 +14,7 @@ import json from discord import FFmpegPCMAudio from discord.utils import get from discord.voice_client import VoiceClient +import requests bot = commands.Bot(command_prefix='$', description='A derpy derp of a bot.') @@ -25,15 +26,21 @@ try: except: print("Error loading config! Please check config file 'bot-config.conf'") +# Setup HomeAssistant URL and Headers HASS_API_KEY = config.get('bot-config', 'hass_api_key') HASS_IP_ADDRESS = config.get('bot-config', 'hass_ip_address') HASS_LIGHT = config.get('bot-config', 'hass_light') +hassURL = "http://" + HASS_IP_ADDRESS + ":8123/api/states/" + HASS_LIGHT +hassHEADERS = { + 'Authorization': f'Bearer {HASS_API_KEY}', + 'content-type': 'application/json', +} OCTOPRINT_IP_ADDRESS = config.get('bot-config', 'octoprint_ip_address') DISCORD_AUTH_TOKEN = config.get('bot-config', 'discord_auth_token') - +# This is now deprecated and will be replaced with using the REST hassapi = remote.API(HASS_IP_ADDRESS, HASS_API_KEY) @bot.event @@ -216,8 +223,9 @@ async def printstat(ctx): # Try to get the status of the 3D printer light print(" - Getting Printer Light Status") - work_lights = remote.get_state(hassapi, 'switch.work_lights') - + #work_lights = remote.get_state(hassapi, 'switch.work_lights') + work_lights = requests.get(hassURL, hassHEADERS) + # Making sure that the API request succeeded. If it has, there will be a state attribute added to # work_lights. try: -- 2.39.5