Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_int_to_hex_string(self):
result = Util.int_to_hex_string(255)
self.assertEqual(result, 'FF')
self.assertRaises(ValueError, Util.int_to_hex_string, 256)
except KeyError:
self.raise_config_error("Could not find WPC light {}".format(number), 4)
else:
number = self.convert_number_from_config(number)
return [
{
"number": number
}
]
if not subtype or subtype == "led":
# if the LED number is in - format, convert it to a
# FAST hardware number
if '-' in str(number):
num = str(number).split('-')
number = Util.int_to_hex_string((int(num[0]) * 64) + int(num[1]))
else:
number = self.convert_number_from_config(number)
return [
{
"number": number + "-0"
},
{
"number": number + "-1"
},
{
"number": number + "-2"
},
]
raise AssertionError("Unknown subtype {}".format(subtype))
def configure_debounce(self, debounce):
"""Configure debounce settings."""
if debounce:
debounce_open = Util.int_to_hex_string(self.platform.config['default_normal_debounce_open'])
debounce_close = Util.int_to_hex_string(self.platform.config['default_normal_debounce_close'])
else:
debounce_open = Util.int_to_hex_string(self.platform.config['default_quick_debounce_open'])
debounce_close = Util.int_to_hex_string(self.platform.config['default_quick_debounce_close'])
if 'debounce_open' in self.platform_settings and self.platform_settings['debounce_open'] is not None:
debounce_open = self.platform.convert_number_from_config(self.platform_settings['debounce_open'])
if 'debounce_close' in self.platform_settings and self.platform_settings['debounce_close'] is not None:
debounce_close = self.platform.convert_number_from_config(self.platform_settings['debounce_close'])
if self.connection:
cmd = 'SN:'
else:
cmd = 'SL:'
def get_control_for_cmd(cls, switch1, switch2=None):
"""Return control bytes."""
control = 0x01 # Driver enabled
if switch1.invert:
control += 0x10
if switch2 and switch2.invert:
control += 0x20
return Util.int_to_hex_string(int(control))
switch = int(switch_str)
if board not in self.io_boards:
raise AssertionError("Board {} does not exist for switch {}".format(board, number))
if self.io_boards[board].switch_count <= switch:
raise AssertionError("Board {} only has {} switches. Switch: {}".format(
board, self.io_boards[board].switch_count, number))
index = 0
for board_number, board_obj in self.io_boards.items():
if board_number >= board:
continue
index += board_obj.switch_count
return Util.int_to_hex_string(index + switch)
def convert_number_from_config(number):
"""Convert a number from config format to hex."""
return Util.int_to_hex_string(number)
def set_brightness(self, brightness: float):
"""Set GI string to a certain brightness."""
brightness = int(brightness * 255)
if brightness >= 255:
brightness = 255
self.log.debug("Turning On GI String to brightness %s", brightness)
# self.send('GI:' + self.number + ',' + Util.int_to_hex_string(brightness))
self.send('GI:{},{}'.format(self.number,
Util.int_to_hex_string(brightness)))
driver = int(driver_str)
if board not in self.io_boards:
raise AssertionError("Board {} does not exist for driver {}".format(board, number))
if self.io_boards[board].driver_count <= driver:
raise AssertionError("Board {} only has {} drivers. Driver: {}".format(
board, self.io_boards[board].driver_count, number))
index = 0
for board_number, board_obj in self.io_boards.items():
if board_number >= board:
continue
index += board_obj.driver_count
return Util.int_to_hex_string(index + driver)
def enable(self, pulse_settings: PulseSettings, hold_settings: HoldSettings):
"""Enable (turn on) this driver."""
config_state = pulse_settings.duration, pulse_settings.power, hold_settings.power
if self.autofire and self.config_state == config_state:
# If this driver is also configured for an autofire rule, we just
# manually trigger it with the trigger_cmd and manual on ('03')
cmd = '{}{},03'.format(self.get_trigger_cmd(), self.number)
else:
# Otherwise we send a full config command, trigger C1 (logic triggered
# and drive now) switch ID 00, mode 18 (latched)
self._autofire_cleared = True
cmd = '{}{},C1,00,18,{},{},{},{}'.format(
self.get_config_cmd(),
self.number,
Util.int_to_hex_string(pulse_settings.duration),
self.get_pwm_for_cmd(pulse_settings.power),
self.get_pwm_for_cmd(hold_settings.power),
self.get_recycle_ms_for_cmd(self.config.default_recycle, pulse_settings.duration)
)
self.config_state = (pulse_settings.duration, pulse_settings.duration, hold_settings.power)
self.log.debug("Sending Enable Command: %s", cmd)
self.send(cmd)