Variable no longer exists

Posted on
Thu Jan 20, 2022 5:44 pm
ryanbuckner offline
Posts: 1081
Joined: Oct 08, 2011
Location: Northern Virginia

Variable no longer exists

I get this Indigo error sporadically. This python file contains a script that gets the ON/OFF status from my Samsung TV and returns it. The action stores the result (true/false) in a variable,. It runs n a schedule every 30 seconds. Not sure if the error is accurate, but seems to indicate that the variable is not there. It is.

It runs error free 90% of the time. Matt & Jay, the error itself also has a typo :)


Code: Select all
Jan 20, 2022 at 6:20:47 PM
   Action Collection Error         Run Shell Script action: varible used to store script result for script /Library/Application Support/Perceptive Automation/Python2-includes/tvgetstatus.py no longer exists.


Posted on
Sun Jan 23, 2022 3:19 pm
matt (support) offline
Site Admin
User avatar
Posts: 21429
Joined: Jan 27, 2003
Location: Texas

Re: Variable no longer exists

Can you post the complete script?

Image

Posted on
Mon Jan 24, 2022 11:18 am
ryanbuckner offline
Posts: 1081
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Variable no longer exists

matt (support) wrote:
Can you post the complete script?


Here's the script. It runs as Shell Script and places the output in the variable listed

Code: Select all
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import os
from samsungtvws import SamsungTVWS
import signal
import urllib3

urllib3.disable_warnings()
sys.path.append('../')


def signal_handler(signum, frame):
    raise Exception("Timed out!")


def status_function_call():
    tv = SamsungTVWS('192.168.1.209')

    # Autosave token to file
    token_file = os.path.dirname(os.path.realpath(__file__)) + '/tv-token.txt'
    tv = SamsungTVWS(host='192.168.1.209', port=8002, token_file=token_file)
    info = tv.rest_device_info()
    tvState = info['device']['PowerState']

    return tvState


signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(5)   # Five seconds

try:
    tvstatus = status_function_call()
except Exception as msg:
    tvstatus = 'off'

print(tvstatus.strip(), end="")


tvstatus.png
tvstatus.png (102.32 KiB) Viewed 953 times

Posted on
Mon Jan 24, 2022 4:46 pm
jay (support) offline
Site Admin
User avatar
Posts: 18260
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Variable no longer exists

I suspect that the output from your script sometimes results in garbage, so when we try to update the variable it fails. I'm not sure how, but there is only one line of code in the try block that results in that error message. Only two things can result: either the variable doesn't exist or the output is somehow bad. We assume that the script output is a valid string, but it's possible that the script is returning something else. Since the variable can't be disappearing and reappearing with the same ID, then it must be the later.

I wonder if there is a scenario where tvstatus isn't actually a string, so tvstatus.strip() fails. I suspect that an uncaught exception might just cause the variable update to fail.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 27, 2022 8:37 am
ryanbuckner offline
Posts: 1081
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Variable no longer exists

I added the following line to see if that is the case.

Code: Select all
if tvstatus not in ('on','off'):
    tvstatus = 'off'

Posted on
Sat Feb 12, 2022 10:59 am
ryanbuckner offline
Posts: 1081
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Variable no longer exists

ryanbuckner wrote:
I added the following line to see if that is the case.

Code: Select all
if tvstatus not in ('on','off'):
    tvstatus = 'off'


Since adding this line I haven't seen the error return. Tho it does seem that Indigo wasn't reporting the correct error

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests