Advertisement
DevTricks

TV Control

Aug 10th, 2021
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.75 KB | None | 0 0
  1. import requests
  2. from PyQt5 import QtWidgets, uic
  3. app = QtWidgets.QApplication([])
  4. ui = uic.loadUi("GUI.ui")
  5. url = ""
  6. params = {'rPOWR': '0', 'power': '0', 'ret': '', 'standby': '0'}
  7. tv_ip=()
  8.  
  9. def ON_TV1():
  10.     print("TV1 ON")
  11.     global url, params
  12.     url = "http://172.16.216.21/Power.cgi"
  13.     params = {'rPOWR': '1', 'power': '1', 'ret': '', 'standby': '0'}
  14.  
  15. def ON_TV2():
  16.     print("TV2 ON")
  17.     global url, params
  18.     url = "http://172.16.216.22/Power.cgi"
  19.     params = {'rPOWR': '1', 'power': '1', 'ret': '', 'standby': '0'}
  20.  
  21. def ON_TV3():
  22.     print("TV3 ON")
  23.     global url, params
  24.     url = "http://172.16.216.23/Power.cgi"
  25.     params = {'rPOWR': '1', 'power': '1', 'ret': '', 'standby': '0'}
  26.  
  27. def ON_TV4():
  28.     print("TV4 ON")
  29.     global url, params
  30.     url = "http://172.16.216.24/Power.cgi"
  31.     params = {'rPOWR': '1', 'power': '1', 'ret': '', 'standby': '0'}
  32.  
  33. def ON_TV5():
  34.     print("TV5 ON")
  35.     global url, params
  36.     url = "http://172.16.216.25/Power.cgi"
  37.     params = {'rPOWR': '1', 'power': '1', 'ret': '', 'standby': '0'}
  38.  
  39. def ON_TV6():
  40.     print("TV6 ON")
  41.     global url, params
  42.     url = "http://172.16.216.26/Power.cgi"
  43.     params = {'rPOWR': '1', 'power': '1', 'ret': '', 'standby': '0'}
  44.  
  45. def OFF_TV1():
  46.     print("TV1 OFF")
  47.     global url, params
  48.     url = "http://172.16.216.21/Power.cgi"
  49.     params = {'rPOWR': '0', 'power': '0', 'ret': '', 'standby': '0'}
  50.  
  51. def OFF_TV2():
  52.     print("TV2 OFF")
  53.     global url, params
  54.     url = "http://172.16.216.22/Power.cgi"
  55.     params = {'rPOWR': '0', 'power': '0', 'ret': '', 'standby': '0'}
  56.  
  57. def OFF_TV3():
  58.     print("TV3 OFF")
  59.     global url, params
  60.     url = "http://172.16.216.23/Power.cgi"
  61.     params = {'rPOWR': '0', 'power': '0', 'ret': '', 'standby': '0'}
  62.  
  63. def OFF_TV4():
  64.     print("TV4 OFF")
  65.     global url, params
  66.     url = "http://172.16.216.24/Power.cgi"
  67.     params = {'rPOWR': '0', 'power': '0', 'ret': '', 'standby': '0'}
  68.  
  69. def OFF_TV5():
  70.     print("TV5 OFF")
  71.     global url, params
  72.     url = "http://172.16.216.25/Power.cgi"
  73.     params = {'rPOWR': '0', 'power': '0', 'ret': '', 'standby': '0'}
  74.  
  75. def OFF_TV6():
  76.     print("TV6 OFF")
  77.     global url, params
  78.     url = "http://172.16.216.26/Power.cgi"
  79.     params = {'rPOWR': '0', 'power': '0', 'ret': '', 'standby': '0'}
  80.  
  81. def PostTV():
  82.     print(url)
  83.     #print(params)
  84.     requests.post(url=url, data=params, auth=('', ''))
  85.     #resp = requests.post(url=url, data=params, auth=('', ''))
  86.  
  87. def ON_ALL():
  88.     ON_TV1()
  89.     PostTV()
  90.     ON_TV2()
  91.     PostTV()
  92.     ON_TV3()
  93.     PostTV()
  94.     ON_TV4()
  95.     PostTV()
  96.     ON_TV5()
  97.     PostTV()
  98.     ON_TV6()
  99.     PostTV()
  100.  
  101. def OFF_ALL():
  102.     OFF_TV1()
  103.     PostTV()
  104.     OFF_TV2()
  105.     PostTV()
  106.     OFF_TV3()
  107.     PostTV()
  108.     OFF_TV4()
  109.     PostTV()
  110.     OFF_TV5()
  111.     PostTV()
  112.     OFF_TV6()
  113.     PostTV()
  114.  
  115. ui.ON_TV1.pressed.connect(ON_TV1)
  116. ui.ON_TV2.pressed.connect(ON_TV2)
  117. ui.ON_TV3.pressed.connect(ON_TV3)
  118. ui.ON_TV4.pressed.connect(ON_TV4)
  119. ui.ON_TV5.pressed.connect(ON_TV5)
  120. ui.ON_TV6.pressed.connect(ON_TV6)
  121. ui.ON_TV1.released.connect(PostTV)
  122. ui.ON_TV2.released.connect(PostTV)
  123. ui.ON_TV3.released.connect(PostTV)
  124. ui.ON_TV4.released.connect(PostTV)
  125. ui.ON_TV5.released.connect(PostTV)
  126. ui.ON_TV6.released.connect(PostTV)
  127. ui.OFF_TV1.pressed.connect(OFF_TV1)
  128. ui.OFF_TV2.pressed.connect(OFF_TV2)
  129. ui.OFF_TV3.pressed.connect(OFF_TV3)
  130. ui.OFF_TV4.pressed.connect(OFF_TV4)
  131. ui.OFF_TV5.pressed.connect(OFF_TV5)
  132. ui.OFF_TV6.pressed.connect(OFF_TV6)
  133. ui.OFF_TV1.released.connect(PostTV)
  134. ui.OFF_TV2.released.connect(PostTV)
  135. ui.OFF_TV3.released.connect(PostTV)
  136. ui.OFF_TV4.released.connect(PostTV)
  137. ui.OFF_TV5.released.connect(PostTV)
  138. ui.OFF_TV6.released.connect(PostTV)
  139. ui.ON_ALL.pressed.connect(ON_ALL)
  140. ui.OFF_ALL.pressed.connect(OFF_ALL)
  141.  
  142. ui.show()
  143. app.exec()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement