Here is documentation:[
- Code: Select all
# ######################################################
CLASS DEFINITION:
class my_class:
def __init__(self, dev_name): # init method or constructor
self.dev_name = dev_name
def my_get_phone_status(self):
# ######################################################
# Get Phone Status
# ######################################################
device = self.dev_name
indigo.server.log("from inside, name = ", device)
# print("from inside, name = ", device)
# return (device)
dev = indigo.devices[device]
h = dev.states
x = h.get ('status')
return (str(x))
# ######################################################
CALLING W/CLASS IMBEDDED INLINE:
xxx = my_class("SJK Pixel 3A XL")
status = xxx.my_get_phone_status()
indigo.server.log ("current status = ", status)
# ######################################################
OUTPUT:
Apr 23, 2021 at 7:34:12 AM
SJK Pixel 3A XL from inside, name =
up current status =
# ######################################################
CALLING W/CLASS IMPORTED:
from My_file import my_class
xxx = my_class("SJK Pixel 3A XL")
status = xxx.my_get_phone_status()
indigo.server.log ("current status = ", status)
# ######################################################
OUTPUT:
Apr 23, 2021 at 7:34:38 AM
Script Error embedded script: global name 'indigo' is not defined
Script Error Exception Traceback (most recent call shown last):
embedded script, line 3, at top level
File "/Users/stanleykrasnow/Google Drive/1 DCQ Home Automatiion - Python/Utilities/My_file.py", line 22, in <module>
status = xxx.my_get_phone_status()
File "/Users/stanleykrasnow/Google Drive/1 DCQ Home Automatiion - Python/Utilities/My_file.py", line 9, in my_get_phone_status
indigo.server.log("from inside, name = ", device)
NameError: global name 'indigo' is not defined