@@ -101,6 +101,8 @@ def main():
101101 parser .add_argument ('args' , nargs = '*' )
102102 parser .add_argument ('--ssl' , action = 'store_true' )
103103 parser .add_argument ('--debug' , '-d' , action = 'store_true' , help = 'enable debug output' )
104+ parser .add_argument ('--list' , '-l' , action = 'store_true' , help = 'list tv\' s and exit' )
105+ parser .add_argument ('--json' , '-j' , action = 'store_true' , help = 'output in json format' )
104106 args = parser .parse_args ()
105107
106108 logging .basicConfig (level = logging .DEBUG if args .debug else logging .INFO )
@@ -112,20 +114,42 @@ def main():
112114 with open (filename , "r" ) as f :
113115 config = json .load (f )
114116
117+ if args .list :
118+ for tv in config .keys ():
119+ if tv == '_default' :
120+ continue
121+ if args .json :
122+ print (json .dumps (config ))
123+ else :
124+ print (f"{ tv } : { config [tv ]['hostname' ]} ({ config [tv ]['ip' ]} , { config [tv ]['mac' ]} )" )
125+ if not args .json :
126+ if '_default' in config .keys ():
127+ print (f"Default is: { config ['_default' ]} " )
128+ else :
129+ print ("No default specified" )
130+ return
131+
115132 if args .command == "scan" :
116133 results = LGTVScan ()
117134 if len (results ) > 0 :
118- print (json .dumps ({
119- "result" : "ok" ,
120- "count" : len (results ),
121- "list" : results
122- }))
135+ if args .json :
136+ print (json .dumps ({
137+ "result" : "ok" ,
138+ "count" : len (results ),
139+ "list" : results
140+ }))
141+ else :
142+ for result in results :
143+ print (f"{ result ['tv_name' ]} : { result ['address' ]} " )
123144 sys .exit (0 )
124145 else :
125- print (json .dumps ({
126- "result" : "failed" ,
127- "count" : len (results )
128- }))
146+ if args .json :
147+ print (json .dumps ({
148+ "result" : "failed" ,
149+ "count" : len (results )
150+ }))
151+ else :
152+ print ("No LG TV's found" )
129153 sys .exit (1 )
130154
131155 elif args .command == "auth" :
@@ -147,6 +171,10 @@ def main():
147171 if filename is None :
148172 print ("No config file found" )
149173 sys .exit (1 )
174+ if name == '_default' :
175+ print ("Error: default cannot be _default" )
176+ return
177+
150178 if name not in config :
151179 print ("TV not found in config" )
152180 sys .exit (1 )
0 commit comments