Skip to content

Commit

Permalink
Fixed Output Control Implementation errors (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ay1tsMe authored Aug 9, 2023
1 parent 87854ae commit e453464
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions ultrasync/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2124,25 +2124,24 @@ def output_control(self):
if not response:
return False

# Regex to capture output names and states
name_pattern = re.compile(
r'var oname(\d) = decodeURIComponent'
r'\(decode_utf8\("([^"]*)"\)\);')
state_pattern = re.compile(r'var ostate(\d) = "(\d)";')

# Extract names and states
names = {int(m.group(1)): unquote(m.group(2))
for m in name_pattern.finditer(response)}
states = {int(m.group(1)): m.group(2)
for m in state_pattern.finditer(response)}
# Regex to capture output names and states
name_pattern = re.compile(
r'var oname(\d) = decodeURIComponent'
r'\(decode_utf8\("([^"]*)"\)\);')
state_pattern = re.compile(r'var ostate(\d) = "(\d)";')

# Extract names and states
names = {int(m.group(1)): unquote(m.group(2))
for m in name_pattern.finditer(response)}
states = {int(m.group(1)): m.group(2)
for m in state_pattern.finditer(response)}

# Store our outputs:
for i in range(1, max(len(names), len(states)) + 1):
self.outputs[i] = {
'name': names.get(i, ''),
'state': states.get(i, '0'),
}
return False
for i in range(1, max(len(names), len(states)) + 1):
self.outputs[i] = {
'name': names.get(i, ''),
'state': states.get(i, '0'),
}

return True

Expand All @@ -2152,16 +2151,16 @@ def set_output_control(self, output, state):
At this time, this feature is only supported by the COMNAV panels
"""
if not self.session_id and not self.login():
return False

if self.vendor is not NX595EVendor.COMNAV:
# Only vendor that supports this right now is COMNAV
logger.error(
'Output control not implemented for vendor {}'.format(
self.vendor))
return False

if not self.session_id and not self.login():
return False

if not isinstance(output, int) or output not in self.outputs.keys():
logger.error(
'{} is not valid output'.format(output))
Expand Down

0 comments on commit e453464

Please sign in to comment.