From 8e7c53b25d96cea148b877d45be4bee03e4c4938 Mon Sep 17 00:00:00 2001 From: Rich O Date: Wed, 27 Nov 2019 14:11:21 -0500 Subject: [PATCH] Converting JSON to python dict and changed how i'm referencing the information --- r0b3bot.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index a8d2f64..6bfa55b 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -231,24 +231,23 @@ async def printstat(ctx): print(" - Getting Printer Light Status") #work_lights = remote.get_state(hassapi, 'switch.work_lights') work_lights = requests.get(hassURL, headers=hassHEADERS) - print(f" Response from HomeAssistant: {work_lights.text}") + print(f" JSON Response from HomeAssistant: {work_lights.text}") + + work_lights = json.loads(work_lights.text) # Making sure that the API request succeeded. If it has, there will be a state attribute added to # work_lights. try: - work_lights.state() + work_lights["state"] except: print(" ! Unable to get light status from Homeassistant, notifying chat channel") await ctx.send("Hmm, I can't tell if the light is on... oh well [Hass API error]") - # Create State class and add state attribute to work_lights - class State: - state = "unknown" - work_lights = State() - work_lights.state = "Unknown" + # Create empty dict w/ state of unknown + work_lights = {'state': "unknown"} # If the light is off, let's turn it on before we take a picture - if work_lights.state == 'off': + if work_lights["state"] == 'off': print(" - Lights are off, turning on for image capture") turned_on_light = True try: -- 2.39.5