added try/except to check for state attribute #14

Merged
Rich merged 1 commits from 3-r0b3bot-does-not-handle-homeassistant-api-failure-gracefully into master 2019-11-22 14:35:15 +00:00
+7 -1
View File
@@ -222,14 +222,20 @@ async def printstat(ctx):
# We weren't able to get the status. Display this text to the chat channel
print(" ! Unable to get light status, notifying chat channel")
await ctx.send("Hmm, I can't tell if the light is on... oh well")
try:
work_lights.state()
except:
print(" ! Unable to get light status, notifying chat channel")
await ctx.send("Hmm, I can't tell if the light is on... oh well")
class State:
state = "unknown"
work_lights = State()
work_lights.state = "Unknown"
# If the light is off, let's turn it on before we take a picture
print(" - Lights are off, turning on for image capture")
if work_lights.state == 'off':
print(" - Lights are off, turning on for image capture")
turned_on_light = True
try:
# REST API call to home assistant to turn the light off.