-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx0smarthdmi.py
118 lines (83 loc) · 2.88 KB
/
x0smarthdmi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
##
## imports
##
import time
import x0opcmd
import x0refcmd
import logging
##
## globals
##
##
## code
##
class X0SmartHDMI:
"""Change HDMI and ensure it changes"""
def __init__(self, inComm, useLog, timeoutConfig):
self.log = useLog
self.cfg = timeoutConfig
self.desired = None
self.jvcip = inComm
self.state = ''
self.timeout = 0
self.operation = None
def action(self):
# 1. Sent Power State
# 2. Validate Power State
# 3. Not not correct state, go back to 1
# state is
# ''
# 'setting'
# 'validating'
# 'delay'
if not self.desired:
self.log.debug('Called with nothing to do')
# True means nothing more to do
return True
if self.state == '':
self.log.debug(f'State "{self.state}" ')
self.log.info(f'Checking if HDMI is {self.desired}')
self.operation = x0refcmd.X0RefCmd(self.jvcip, self.log, self.cfg)
self.operation.set('IP',b'')
self.state = 'validating'
elif self.state == 'validating':
finished, rsp = self.operation.action()
if finished:
self.log.debug(f'JVC verified HDMI is {rsp}')
# 6 - HDMI1
# 7 - HDMI2
if (self.desired == b'6' and rsp == b'6') or (self.desired == b'7' and rsp == b'7'):
self.log.info(f'No need to change since HDMI state is correct already {self.desired} {rsp}')
self.state = ''
self.desired = None
else:
self.log.info(f'Need to change HDMI state {self.desired} {rsp}')
self.operation = x0opcmd.X0OpCmd(self.jvcip, self.log, self.cfg)
self.operation.set('IP',self.desired)
self.state = 'setting'
elif self.state == 'setting':
finished, rsp = self.operation.action()
if finished:
self.log.info(f'JVC performed HDMI operation and returned {rsp}')
self.state = ''
self.desired = None
else:
self.log.error(f'**** YIKES {self.state}')
if not self.desired:
# we are done
return (True,None)
else:
# more to do
return (False,None)
def set(self, cmd:str, data: bytearray):
if self.desired:
# same mode
self.log.error(f'!!!! Already sending command {self.desired} {cmd} {data}')
else:
self.desired = b'6'
if cmd == '2':
self.desired = b'7'
self.log.info(f'Asked to set HDMI State to {self.desired}')
# definitely need to restart the state machine
self.state = ''
self.action()