def get_pwm2_for_cmd(cls, coil): """Return pwm2/hold pwm.""" if coil.config['hold_pwm_mask']: hold_pwm_mask = str(coil.config['hold_pwm_mask']) if len(hold_pwm_mask) == 32: return Util.bin_str_to_hex_str(hold_pwm_mask, 8) elif len(hold_pwm_mask) == 8: return Util.bin_str_to_hex_str(hold_pwm_mask, 2) else: raise ValueError("hold_pwm_mask must either be 8 or 32 bits") elif coil.config['hold_power32'] is not None: return "ff" elif coil.config['hold_power'] is not None: return Util.pwm8_to_hex_string(coil.config['hold_power']) else: return "ff"
def test_bin_str_to_hex_str(self): result = Util.bin_str_to_hex_str('1111', 2) self.assertEqual(result, '0F')